From 547ce2e85e5b22e7c31f5a51df149919260d54b0 Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Wed, 15 Dec 2021 01:00:37 -0600 Subject: Adds the details activity --- androidApp/src/main/AndroidManifest.xml | 3 ++ .../TrackerMap/android/details/DetailsActivity.kt | 32 ++++++++++++++++++++++ .../TrackerMap/android/devices/DevicesFragment.kt | 8 ++++++ .../src/main/res/layout/details_activity.xml | 17 ++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt create mode 100644 androidApp/src/main/res/layout/details_activity.xml (limited to 'androidApp') 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 @@ + \ No newline at end of file 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..c9769e4 --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt @@ -0,0 +1,32 @@ +package mx.trackermap.TrackerMap.android.details + +import android.os.Bundle +import android.util.Log +import androidx.appcompat.app.AppCompatActivity +import mx.trackermap.TrackerMap.android.databinding.DetailsActivityBinding + +class DetailsActivity: AppCompatActivity() { + private var _binding: DetailsActivityBinding? = null + private val binding get() = _binding!! + + 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) + + Log.d("DetailsActivity", "Device ID - ${intent.getIntExtra(DEVICE_ID_EXTRA, 0)}") + Log.d("DetailsActivity", "Device ID - ${intent.getSerializableExtra(ACTION_EXTRA)}") + } + + override fun onDestroy() { + super.onDestroy() + + _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..2c11dc2 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,8 @@ 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.UnitsActivity import mx.trackermap.TrackerMap.android.units.UnitsViewModel import mx.trackermap.TrackerMap.client.models.UnitInformation import org.koin.androidx.viewmodel.ext.android.viewModel @@ -62,5 +65,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..1a50487 --- /dev/null +++ b/androidApp/src/main/res/layout/details_activity.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file -- cgit v1.2.3 From 36b7d109fa1e8c5a7c5fc262a3b0d7b1286e07c8 Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Thu, 16 Dec 2021 01:50:17 -0600 Subject: Shows the details section - Show tabs with each details section, the sections doesn't display any useful information for now - Properly converts speed to km/h --- .../TrackerMap/android/details/DetailsActivity.kt | 30 +++++++++++++++++-- .../android/details/UnitDetailsAdapter.kt | 34 +++++++++++++++++++++ .../details/commands/UnitCommandsFragment.kt | 34 +++++++++++++++++++++ .../details/information/UnitInformationFragment.kt | 35 ++++++++++++++++++++++ .../android/details/reports/UnitReportsFragment.kt | 34 +++++++++++++++++++++ .../TrackerMap/android/devices/DevicesAdapter.kt | 2 +- .../TrackerMap/android/devices/DevicesFragment.kt | 1 - .../src/main/res/layout/details_activity.xml | 16 +++++++--- .../src/main/res/layout/unit_details_commands.xml | 19 ++++++++++++ .../main/res/layout/unit_details_information.xml | 19 ++++++++++++ .../src/main/res/layout/unit_details_reports.xml | 19 ++++++++++++ androidApp/src/main/res/layout/unit_item.xml | 3 +- 12 files changed, 237 insertions(+), 9 deletions(-) create mode 100644 androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/UnitDetailsAdapter.kt create mode 100644 androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt create mode 100644 androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt create mode 100644 androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt create mode 100644 androidApp/src/main/res/layout/unit_details_commands.xml create mode 100644 androidApp/src/main/res/layout/unit_details_information.xml create mode 100644 androidApp/src/main/res/layout/unit_details_reports.xml (limited to 'androidApp') 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 c9769e4..3e8f00b 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 @@ -3,11 +3,16 @@ 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 + private lateinit var initialSection: Action companion object { val DEVICE_ID_EXTRA = "device_id" @@ -20,8 +25,7 @@ class DetailsActivity: AppCompatActivity() { _binding = DetailsActivityBinding.inflate(layoutInflater) setContentView(binding.root) - Log.d("DetailsActivity", "Device ID - ${intent.getIntExtra(DEVICE_ID_EXTRA, 0)}") - Log.d("DetailsActivity", "Device ID - ${intent.getSerializableExtra(ACTION_EXTRA)}") + initialize() } override fun onDestroy() { @@ -29,4 +33,26 @@ class DetailsActivity: AppCompatActivity() { _binding = null } + + private fun initialize() { + deviceId = intent.getIntExtra(DEVICE_ID_EXTRA, 0) + 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..3b8e7d5 --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt @@ -0,0 +1,35 @@ +package mx.trackermap.TrackerMap.android.details.information + +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.UnitDetailsInformationBinding +import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter + +class UnitInformationFragment : Fragment() { + + private var _binding: UnitDetailsInformationBinding? = null + private val binding get() = _binding!! + + 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) + val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) + binding.unitInformationText.text = "INFORMATION 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/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/DevicesAdapter.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt index 4aa210d..5d512f0 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt @@ -32,7 +32,7 @@ class DevicesAdapter( holder.binding.apply { unitName.text = unit.device.name driverName.text = unit.device.contact - unitSpeed.text = "${unit.position?.speed ?: "--"} Km/h" + unitSpeed.text = "${unit.position?.speed?.times(1.852) ?: "--"} Km/h" lastAddress.text = unit.position?.address ?: "Unknown location" lastDate.text = "yyyy/mm/dd, hh:mm" actionCallback?.let { callback -> 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 2c11dc2..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 @@ -11,7 +11,6 @@ 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.UnitsActivity import mx.trackermap.TrackerMap.android.units.UnitsViewModel import mx.trackermap.TrackerMap.client.models.UnitInformation import org.koin.androidx.viewmodel.ext.android.viewModel diff --git a/androidApp/src/main/res/layout/details_activity.xml b/androidApp/src/main/res/layout/details_activity.xml index 1a50487..00ebdbf 100644 --- a/androidApp/src/main/res/layout/details_activity.xml +++ b/androidApp/src/main/res/layout/details_activity.xml @@ -5,13 +5,21 @@ android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> - + + + app:layout_constraintBottom_toBottomOf="parent"/> \ 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 @@ + + + + + + \ 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..1e88af8 --- /dev/null +++ b/androidApp/src/main/res/layout/unit_details_information.xml @@ -0,0 +1,19 @@ + + + + + + \ 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 @@ + + + + + + \ No newline at end of file diff --git a/androidApp/src/main/res/layout/unit_item.xml b/androidApp/src/main/res/layout/unit_item.xml index cdf0610..d3601bb 100644 --- a/androidApp/src/main/res/layout/unit_item.xml +++ b/androidApp/src/main/res/layout/unit_item.xml @@ -50,7 +50,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18dp" - tools:text="4 de Diciembre de 2021, 7:00 PM" /> + tools:text="4 de Diciembre de 2021, 7:00 PM" + android:visibility="gone"/> Date: Thu, 16 Dec 2021 02:08:57 -0600 Subject: Updates unit details fragment to fetch the information for the given ID --- .../mx/trackermap/TrackerMap/android/TrackerApp.kt | 2 ++ .../TrackerMap/android/details/DetailsActivity.kt | 3 +-- .../details/information/UnitInformationFragment.kt | 20 +++++++++++++++-- .../information/UnitInformationViewModel.kt | 26 ++++++++++++++++++++++ .../TrackerMap/controllers/UnitsController.kt | 4 ++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationViewModel.kt (limited to 'androidApp') 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() + + 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/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt index 29c84f4..db6d9b3 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt @@ -51,6 +51,10 @@ class UnitsController( queryFlow.value = query } + fun getUnit(deviceId: Int): UnitInformation? { + return unitsFlow.value.firstOrNull { it.device.id == deviceId } + } + private suspend fun setupFlows() { unitsFlow.combine(queryFlow) { units, query -> units.filter { unit -> -- cgit v1.2.3 From 6ed24f2be979187d90ab3250d02d8b71fc570535 Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Thu, 16 Dec 2021 02:38:42 -0600 Subject: Adds a very basic UI to display details --- .../details/information/UnitInformationFragment.kt | 9 +++ .../main/res/layout/unit_details_information.xml | 89 +++++++++++++++++++--- 2 files changed, 86 insertions(+), 12 deletions(-) (limited to 'androidApp') 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 7a0ed16..1af8ec3 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 @@ -41,6 +41,15 @@ class UnitInformationFragment : Fragment() { 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 ?: "--" + } } } diff --git a/androidApp/src/main/res/layout/unit_details_information.xml b/androidApp/src/main/res/layout/unit_details_information.xml index 1e88af8..dae2056 100644 --- a/androidApp/src/main/res/layout/unit_details_information.xml +++ b/androidApp/src/main/res/layout/unit_details_information.xml @@ -1,19 +1,84 @@ - + android:orientation="vertical" + android:scrollbars="vertical"> - + app:cardCornerRadius="@dimen/card_border_radius" + app:cardElevation="@dimen/card_elevation" + app:cardUseCompatPadding="true" + app:contentPadding="@dimen/card_padding"> + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + \ No newline at end of file -- cgit v1.2.3