aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-09-11 13:38:19 -0600
committerIván Ávalos <avalos@disroot.org>2023-09-11 13:38:19 -0600
commitfa2a7a8dd35e6d066022239f4da9cd5ddc54a229 (patch)
tree2795643d230e54d6abf7a7dacd460891aaa810eb /androidApp/src/main
parent0c61b3bb0bc4e91835572d0fb43a862e8759e4ca (diff)
downloadetbsa-trackermap-mobile-fa2a7a8dd35e6d066022239f4da9cd5ddc54a229.tar.gz
etbsa-trackermap-mobile-fa2a7a8dd35e6d066022239f4da9cd5ddc54a229.tar.bz2
etbsa-trackermap-mobile-fa2a7a8dd35e6d066022239f4da9cd5ddc54a229.zip
[android] Upgrade AGP, Kotlin plugin, JDK + StateFlow fixes
Diffstat (limited to 'androidApp/src/main')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt12
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt15
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationViewModel.kt6
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt8
4 files changed, 21 insertions, 20 deletions
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<ReportController.ReportType> = savedStateHandle.getLiveData("reportType", null)
+ private val _reportType: MutableLiveData<ReportController.ReportType> =
+ savedStateHandle.getLiveData("reportType", ReportController.ReportType.POSITIONS)
private val _reportPeriod: MutableLiveData<ReportDates.ReportPeriod> =
- savedStateHandle.getLiveData("reportPeriod", null)
- private val _report: MutableLiveData<ReportController.Report> = MutableLiveData()
+ savedStateHandle.getLiveData("reportPeriod", ReportDates.ReportPeriod.Today())
+ private val _report: MutableLiveData<ReportController.Report?> = MutableLiveData()
private val _geofences: MutableLiveData<Array<Geofence>> = MutableLiveData(emptyArray())
val deviceId: LiveData<Int> get() = _deviceId
val reportType: LiveData<ReportController.ReportType> get() = _reportType
val reportPeriod: LiveData<ReportDates.ReportPeriod> get() = _reportPeriod
- val report: LiveData<ReportController.Report> get() = _report
+ val report: LiveData<ReportController.Report?> get() = _report
val geofences: LiveData<Array<Geofence>> get() = _geofences
init {
@@ -82,13 +83,13 @@ class UnitReportsViewModel(
}
private suspend fun setupReportObserver() {
- reportController.reportFlow.collect {
+ (reportController.reportFlow as StateFlow<ReportController.Report>).collect {
_report.value = it
}
}
private suspend fun setupGeofenceObserver() {
- geofencesController.geofencesFlow.collect {
+ (geofencesController.geofencesFlow as StateFlow<Map<Int, Geofence>>).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<SessionController.LoginState?>).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<User?>).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<List<UnitInformation>>).collect { units ->
Log.d("UnitsViewModel", "Collecting units")
this._displayedUnits.value = units
}
}
private suspend fun setupDisplayedUnitsObserver() {
- unitsController.unitsFlow.collect { units ->
+ (unitsController.unitsFlow as StateFlow<List<UnitInformation>>).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<Map<Int, Geofence>>).collect {
Log.d("UnitsViewModel", "Collecting geofences")
this._geofences.postValue(it)
}