aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2021-12-08 04:28:51 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2021-12-08 04:28:51 -0600
commit04c2889895483f5925c90ed7a856d38391fcab45 (patch)
tree896334a1d8a0540b9d54c7390db2d78e61cadb1b /androidApp/src/main/java/mx/trackermap
parentd2ee6a21355c390a4aaefc6ea847060c8e47c6ae (diff)
downloadetbsa-trackermap-mobile-04c2889895483f5925c90ed7a856d38391fcab45.tar.gz
etbsa-trackermap-mobile-04c2889895483f5925c90ed7a856d38391fcab45.tar.bz2
etbsa-trackermap-mobile-04c2889895483f5925c90ed7a856d38391fcab45.zip
WIP: Implements the basic structure for the units list/map
- Updates the Devices and Positions APIs to properly construct the Url's query when there are null values - Adds a units controller to the shared module - Adds a devices and map fragment that each print the fetched units on the console - Adds a units view model to connect previously mentioned fragments with the units controller
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt4
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt19
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt19
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt37
4 files changed, 76 insertions, 3 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 b236577..e23c0de 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
@@ -6,6 +6,7 @@ import mx.trackermap.TrackerMap.android.units.UnitsViewModel
import mx.trackermap.TrackerMap.client.apis.DevicesApi
import mx.trackermap.TrackerMap.client.apis.PositionsApi
import mx.trackermap.TrackerMap.client.apis.SessionApi
+import mx.trackermap.TrackerMap.controllers.UnitsController
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.viewmodel.dsl.viewModel
@@ -23,9 +24,10 @@ class TrackerApp : Application() {
single { SessionApi(get()) }
single { DevicesApi(get()) }
single { PositionsApi(get()) }
+ single { UnitsController(get(), get()) }
viewModel { LoginViewModel(get(), get()) }
- viewModel { UnitsViewModel() }
+ single { UnitsViewModel(get()) }
}
startKoin {
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
index 7e09b17..98c98cc 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
@@ -1,16 +1,22 @@
package mx.trackermap.TrackerMap.android.devices
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 kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.databinding.DevicesFragmentBinding
+import mx.trackermap.TrackerMap.android.units.UnitsViewModel
+import org.koin.androidx.viewmodel.ext.android.viewModel
class DevicesFragment: Fragment() {
private var _binding: DevicesFragmentBinding? = null
private val binding get() = _binding!!
+ private val unitsViewModel: UnitsViewModel by viewModel()
+
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -24,4 +30,17 @@ class DevicesFragment: Fragment() {
super.onDestroyView()
_binding = null
}
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ setupObservers()
+ }
+
+ @DelicateCoroutinesApi
+ private fun setupObservers() {
+ unitsViewModel.units.observe(this) { units ->
+ Log.d("DevicesFragment", "Success $units")
+ }
+ }
} \ No newline at end of file
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 0d4d91a..2ffaa2c 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
@@ -1,16 +1,22 @@
package mx.trackermap.TrackerMap.android.map
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 kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.databinding.MapFragmentBinding
+import mx.trackermap.TrackerMap.android.units.UnitsViewModel
+import org.koin.androidx.viewmodel.ext.android.viewModel
class MapFragment: Fragment() {
private var _binding: MapFragmentBinding? = null
private val binding get() = _binding!!
+ private val unitsViewModel: UnitsViewModel by viewModel()
+
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -24,4 +30,17 @@ class MapFragment: Fragment() {
super.onDestroyView()
_binding = null
}
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ setupObservers()
+ }
+
+ @DelicateCoroutinesApi
+ private fun setupObservers() {
+ unitsViewModel.units.observe(this) { units ->
+ Log.d("MapFragment", "Success $units")
+ }
+ }
} \ No newline at end of file
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 11df89b..7ac6e28 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
@@ -2,15 +2,44 @@ package mx.trackermap.TrackerMap.android.units
import android.util.Log
import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import kotlinx.coroutines.DelicateCoroutinesApi
+import kotlinx.coroutines.flow.collect
+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 UnitsViewModel : ViewModel() {
+@DelicateCoroutinesApi
+class UnitsViewModel(
+ private val savedStateHandle: SavedStateHandle
+) : ViewModel(), KoinComponent {
enum class UnitsDisplayMode {
MAP, LIST
}
- var unitsDisplayMode = MutableLiveData<UnitsDisplayMode>(UnitsDisplayMode.MAP)
+ private val unitsController: UnitsController by inject()
+
+ var unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP)
+ var units = MutableLiveData<List<UnitInformation>>()
+
+ init {
+ Log.d("UnitsViewModel", "Initializing Units View Model")
+ viewModelScope.launch {
+ setupObservers()
+ }
+ }
+
+ private suspend fun setupObservers() {
+ Log.d("UnitsViewModel", "Setup observers")
+ unitsController.displayedUnitsFlow.collect { units ->
+ this.units.value = units
+ }
+ }
fun toggleDisplayMode() {
Log.d("UnitsViewModel", "Toggling Display mode")
@@ -22,4 +51,8 @@ class UnitsViewModel : ViewModel() {
}
unitsDisplayMode.postValue(newDisplayMode)
}
+
+ fun search(query: String) {
+ unitsController.search(query)
+ }
} \ No newline at end of file