aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2021-12-16 02:52:28 -0600
committerIván Ávalos <avalos@disroot.org>2021-12-16 02:52:28 -0600
commit4ff66b74fa8f647e988f909ee0e0239b542f7fdd (patch)
tree0049335782d9ed10242ca994c3c111268768b94e /androidApp/src/main/java/mx/trackermap
parent04b33cf071672a955c3e3229f8d48de4c215dc18 (diff)
parent6ed24f2be979187d90ab3250d02d8b71fc570535 (diff)
downloadetbsa-trackermap-mobile-4ff66b74fa8f647e988f909ee0e0239b542f7fdd.tar.gz
etbsa-trackermap-mobile-4ff66b74fa8f647e988f909ee0e0239b542f7fdd.tar.bz2
etbsa-trackermap-mobile-4ff66b74fa8f647e988f909ee0e0239b542f7fdd.zip
Merge remote-tracking branch 'origin/main'
# Conflicts: # androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt # androidApp/src/main/res/layout/unit_item.xml
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap')
-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.kt57
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt34
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt34
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt60
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt26
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt34
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt7
8 files changed, 254 insertions, 0 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
new file mode 100644
index 0000000..12ab79e
--- /dev/null
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
@@ -0,0 +1,57 @@
+package mx.trackermap.TrackerMap.android.details
+
+import android.os.Bundle
+import android.util.Log
+import androidx.appcompat.app.AppCompatActivity
+import com.google.android.material.tabs.TabLayoutMediator
+import mx.trackermap.TrackerMap.android.databinding.DetailsActivityBinding
+import mx.trackermap.TrackerMap.android.devices.Action
+
+class DetailsActivity: AppCompatActivity() {
+ private var _binding: DetailsActivityBinding? = null
+ private val binding get() = _binding!!
+ private lateinit var adapter: UnitDetailsAdapter
+ private var deviceId: Int = 0
+
+ companion object {
+ val DEVICE_ID_EXTRA = "device_id"
+ val ACTION_EXTRA = "action"
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ _binding = DetailsActivityBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+
+ initialize()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+
+ _binding = null
+ }
+
+ private fun initialize() {
+ deviceId = intent.getIntExtra(DEVICE_ID_EXTRA, 0)
+ val initialSection = intent.getSerializableExtra(ACTION_EXTRA) as Action
+ Log.d("DetailsActivity", "Device ID - $deviceId")
+ Log.d("DetailsActivity", "Initial Section - $initialSection")
+
+ adapter = UnitDetailsAdapter(this, deviceId)
+ binding.detailsPager.adapter = adapter
+ TabLayoutMediator(binding.detailsTabs, binding.detailsPager) { tab, position ->
+ tab.text = when(position) {
+ 0 -> "Details"
+ 1 -> "Reports"
+ else -> "Commands"
+ }
+ }.attach()
+ binding.detailsPager.setCurrentItem(when(initialSection) {
+ Action.DETAILS -> 0
+ Action.REPORTS -> 1
+ else -> 2
+ }, false)
+ }
+} \ No newline at end of file
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt
new file mode 100644
index 0000000..df13b51
--- /dev/null
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt
@@ -0,0 +1,34 @@
+package mx.trackermap.TrackerMap.android.details
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentActivity
+import androidx.viewpager2.adapter.FragmentStateAdapter
+import mx.trackermap.TrackerMap.android.details.commands.UnitCommandsFragment
+import mx.trackermap.TrackerMap.android.details.information.UnitInformationFragment
+import mx.trackermap.TrackerMap.android.details.reports.UnitReportsFragment
+
+class UnitDetailsAdapter(
+ activity: FragmentActivity,
+ private val deviceId: Int
+) : FragmentStateAdapter(activity) {
+
+ companion object {
+ val DEVICE_ID_ARG = "device_id"
+ }
+
+ override fun getItemCount(): Int = 3
+
+ override fun createFragment(position: Int): Fragment {
+ val fragment = when (position) {
+ 0 -> UnitInformationFragment()
+ 1 -> UnitReportsFragment()
+ else -> UnitCommandsFragment()
+ }
+ fragment.arguments = Bundle().apply {
+ putInt(DEVICE_ID_ARG, deviceId)
+ }
+ return fragment
+ }
+
+} \ No newline at end of file
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt
new file mode 100644
index 0000000..0391c16
--- /dev/null
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt
@@ -0,0 +1,34 @@
+package mx.trackermap.TrackerMap.android.details.commands
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import mx.trackermap.TrackerMap.android.databinding.UnitDetailsCommandsBinding
+import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter
+
+class UnitCommandsFragment: Fragment() {
+ private var _binding: UnitDetailsCommandsBinding? = null
+ private val binding get() = _binding!!
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ _binding = UnitDetailsCommandsBinding.inflate(inflater, container, false)
+ return binding.root
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG)
+ binding.unitCommandsText.text = "COMMANDS for ID - $id"
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ _binding = null
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000..1af8ec3
--- /dev/null
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt
@@ -0,0 +1,60 @@
+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?,
+ savedInstanceState: Bundle?
+ ): View {
+ _binding = UnitDetailsInformationBinding.inflate(inflater, container, false)
+ return binding.root
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ setupObservers()
+ fetchInformation()
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ _binding = null
+ }
+
+ private fun setupObservers() {
+ unitInformationViewModel.unit.observe(this) { unitInformation ->
+ Log.d("UnitInformationFragment", "Unit Information Fetched - $unitInformation")
+ unitInformation?.let {
+ binding.deviceName.text = it.device.name
+ binding.driverDetail.text = it.device.contact
+ binding.speedDetail.text = "${it.position?.speed?.times(1.852) ?: "--"} Km/h"
+ binding.addressDetail.text = it.position?.address ?: "Unknown location"
+ binding.latitudeDetail.text = it.position?.latitude.toString()
+ binding.longitudeDetail.text = it.position?.longitude.toString()
+ binding.protocolDetail.text = it.position?.protocol ?: "--"
+ }
+ }
+ }
+
+ 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
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
new file mode 100644
index 0000000..a2faec8
--- /dev/null
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt
@@ -0,0 +1,34 @@
+package mx.trackermap.TrackerMap.android.details.reports
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import mx.trackermap.TrackerMap.android.databinding.UnitDetailsReportsBinding
+import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter
+
+class UnitReportsFragment: Fragment() {
+ private var _binding: UnitDetailsReportsBinding? = null
+ private val binding get() = _binding!!
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ _binding = UnitDetailsReportsBinding.inflate(inflater, container, false)
+ return binding.root
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG)
+ binding.unitReportsText.text = "COMMANDS for ID - $id"
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ _binding = null
+ }
+} \ No newline at end of file
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 a3ed7a8..6beacec 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,5 +1,6 @@
package mx.trackermap.TrackerMap.android.devices
+import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -9,6 +10,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.databinding.DevicesFragmentBinding
+import mx.trackermap.TrackerMap.android.details.DetailsActivity
import mx.trackermap.TrackerMap.android.units.UnitsViewModel
import mx.trackermap.TrackerMap.client.models.UnitInformation
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -62,5 +64,10 @@ class DevicesFragment : Fragment() {
private fun itemAction(unit: UnitInformation, action: Action) {
Log.d("DevicesFragment", "Action: $action - Unit: $unit")
+ val activity = requireActivity()
+ val intent = Intent(activity.applicationContext, DetailsActivity::class.java)
+ intent.putExtra(DetailsActivity.DEVICE_ID_EXTRA, unit.device.id)
+ intent.putExtra(DetailsActivity.ACTION_EXTRA, action)
+ startActivity(intent)
}
} \ No newline at end of file