Skip to content

Commit bcbd85f

Browse files
committed
Fix Android build, fix OSRM routing, stabilize offline tiles, and optimize startup load
1 parent 717a0a8 commit bcbd85f

8 files changed

Lines changed: 31 additions & 43 deletions

File tree

mobile_app/android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
android {
99
namespace = "com.example.mobile_app"
10-
compileSdk = 34
10+
compileSdk = 36
1111
ndkVersion = flutter.ndkVersion
1212

1313
compileOptions {

mobile_app/android/build.gradle.kts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath("com.android.tools.build:gradle:8.2.2")
9-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
8+
classpath("com.android.tools.build:gradle:8.3.2")
9+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
1010
}
1111
}
1212

1313
allprojects {
1414
configurations.all {
1515
resolutionStrategy {
16+
force("androidx.core:core:1.13.1")
17+
force("androidx.core:core-ktx:1.13.1")
1618
eachDependency {
17-
if (requested.group == "androidx.core" && requested.name.startsWith("core")) {
18-
useVersion("1.12.0")
19-
}
2019
if (requested.group == "org.jetbrains.kotlin") {
2120
useVersion("1.9.24")
2221
}

mobile_app/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
import 'dart:io';
22
import 'package:flutter/widgets.dart';
33
import 'package:flutter_map/flutter_map.dart';
4-
import 'package:path/path.dart' as p;
54

6-
/// A TileProvider that checks if a tile exists locally before falling back to network.
7-
class FallbackFileTileProvider extends TileProvider {
8-
final String tilesDir;
9-
final NetworkTileProvider _networkProvider;
10-
11-
FallbackFileTileProvider({required this.tilesDir})
12-
: _networkProvider = NetworkTileProvider();
5+
class FileTileProvider extends TileProvider {
6+
FileTileProvider();
137

148
@override
159
ImageProvider getImage(TileCoordinates coordinates, TileLayer options) {
16-
final z = coordinates.z;
17-
final x = coordinates.x;
18-
final y = coordinates.y;
19-
20-
final tilePath = p.join(tilesDir, '$z', '$x', '$y.png');
21-
final file = File(tilePath);
10+
// Determine path from urlTemplate which was populated with dir path
11+
final url = getTileUrl(coordinates, options);
12+
final file = File(url);
2213

23-
try {
24-
if (file.existsSync() == true) {
25-
print("Tile path: $tilePath");
26-
return FileImage(file);
27-
} else {
28-
return _networkProvider.getImage(coordinates, options);
29-
}
30-
} catch (e, s) {
31-
debugPrint("ERROR: $e");
32-
debugPrint("$s");
33-
return _networkProvider.getImage(coordinates, options);
14+
if (file.existsSync()) {
15+
return FileImage(file);
16+
} else {
17+
debugPrint("Tile not found: $url");
18+
// Return a transparent image or handle error
19+
throw Exception("Tile not found: $url");
3420
}
3521
}
3622
}

mobile_app/lib/features/map/map_screen.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,12 +768,10 @@ class _MapScreenState extends State<MapScreen> {
768768
),
769769
children: [
770770
TileLayer(
771-
urlTemplate: _tileUrl!,
771+
urlTemplate: _tilesDir != null ? '$_tilesDir/{z}/{x}/{y}.png' : _tileUrl!,
772772
userAgentPackageName: 'org.openrescue.mobile',
773773
maxZoom: 19,
774-
tileProvider: _tilesDir != null
775-
? FallbackFileTileProvider(tilesDir: _tilesDir!)
776-
: NetworkTileProvider(),
774+
tileProvider: FileTileProvider(),
777775
),
778776
StreamBuilder<ResponderState>(
779777
stream: context.read<ResponderStateService>().stateStream,
@@ -983,17 +981,21 @@ class _CreateIncidentFormState extends State<_CreateIncidentForm> {
983981
),
984982
),
985983
TextField(
984+
autofocus: false,
986985
controller: _typeController,
987986
decoration: const InputDecoration(labelText: 'Type')),
988987
TextField(
988+
autofocus: false,
989989
controller: _priorityController,
990990
decoration: const InputDecoration(labelText: 'Priority')),
991991
if (widget.initialLat == null) ...[
992992
TextField(
993+
autofocus: false,
993994
controller: _latController,
994995
keyboardType: TextInputType.number,
995996
decoration: const InputDecoration(labelText: 'Latitude')),
996997
TextField(
998+
autofocus: false,
997999
controller: _lonController,
9981000
keyboardType: TextInputType.number,
9991001
decoration: const InputDecoration(labelText: 'Longitude')),

mobile_app/lib/features/prefetch/prefetch_screen.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class _PrefetchScreenState extends State<PrefetchScreen> {
7979
fontSize: 16, fontWeight: FontWeight.bold)),
8080
const SizedBox(height: 12),
8181
TextField(
82+
autofocus: false,
8283
controller: _radiusController,
8384
keyboardType: TextInputType.number,
8485
decoration: const InputDecoration(
@@ -94,6 +95,7 @@ class _PrefetchScreenState extends State<PrefetchScreen> {
9495
children: [
9596
Expanded(
9697
child: TextField(
98+
autofocus: false,
9799
controller: _minZoomController,
98100
keyboardType: TextInputType.number,
99101
decoration: const InputDecoration(
@@ -106,6 +108,7 @@ class _PrefetchScreenState extends State<PrefetchScreen> {
106108
const SizedBox(width: 12),
107109
Expanded(
108110
child: TextField(
111+
autofocus: false,
109112
controller: _maxZoomController,
110113
keyboardType: TextInputType.number,
111114
decoration: const InputDecoration(

mobile_app/lib/main.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ void main() async {
4141
final apiClient = ApiClient(baseUrl: baseUrl, authService: authService);
4242
final db = AppDatabase();
4343
final p2pService = P2PService(hostUrl: baseUrl);
44-
// Start the background connection to the local node
45-
Future(() async {
46-
p2pService.connect();
47-
});
4844
final wsService = WsService(baseUrl, authService, db);
4945
final mapService = MapService();
5046

@@ -55,8 +51,9 @@ void main() async {
5551
repo: tilesRepo,
5652
mapService: mapService,
5753
);
58-
Future(() async {
59-
await prefetchService.resumePendingJobs();
54+
Future.delayed(const Duration(seconds: 2), () {
55+
p2pService.connect();
56+
prefetchService.resumePendingJobs();
6057
});
6158
final prefetchController = PrefetchController(prefetchService);
6259

mobile_app/lib/services/osrm_service.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ class OSRMService {
2424
bool alternatives = false,
2525
}) async {
2626
try {
27-
final baseUrl = baseUrlOverride ?? AppConfig.osrmBaseUrl;
27+
final baseUrl = "http://192.168.1.105:5000";
2828
final uriStr = '$baseUrl/route/v1/driving/'
2929
'${start.longitude},${start.latitude};'
3030
'${end.longitude},${end.latitude}'
3131
'?overview=full&geometries=polyline6&steps=true'
3232
'&annotations=false&alternatives=$alternatives';
33+
print("Calling OSRM: $uriStr");
3334

3435
final uri = Uri.parse(uriStr);
3536
print("Calling OSRM...");

0 commit comments

Comments
 (0)