aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2021-12-16 02:08:57 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2021-12-16 02:08:57 -0600
commitbab8bb576cd741ebd928d55539286580dad07db1 (patch)
tree166965a85371aca7553058cf5ec44db890d7fd36 /androidApp/src/main
parent95af352c7ae6b7f06d3248aac18b3a65cefc803a (diff)
downloadetbsa-trackermap-mobile-bab8bb576cd741ebd928d55539286580dad07db1.tar.gz
etbsa-trackermap-mobile-bab8bb576cd741ebd928d55539286580dad07db1.tar.bz2
etbsa-trackermap-mobile-bab8bb576cd741ebd928d55539286580dad07db1.zip
Updates unit details fragment to fetch the information for the given ID
Diffstat (limited to 'androidApp/src/main')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt2
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt3
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt20
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt26
4 files changed, 47 insertions, 4 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
index e23c0de..7929832 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
@@ -1,6 +1,7 @@
package mx.trackermap.TrackerMap.android
import android.app.Application
+import mx.trackermap.TrackerMap.android.details.information.UnitInformationViewModel
import mx.trackermap.TrackerMap.android.session.LoginViewModel
import mx.trackermap.TrackerMap.android.units.UnitsViewModel
import mx.trackermap.TrackerMap.client.apis.DevicesApi
@@ -27,6 +28,7 @@ class TrackerApp : Application() {
single { UnitsController(get(), get()) }
viewModel { LoginViewModel(get(), get()) }
+ viewModel { UnitInformationViewModel() }
single { UnitsViewModel(get()) }
}
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
index 3e8f00b..12ab79e 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
@@ -12,7 +12,6 @@ class DetailsActivity: AppCompatActivity() {
private val binding get() = _binding!!
private lateinit var adapter: UnitDetailsAdapter
private var deviceId: Int = 0
- private lateinit var initialSection: Action
companion object {
val DEVICE_ID_EXTRA = "device_id"
@@ -36,7 +35,7 @@ class DetailsActivity: AppCompatActivity() {
private fun initialize() {
deviceId = intent.getIntExtra(DEVICE_ID_EXTRA, 0)
- initialSection = intent.getSerializableExtra(ACTION_EXTRA) as Action
+ val initialSection = intent.getSerializableExtra(ACTION_EXTRA) as Action
Log.d("DetailsActivity", "Device ID - $deviceId")
Log.d("DetailsActivity", "Initial Section - $initialSection")
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 3b8e7d5..7a0ed16 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
@@ -1,18 +1,22 @@
package mx.trackermap.TrackerMap.android.details.information
import android.os.Bundle
+import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import mx.trackermap.TrackerMap.android.databinding.UnitDetailsInformationBinding
import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter
+import org.koin.androidx.viewmodel.ext.android.viewModel
class UnitInformationFragment : Fragment() {
private var _binding: UnitDetailsInformationBinding? = null
private val binding get() = _binding!!
+ private val unitInformationViewModel: UnitInformationViewModel by viewModel()
+
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -24,12 +28,24 @@ class UnitInformationFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG)
- binding.unitInformationText.text = "INFORMATION for ID - $id"
+
+ setupObservers()
+ fetchInformation()
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
+
+ private fun setupObservers() {
+ unitInformationViewModel.unit.observe(this) { unitInformation ->
+ Log.d("UnitInformationFragment", "Unit Information Fetched - $unitInformation")
+ }
+ }
+
+ private fun fetchInformation() {
+ val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG)
+ unitInformationViewModel.fetchUnit(id ?: 0)
+ }
} \ No newline at end of file
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
new file mode 100644
index 0000000..e7100e1
--- /dev/null
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt
@@ -0,0 +1,26 @@
+package mx.trackermap.TrackerMap.android.details.information
+
+import android.util.Log
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import kotlinx.coroutines.DelicateCoroutinesApi
+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
+
+class UnitInformationViewModel: ViewModel(), KoinComponent {
+ @DelicateCoroutinesApi
+ private val unitsController: UnitsController by inject()
+ var unit = MutableLiveData<UnitInformation?>()
+
+ init {
+ Log.d("UnitInformationVM", "Initializing Unit Information View Model")
+ }
+
+ fun fetchUnit(deviceId: Int) {
+ unit.postValue(unitsController.getUnit(deviceId))
+ }
+} \ No newline at end of file