aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp')
-rw-r--r--androidApp/src/main/AndroidManifest.xml3
-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
-rw-r--r--androidApp/src/main/res/layout/details_activity.xml25
-rw-r--r--androidApp/src/main/res/layout/unit_details_commands.xml19
-rw-r--r--androidApp/src/main/res/layout/unit_details_information.xml84
-rw-r--r--androidApp/src/main/res/layout/unit_details_reports.xml19
13 files changed, 404 insertions, 0 deletions
diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml
index 889342f..5d56847 100644
--- a/androidApp/src/main/AndroidManifest.xml
+++ b/androidApp/src/main/AndroidManifest.xml
@@ -23,5 +23,8 @@
<activity
android:name=".units.UnitsActivity"
android:exported="false"/>
+ <activity
+ android:name=".details.DetailsActivity"
+ android:exported="false"/>
</application>
</manifest> \ No newline at end of file
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
diff --git a/androidApp/src/main/res/layout/details_activity.xml b/androidApp/src/main/res/layout/details_activity.xml
new file mode 100644
index 0000000..00ebdbf
--- /dev/null
+++ b/androidApp/src/main/res/layout/details_activity.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <com.google.android.material.tabs.TabLayout
+ android:id="@+id/detailsTabs"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"/>
+
+ <androidx.viewpager2.widget.ViewPager2
+ android:id="@+id/detailsPager"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ app:layout_constraintTop_toBottomOf="@id/detailsTabs"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"/>
+
+</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
diff --git a/androidApp/src/main/res/layout/unit_details_commands.xml b/androidApp/src/main/res/layout/unit_details_commands.xml
new file mode 100644
index 0000000..dfd6516
--- /dev/null
+++ b/androidApp/src/main/res/layout/unit_details_commands.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools">
+
+ <TextView
+ android:id="@+id/unitCommandsText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ tools:text="COMMANDS"/>
+
+</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
diff --git a/androidApp/src/main/res/layout/unit_details_information.xml b/androidApp/src/main/res/layout/unit_details_information.xml
new file mode 100644
index 0000000..dae2056
--- /dev/null
+++ b/androidApp/src/main/res/layout/unit_details_information.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:scrollbars="vertical">
+
+ <com.google.android.material.card.MaterialCardView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:cardCornerRadius="@dimen/card_border_radius"
+ app:cardElevation="@dimen/card_elevation"
+ app:cardUseCompatPadding="true"
+ app:contentPadding="@dimen/card_padding">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/deviceName"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:textSize="26dp"
+ tools:text="1AAUTO" />
+
+ <TextView
+ android:id="@+id/driverDetail"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:textSize="18dp"
+ tools:text="Javier Zavala" />
+
+ <TextView
+ android:id="@+id/speedDetail"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:textSize="18dp"
+ tools:text="0Km/h - Stopped" />
+
+ <TextView
+ android:id="@+id/addressDetail"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:textSize="18dp"
+ tools:text="404 Av. Arboledas, Celaya, Gto." />
+
+ <TextView
+ android:id="@+id/latitudeDetail"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:textSize="18dp"
+ tools:text="20.32958356" />
+
+ <TextView
+ android:id="@+id/longitudeDetail"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:textSize="18dp"
+ tools:text="-101.38659274" />
+
+ <TextView
+ android:id="@+id/protocolDetail"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/colorPrimaryDark"
+ android:textSize="18dp"
+ tools:text="osmand" />
+
+ </LinearLayout>
+
+ </com.google.android.material.card.MaterialCardView>
+
+</LinearLayout> \ No newline at end of file
diff --git a/androidApp/src/main/res/layout/unit_details_reports.xml b/androidApp/src/main/res/layout/unit_details_reports.xml
new file mode 100644
index 0000000..f1b52e3
--- /dev/null
+++ b/androidApp/src/main/res/layout/unit_details_reports.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools">
+
+ <TextView
+ android:id="@+id/unitReportsText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ tools:text="REPORTS"/>
+
+</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file