From 846d28de3f209bb76cb6c3bad80294a100ae9e94 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 11 Sep 2023 11:31:56 -0600 Subject: [android] Upgrade AGP and base dependencies --- androidApp/src/google/AndroidManifest.xml | 3 +-- androidApp/src/main/AndroidManifest.xml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'androidApp/src') diff --git a/androidApp/src/google/AndroidManifest.xml b/androidApp/src/google/AndroidManifest.xml index 5207ee9..c666fc8 100644 --- a/androidApp/src/google/AndroidManifest.xml +++ b/androidApp/src/google/AndroidManifest.xml @@ -1,8 +1,7 @@ + xmlns:tools="http://schemas.android.com/tools"> + xmlns:android="http://schemas.android.com/apk/res/android"> -- cgit v1.2.3 From fa2a7a8dd35e6d066022239f4da9cd5ddc54a229 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 11 Sep 2023 13:38:19 -0600 Subject: [android] Upgrade AGP, Kotlin plugin, JDK + StateFlow fixes --- androidApp/build.gradle.kts | 22 +++++++++++++--------- .../android/details/reports/UnitReportsFragment.kt | 12 ++++++------ .../details/reports/UnitReportsViewModel.kt | 15 ++++++++------- .../android/session/UserInformationViewModel.kt | 6 +++--- .../TrackerMap/android/units/UnitsViewModel.kt | 8 ++++---- build.gradle.kts | 6 +++--- gradle.properties | 5 ++++- gradle/wrapper/gradle-wrapper.properties | 2 +- shared/build.gradle.kts | 7 ++++--- 9 files changed, 46 insertions(+), 37 deletions(-) (limited to 'androidApp/src') diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 6760c56..3cec8c5 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -18,6 +18,10 @@ android { abiFilters += listOf("armeabi-v7a", "arm64-v8a") } } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_20 + targetCompatibility = JavaVersion.VERSION_20 + } buildTypes { getByName("release") { isMinifyEnabled = false @@ -45,18 +49,18 @@ val googleImplementation by configurations dependencies { implementation(project(":shared")) - implementation("com.google.android.material:material:1.6.0") - implementation("androidx.appcompat:appcompat:1.4.1") + implementation("com.google.android.material:material:1.9.0") + implementation("androidx.appcompat:appcompat:1.6.1") implementation("androidx.constraintlayout:constraintlayout:2.1.4") - implementation("com.squareup.okhttp3:okhttp:4.9.1") + implementation("com.squareup.okhttp3:okhttp:4.10.0") implementation("com.github.Zhuinden:live-event:1.2.0") - implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1") - implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.4.1") - implementation("androidx.preference:preference-ktx:1.2.0") + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2") + implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2") + implementation("androidx.preference:preference-ktx:1.2.1") implementation("io.insert-koin:koin-android:3.1.4") - implementation("androidx.core:core-ktx:1.7.0") - implementation("androidx.activity:activity-ktx:1.4.0") - implementation("androidx.fragment:fragment-ktx:1.4.1") + implementation("androidx.core:core-ktx:1.10.1") + implementation("androidx.activity:activity-ktx:1.7.2") + implementation("androidx.fragment:fragment-ktx:1.6.1") implementation("io.ktor:ktor-client-serialization:1.6.6") implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.1") implementation("com.github.zerobranch:SwipeLayout:1.3.1") diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt index aab3cfa..65071da 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt @@ -36,7 +36,6 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.commit import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.card.MaterialCardView -import io.ktor.utils.io.* import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.datetime.* import kotlinx.datetime.TimeZone @@ -223,6 +222,7 @@ class UnitReportsFragment : Fragment() { } } is ReportController.Report.LoadingReport -> loading() + else -> loading() } } @@ -260,13 +260,13 @@ class UnitReportsFragment : Fragment() { val (from, to) = period.getObjectDates() - fromDatePicker = DatePickerDialog(requireContext(), { p0, p1, p2, p3 -> + fromDatePicker = DatePickerDialog(requireContext(), { _, p1, p2, p3 -> fromPickedDatetime = LocalDateTime(p1, p2 + 1, p3, from.hour, from.minute) fromTimePicker.show() }, from.year, from.monthNumber, from.dayOfMonth) fromDatePicker.datePicker.maxDate = Calendar.getInstance().timeInMillis - fromTimePicker = TimePickerDialog(requireContext(), { p0, p1, p2 -> + fromTimePicker = TimePickerDialog(requireContext(), { _, p1, p2 -> fromPickedDatetime = LocalDateTime( fromPickedDatetime.year, fromPickedDatetime.monthNumber, @@ -275,7 +275,7 @@ class UnitReportsFragment : Fragment() { ) (period as? ReportDates.ReportPeriod.Custom)?.let { val fromInstant = fromPickedDatetime.toInstant(TimeZone.currentSystemDefault()) - val toInstant = Calendar.getInstance().toInstant().toKotlinInstant() + val toInstant = Clock.System.now() val plusMonth = fromInstant.plus(31.toDuration(DurationUnit.DAYS)) /* Make ultra sure that user can't select a period longer than a month */ @@ -293,13 +293,13 @@ class UnitReportsFragment : Fragment() { } }, from.hour, from.minute, false) - toDatePicker = DatePickerDialog(requireContext(), { p0, p1, p2, p3 -> + toDatePicker = DatePickerDialog(requireContext(), { _, p1, p2, p3 -> toPickedDatetime = LocalDateTime(p1, p2 + 1, p3, from.hour, from.minute) toTimePicker.show() }, to.year, to.monthNumber, to.dayOfMonth) toDatePicker.datePicker.maxDate = Calendar.getInstance().timeInMillis - toTimePicker = TimePickerDialog(requireContext(), { p0, p1, p2 -> + toTimePicker = TimePickerDialog(requireContext(), { _, p1, p2 -> toPickedDatetime = LocalDateTime( toPickedDatetime.year, toPickedDatetime.monthNumber, diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt index 41a6b6d..628ce2f 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt @@ -19,7 +19,7 @@ package mx.trackermap.TrackerMap.android.details.reports import androidx.lifecycle.* import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.models.EventInformation import mx.trackermap.TrackerMap.client.models.Geofence @@ -42,16 +42,17 @@ class UnitReportsViewModel( private val reportController: ReportController by inject() private var _deviceId = savedStateHandle.getLiveData("deviceId", 0) - private val _reportType: MutableLiveData = savedStateHandle.getLiveData("reportType", null) + private val _reportType: MutableLiveData = + savedStateHandle.getLiveData("reportType", ReportController.ReportType.POSITIONS) private val _reportPeriod: MutableLiveData = - savedStateHandle.getLiveData("reportPeriod", null) - private val _report: MutableLiveData = MutableLiveData() + savedStateHandle.getLiveData("reportPeriod", ReportDates.ReportPeriod.Today()) + private val _report: MutableLiveData = MutableLiveData() private val _geofences: MutableLiveData> = MutableLiveData(emptyArray()) val deviceId: LiveData get() = _deviceId val reportType: LiveData get() = _reportType val reportPeriod: LiveData get() = _reportPeriod - val report: LiveData get() = _report + val report: LiveData get() = _report val geofences: LiveData> get() = _geofences init { @@ -82,13 +83,13 @@ class UnitReportsViewModel( } private suspend fun setupReportObserver() { - reportController.reportFlow.collect { + (reportController.reportFlow as StateFlow).collect { _report.value = it } } private suspend fun setupGeofenceObserver() { - geofencesController.geofencesFlow.collect { + (geofencesController.geofencesFlow as StateFlow>).collect { _geofences.value = it.values.toTypedArray() } } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationViewModel.kt index 0d3784c..7a57755 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationViewModel.kt @@ -25,7 +25,7 @@ import androidx.lifecycle.viewModelScope import com.zhuinden.eventemitter.EventEmitter import com.zhuinden.eventemitter.EventSource import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.models.User import mx.trackermap.TrackerMap.controllers.SessionController @@ -57,7 +57,7 @@ class UserInformationViewModel : ViewModel(), KoinComponent { } private suspend fun setupLoginStateObserver() { - sessionController.loginStateFlow.collect { + (sessionController.loginStateFlow as StateFlow).collect { it?.let { loginStateEmitter.emit(it) } @@ -65,7 +65,7 @@ class UserInformationViewModel : ViewModel(), KoinComponent { } private suspend fun setupUserObserver() { - sessionController.userFlow.collect { + (sessionController.userFlow as StateFlow).collect { it?.let { _user.postValue(it) } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt index b537c0b..b5ed78d 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt @@ -21,7 +21,7 @@ import android.util.Log import androidx.lifecycle.* import com.mousebird.maply.Point2d import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.models.Geofence import mx.trackermap.TrackerMap.client.models.MapLayer @@ -87,14 +87,14 @@ class UnitsViewModel( } private suspend fun setupUnitsObserver() { - unitsController.displayedUnitsFlow.collect { units -> + (unitsController.displayedUnitsFlow as StateFlow>).collect { units -> Log.d("UnitsViewModel", "Collecting units") this._displayedUnits.value = units } } private suspend fun setupDisplayedUnitsObserver() { - unitsController.unitsFlow.collect { units -> + (unitsController.unitsFlow as StateFlow>).collect { units -> Log.d("UnitsViewModel", "Collecting displayed units") this._units.value = units updateSelectedUnit() @@ -102,7 +102,7 @@ class UnitsViewModel( } private suspend fun setupGeofenceObserver() { - geofenceController.geofencesFlow.collect { + (geofenceController.geofencesFlow as StateFlow>).collect { Log.d("UnitsViewModel", "Collecting geofences") this._geofences.postValue(it) } diff --git a/build.gradle.kts b/build.gradle.kts index 8e8e9d2..7d1f0e2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,9 +6,9 @@ buildscript { maven("https://jitpack.io") } dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") - classpath("org.jetbrains.kotlin:kotlin-serialization:1.8.20") - classpath("com.android.tools.build:gradle:7.4.2") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") + classpath("org.jetbrains.kotlin:kotlin-serialization:1.9.0") + classpath("com.android.tools.build:gradle:8.1.1") classpath("com.google.gms:google-services:4.3.15") } } diff --git a/gradle.properties b/gradle.properties index 3211eb8..0556818 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,7 @@ android.useAndroidX=true #MPP kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.native.enableDependencyPropagation=false -kotlin.mpp.enableCInteropCommonization=true \ No newline at end of file +kotlin.mpp.enableCInteropCommonization=true +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6c26f1e..8424d98 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Fri Dec 03 21:13:43 CST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 960c51d..c47336d 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -8,7 +8,9 @@ kotlin { val ktor_version = "1.6.6" val settings_version = "0.8.1" - android() + androidTarget() + + jvmToolchain(20) listOf( iosX64(), @@ -56,11 +58,10 @@ kotlin { } android { - compileSdk = 31 + compileSdk = 34 sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") defaultConfig { minSdk = 21 - targetSdk = 31 ndk { abiFilters.clear() abiFilters += listOf("armeabi-v7a", "arm64-v8a") -- cgit v1.2.3 From 55c1f26f70ae02dfdad215c0c1830ebfce76a0e5 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 11 Sep 2023 18:01:17 -0600 Subject: [android] More dependency updates and misc. fixes --- androidApp/build.gradle.kts | 8 ++++---- androidApp/src/main/AndroidManifest.xml | 6 ++++-- .../main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt | 6 ++++++ shared/build.gradle.kts | 6 +++++- 4 files changed, 19 insertions(+), 7 deletions(-) (limited to 'androidApp/src') diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 3cec8c5..5713a6a 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -19,8 +19,8 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_20 - targetCompatibility = JavaVersion.VERSION_20 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } buildTypes { getByName("release") { @@ -58,11 +58,11 @@ dependencies { implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2") implementation("androidx.preference:preference-ktx:1.2.1") implementation("io.insert-koin:koin-android:3.1.4") - implementation("androidx.core:core-ktx:1.10.1") + implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.activity:activity-ktx:1.7.2") implementation("androidx.fragment:fragment-ktx:1.6.1") implementation("io.ktor:ktor-client-serialization:1.6.6") - implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.1") + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0") implementation("com.github.zerobranch:SwipeLayout:1.3.1") implementation("com.github.addisonElliott:SegmentedButton:3.1.9") implementation("mil.nga.sf:sf-wkt:1.0.1") diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml index d058321..0a3a539 100644 --- a/androidApp/src/main/AndroidManifest.xml +++ b/androidApp/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - @@ -11,7 +11,9 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + android:enableOnBackInvokedCallback="true" + tools:targetApi="tiramisu"> diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt index b04bfbc..4915c49 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt @@ -114,6 +114,12 @@ open class MapFragment : GlobeMapFragment() { hasStarted = false } + override fun onDestroyView() { + super.onDestroyView() + loader?.shutdown() + loader = null + } + override fun mapDidStopMoving( mapControl: MapController?, corners: Array?, diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index c47336d..94b8f09 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -10,7 +10,7 @@ kotlin { androidTarget() - jvmToolchain(20) + jvmToolchain(17) listOf( iosX64(), @@ -68,4 +68,8 @@ android { } } namespace = "mx.trackermap.TrackerMap" + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } } \ No newline at end of file -- cgit v1.2.3