From 7f1388bc554a3ee68a1865d2a219395805a79575 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 24 Jan 2022 14:51:58 -0600 Subject: Set color background to devices_fragment.xml to avoid showing map on background in certain occasions --- androidApp/src/main/res/layout/devices_fragment.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'androidApp/src') diff --git a/androidApp/src/main/res/layout/devices_fragment.xml b/androidApp/src/main/res/layout/devices_fragment.xml index 1dd1690..6e4db3f 100644 --- a/androidApp/src/main/res/layout/devices_fragment.xml +++ b/androidApp/src/main/res/layout/devices_fragment.xml @@ -2,7 +2,8 @@ + android:layout_height="match_parent" + android:background="@color/background"> Date: Mon, 31 Jan 2022 17:42:26 -0600 Subject: Tries to fix the units update issue --- .../java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt | 1 + .../mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt | 4 ++++ .../mx/trackermap/TrackerMap/controllers/UnitsController.kt | 9 ++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'androidApp/src') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt index 4371eed..a327234 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt @@ -78,6 +78,7 @@ class UnitsActivity : AppCompatActivity() { override fun onDestroy() { super.onDestroy() _binding = null + unitsViewModel.stopUpdates() } private fun setupViews() { 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 d7b6db1..8401ee7 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 @@ -90,6 +90,10 @@ class UnitsViewModel( } } + fun stopUpdates() { + unitsController.stopUpdates() + } + fun selectUnit(unit: UnitInformation) { Log.d("UnitsViewModel", "Selecting unit ${unit.device.name}") _selectedUnit.postValue(unit) diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt index b282a34..e74c7c4 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt @@ -32,6 +32,7 @@ import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.utils.Coroutines import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime +import kotlinx.coroutines.Job @DelicateCoroutinesApi @ExperimentalTime @@ -47,6 +48,8 @@ class UnitsController( private val unitsFlow = MutableStateFlow>(emptyList()) private val queryFlow = MutableStateFlow("") + private var unitsUpdateJob: Job? = null + init { GlobalScope.launch { fetchUnits(this) @@ -57,7 +60,7 @@ class UnitsController( } private suspend fun fetchUnits(scope: CoroutineScope) { - Coroutines.tickerFlow(UPDATE_TIME.seconds) + unitsUpdateJob = Coroutines.tickerFlow(UPDATE_TIME.seconds) .map { print("Fetching new positions...\n") positionsApi.positionsGet() @@ -87,6 +90,10 @@ class UnitsController( .launchIn(scope) } + fun stopUpdates() { + unitsUpdateJob?.cancel() + } + fun search(query: String) { queryFlow.value = query } -- cgit v1.2.3 From 9d753c9fa9e93171206e6036c1889ea17cac9db6 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 31 Jan 2022 22:47:33 -0600 Subject: Attach tickerFlow to viewModelScope in an attempt to bind it to app lifecycle more effectively --- .../mx/trackermap/TrackerMap/android/units/UnitsActivity.kt | 1 - .../trackermap/TrackerMap/android/units/UnitsViewModel.kt | 5 +---- .../mx/trackermap/TrackerMap/controllers/UnitsController.kt | 13 ++----------- 3 files changed, 3 insertions(+), 16 deletions(-) (limited to 'androidApp/src') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt index a327234..4371eed 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt @@ -78,7 +78,6 @@ class UnitsActivity : AppCompatActivity() { override fun onDestroy() { super.onDestroy() _binding = null - unitsViewModel.stopUpdates() } private fun setupViews() { 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 8401ee7..ba29090 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 @@ -69,6 +69,7 @@ class UnitsViewModel( init { Log.d("UnitsViewModel", "Initializing Units View Model") + unitsController.fetchUnits(viewModelScope) viewModelScope.launch { setupObservers() } @@ -90,10 +91,6 @@ class UnitsViewModel( } } - fun stopUpdates() { - unitsController.stopUpdates() - } - fun selectUnit(unit: UnitInformation) { Log.d("UnitsViewModel", "Selecting unit ${unit.device.name}") _selectedUnit.postValue(unit) diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt index e74c7c4..a5d5bd7 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt @@ -48,19 +48,14 @@ class UnitsController( private val unitsFlow = MutableStateFlow>(emptyList()) private val queryFlow = MutableStateFlow("") - private var unitsUpdateJob: Job? = null - init { - GlobalScope.launch { - fetchUnits(this) - } GlobalScope.launch { setupFlows() } } - private suspend fun fetchUnits(scope: CoroutineScope) { - unitsUpdateJob = Coroutines.tickerFlow(UPDATE_TIME.seconds) + fun fetchUnits(scope: CoroutineScope) { + Coroutines.tickerFlow(UPDATE_TIME.seconds) .map { print("Fetching new positions...\n") positionsApi.positionsGet() @@ -90,10 +85,6 @@ class UnitsController( .launchIn(scope) } - fun stopUpdates() { - unitsUpdateJob?.cancel() - } - fun search(query: String) { queryFlow.value = query } -- cgit v1.2.3