diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-16 01:50:17 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-16 01:50:17 -0600 |
commit | 36b7d109fa1e8c5a7c5fc262a3b0d7b1286e07c8 (patch) | |
tree | 85c61ca55fc2d05b8a4ee8e505b05b2d599610bb /androidApp/src/main | |
parent | 547ce2e85e5b22e7c31f5a51df149919260d54b0 (diff) | |
download | etbsa-trackermap-mobile-36b7d109fa1e8c5a7c5fc262a3b0d7b1286e07c8.tar.gz etbsa-trackermap-mobile-36b7d109fa1e8c5a7c5fc262a3b0d7b1286e07c8.tar.bz2 etbsa-trackermap-mobile-36b7d109fa1e8c5a7c5fc262a3b0d7b1286e07c8.zip |
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
Diffstat (limited to 'androidApp/src/main')
12 files changed, 237 insertions, 9 deletions
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"> - <TextView - android:layout_width="wrap_content" + <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" - android:text="DETAILS"/> + 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..1e88af8 --- /dev/null +++ b/androidApp/src/main/res/layout/unit_details_information.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/unitInformationText" + 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="INFORMATION"/> + +</androidx.constraintlayout.widget.ConstraintLayout>
\ 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 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"/> <LinearLayout android:id="@+id/itemOptions" |