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 | 95af352c7ae6b7f06d3248aac18b3a65cefc803a (patch) | |
tree | eb2647294f39d691c1dd09b228ae7a91b883048b /androidApp/src/main/java/mx/trackermap/TrackerMap | |
parent | f08ef2459cfa0f3582db77372b1e534b1291cdc0 (diff) | |
download | etbsa-trackermap-mobile-95af352c7ae6b7f06d3248aac18b3a65cefc803a.tar.gz etbsa-trackermap-mobile-95af352c7ae6b7f06d3248aac18b3a65cefc803a.tar.bz2 etbsa-trackermap-mobile-95af352c7ae6b7f06d3248aac18b3a65cefc803a.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/java/mx/trackermap/TrackerMap')
7 files changed, 166 insertions, 4 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 |