diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2022-01-12 18:37:07 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2022-01-12 18:37:07 -0600 |
commit | 9cdf080dfb589c748928657c8ce0a53b3959d3a8 (patch) | |
tree | 477afcf01a9557384a72af783d8fee7a0353470b | |
parent | 9a125dd2ca5144ae49761b73564871bb0b38c0b7 (diff) | |
download | etbsa-trackermap-mobile-9cdf080dfb589c748928657c8ce0a53b3959d3a8.tar.gz etbsa-trackermap-mobile-9cdf080dfb589c748928657c8ce0a53b3959d3a8.tar.bz2 etbsa-trackermap-mobile-9cdf080dfb589c748928657c8ce0a53b3959d3a8.zip |
Fixes the empty unit details
4 files changed, 25 insertions, 8 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt index b1c5daf..6e38ffe 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt @@ -7,7 +7,8 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.* +import android.widget.LinearLayout +import android.widget.TextView import androidx.core.widget.TextViewCompat import androidx.fragment.app.Fragment import com.google.android.material.button.MaterialButton diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt index 11daaaf..4705c00 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt @@ -9,7 +9,6 @@ import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.controllers.UnitsController import org.koin.core.component.KoinComponent -import org.koin.core.component.inject @DelicateCoroutinesApi class UnitInformationViewModel constructor( @@ -23,6 +22,8 @@ class UnitInformationViewModel constructor( } fun fetchUnit(deviceId: Int) { - unit.postValue(unitsController.getUnit(deviceId)) + viewModelScope.launch { + unit.postValue(unitsController.getUnit(deviceId)) + } } }
\ No newline at end of file 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 e198ce0..5213577 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 @@ -3,8 +3,6 @@ package mx.trackermap.TrackerMap.android.units import android.content.Intent import android.os.Bundle import android.util.Log -import android.view.Gravity -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.commit @@ -13,7 +11,6 @@ import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitsActivityBinding import mx.trackermap.TrackerMap.android.devices.DevicesFragment import mx.trackermap.TrackerMap.android.map.UnitMapFragment -import mx.trackermap.TrackerMap.android.session.LoginActivity import mx.trackermap.TrackerMap.android.session.UserInformationActivity import org.koin.androidx.viewmodel.ext.android.viewModel @@ -38,9 +35,20 @@ class UnitsActivity : AppCompatActivity() { setContentView(binding.root) setupEvents() + } + + override fun onResume() { + super.onResume() + setupObservers() } + override fun onPause() { + super.onPause() + + removeObservers() + } + override fun onDestroy() { super.onDestroy() _binding = null @@ -87,4 +95,8 @@ class UnitsActivity : AppCompatActivity() { } } } + + private fun removeObservers() { + unitsViewModel.unitsDisplayMode.removeObservers(this) + } }
\ No newline at end of file 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 576ca0e..584f656 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt @@ -51,8 +51,11 @@ class UnitsController( queryFlow.value = query } - fun getUnit(deviceId: Int): UnitInformation? { - return unitsFlow.value.firstOrNull { it.device.id == deviceId } + suspend fun getUnit(deviceId: Int): UnitInformation { + val device = devicesApi.devicesGet(id = deviceId).first() + val position = positionsApi.positionsGet(id = device.positionId).first() + + return UnitInformation(device, position) } private suspend fun setupFlows() { |