From 0c3f15edc35251d171bb19f13ffb4c2f98d72967 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 25 Jun 2024 16:32:51 +0200 Subject: [PATCH] 1462: update kotlin android plugin, set kotlinOptions to jvm target, add workaround to reload map page if it comes to foreground --- frontend/android/app/build.gradle | 4 ++++ frontend/android/settings.gradle | 2 +- frontend/ios/Podfile.lock | 24 +++++++++++----------- frontend/lib/home/home_page.dart | 33 +++++++++++++++++++++++++++---- frontend/lib/map/map/map.dart | 9 ++++----- 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/frontend/android/app/build.gradle b/frontend/android/app/build.gradle index 5e56a3f58..98f9d3c1f 100644 --- a/frontend/android/app/build.gradle +++ b/frontend/android/app/build.gradle @@ -64,6 +64,10 @@ ext.setupVariant = { variant, buildConfigName -> android { compileSdkVersion 34 + kotlinOptions { + jvmTarget=JavaVersion.VERSION_1_8 + } + sourceSets { main.java.srcDirs += 'src/main/kotlin' } diff --git a/frontend/android/settings.gradle b/frontend/android/settings.gradle index ef03c12b4..83b4cf1d3 100644 --- a/frontend/android/settings.gradle +++ b/frontend/android/settings.gradle @@ -19,7 +19,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "7.3.1" apply false - id "org.jetbrains.kotlin.android" version "1.7.10" apply false + id "org.jetbrains.kotlin.android" version "1.9.10" apply false } include ":app" diff --git a/frontend/ios/Podfile.lock b/frontend/ios/Podfile.lock index 45264fa74..d868d2b84 100644 --- a/frontend/ios/Podfile.lock +++ b/frontend/ios/Podfile.lock @@ -32,23 +32,23 @@ PODS: - GoogleToolboxForMac/Defines (= 2.3.2) - "GoogleToolboxForMac/NSString+URLArguments (= 2.3.2)" - "GoogleToolboxForMac/NSString+URLArguments (2.3.2)" - - GoogleUtilities/Environment (7.13.0): + - GoogleUtilities/Environment (7.13.3): - GoogleUtilities/Privacy - PromisesObjC (< 3.0, >= 1.2) - - GoogleUtilities/Logger (7.13.0): + - GoogleUtilities/Logger (7.13.3): - GoogleUtilities/Environment - GoogleUtilities/Privacy - - GoogleUtilities/Privacy (7.13.0) - - GoogleUtilities/UserDefaults (7.13.0): + - GoogleUtilities/Privacy (7.13.3) + - GoogleUtilities/UserDefaults (7.13.3): - GoogleUtilities/Logger - GoogleUtilities/Privacy - GoogleUtilitiesComponents (1.1.0): - GoogleUtilities/Logger - GTMSessionFetcher/Core (2.3.0) - - MapLibre (5.14.0-pre3) + - MapLibre (6.5.0) - maplibre_gl (0.0.1): - Flutter - - MapLibre (= 5.14.0-pre3) + - MapLibre (= 6.5.0) - MLImage (1.0.0-beta4) - MLKitBarcodeScanning (3.0.0): - MLKitCommon (~> 9.0) @@ -83,7 +83,7 @@ PODS: - permission_handler_apple (9.3.0): - Flutter - PromisesObjC (2.4.0) - - ReachabilitySwift (5.2.1) + - ReachabilitySwift (5.2.3) - Sentry/HybridSDK (8.21.0): - SentryPrivate (= 8.21.0) - sentry_flutter (0.0.1): @@ -172,11 +172,11 @@ SPEC CHECKSUMS: GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a GoogleMLKit: 2bd0dc6253c4d4f227aad460f69215a504b2980e GoogleToolboxForMac: 8bef7c7c5cf7291c687cf5354f39f9db6399ad34 - GoogleUtilities: d053d902a8edaa9904e1bd00c37535385b8ed152 + GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15 GoogleUtilitiesComponents: 679b2c881db3b615a2777504623df6122dd20afe GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2 - MapLibre: 620fc933c1d6029b33738c905c1490d024e5d4ef - maplibre_gl: a2efec727dd340e4c65e26d2b03b584f14881fd9 + MapLibre: 0ebfa9329d313cec8bf0a5ba5a336a1dc903785e + maplibre_gl: 943a491fffb3337c1b9de57fd377206d18c16e34 MLImage: 7bb7c4264164ade9bf64f679b40fb29c8f33ee9b MLKitBarcodeScanning: 04e264482c5f3810cb89ebc134ef6b61e67db505 MLKitCommon: c1b791c3e667091918d91bda4bba69a91011e390 @@ -187,7 +187,7 @@ SPEC CHECKSUMS: path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 - ReachabilitySwift: 5ae15e16814b5f9ef568963fb2c87aeb49158c66 + ReachabilitySwift: 7f151ff156cea1481a8411701195ac6a984f4979 Sentry: ebc12276bd17613a114ab359074096b6b3725203 sentry_flutter: dff1df05dc39c83d04f9330b36360fc374574c5e SentryPrivate: d651efb234cf385ec9a1cdd3eff94b5e78a0e0fe @@ -196,4 +196,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 911aea8a3150d910789c4f32e348c4d0ff803162 -COCOAPODS: 1.13.0 +COCOAPODS: 1.15.2 diff --git a/frontend/lib/home/home_page.dart b/frontend/lib/home/home_page.dart index c1f51a068..0dc0c2106 100644 --- a/frontend/lib/home/home_page.dart +++ b/frontend/lib/home/home_page.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:ehrenamtskarte/about/about_page.dart'; import 'package:ehrenamtskarte/build_config/build_config.dart' show buildConfig; import 'package:ehrenamtskarte/configuration/settings_model.dart'; @@ -13,18 +15,21 @@ import 'package:provider/provider.dart'; import 'package:ehrenamtskarte/l10n/translations.g.dart'; +import 'package:ehrenamtskarte/routing.dart'; + const mapTabIndex = 0; const identityTabIndex = 2; -class HomePage extends StatefulWidget { +class HomePage extends StatefulWidget with WidgetsBindingObserver { final int? initialTabIndex; - const HomePage({super.key, this.initialTabIndex}); + final int? initialSelectedAcceptanceStore; + const HomePage({super.key, this.initialTabIndex, this.initialSelectedAcceptanceStore}); @override HomePageState createState() => HomePageState(); } -class HomePageState extends State { +class HomePageState extends State with WidgetsBindingObserver { late List appFlows; int _currentTabIndex = mapTabIndex; @@ -34,12 +39,14 @@ class HomePageState extends State { @override void initState() { super.initState(); + WidgetsBinding.instance.addObserver(this); _currentTabIndex = widget.initialTabIndex ?? mapTabIndex; appFlows = [ AppFlow( MapPage( onMapCreated: (controller) => setState(() => mapPageController = controller), - selectAcceptingStore: (id) => setState(() => selectedAcceptingStoreId = id), + selectAcceptingStore: (id) => + setState(() => selectedAcceptingStoreId = widget.initialSelectedAcceptanceStore ?? id), ), Icons.map_outlined, (BuildContext context) => t.map.title, @@ -63,6 +70,24 @@ class HomePageState extends State { ]; } + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + super.dispose(); + } + + // Reload map on android devices to solve this issue https://github.com/maplibre/flutter-maplibre-gl/issues/327 + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (state == AppLifecycleState.resumed && _currentTabIndex == mapTabIndex && Platform.isAndroid) { + Navigator.of(context, rootNavigator: true).push( + AppRoute( + builder: (context) => HomePage(initialSelectedAcceptanceStore: widget.initialSelectedAcceptanceStore), + ), + ); + } + } + @override Widget build(BuildContext context) { final settings = Provider.of(context); diff --git a/frontend/lib/map/map/map.dart b/frontend/lib/map/map/map.dart index 496970789..33d22436b 100644 --- a/frontend/lib/map/map/map.dart +++ b/frontend/lib/map/map/map.dart @@ -46,8 +46,8 @@ class MapContainer extends StatefulWidget { const mapboxColor = Color(0xFF979897); -class _MapContainerState extends State implements MapController { - MaplibreMapController? _controller; +class _MapContainerState extends State with WidgetsBindingObserver implements MapController { + MapLibreMapController? _controller; Symbol? _symbol; bool _permissionGiven = false; bool _isMapInitialized = false; @@ -65,7 +65,6 @@ class _MapContainerState extends State implements MapController { final statusBarHeight = MediaQuery.of(context).padding.top; final pixelRatio = MediaQuery.of(context).devicePixelRatio; final compassMargin = Platform.isIOS ? statusBarHeight / pixelRatio : statusBarHeight * pixelRatio; - final userLocation = widget.userLocation; final cameraPosition = userLocation != null ? CameraPosition(target: userLocation, zoom: MapContainer.zoomLevelUserLocation) @@ -73,7 +72,7 @@ class _MapContainerState extends State implements MapController { final mapLibreView = Stack( children: [ - MaplibreMap( + MapLibreMap( initialCameraPosition: cameraPosition, styleString: config.mapStyleUrl, // We provide our own attribution menu @@ -121,7 +120,7 @@ class _MapContainerState extends State implements MapController { : mapLibreView; } - void _onMapCreated(MaplibreMapController controller) { + void _onMapCreated(MapLibreMapController controller) { _controller = controller; setState(() {