aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2021-12-15 00:28:54 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2021-12-15 00:28:54 -0600
commit14dff03d1d705722d8184724f296deff557a3014 (patch)
tree09ae59ecd4f158683aba2c3e5131fcca8ecf4fa6 /androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices
parent6674ec486e3ffcf0a3d2a19e7f7bf7f963722264 (diff)
downloadetbsa-trackermap-mobile-14dff03d1d705722d8184724f296deff557a3014.tar.gz
etbsa-trackermap-mobile-14dff03d1d705722d8184724f296deff557a3014.tar.bz2
etbsa-trackermap-mobile-14dff03d1d705722d8184724f296deff557a3014.zip
Updates the devices list
- The unit items now react to user interaction, they display and change their appearance on click - The adapter has a callback to manage the different options - Minor changes to dimen values
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt30
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt20
2 files changed, 41 insertions, 9 deletions
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 72d61e3..4aa210d 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
@@ -4,11 +4,20 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
+import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.UnitItemBinding
import mx.trackermap.TrackerMap.client.models.UnitInformation
-class DevicesAdapter(private val units: List<UnitInformation>) :
- RecyclerView.Adapter<DevicesAdapter.ViewHolder>() {
+enum class Action {
+ DETAILS, REPORTS, COMMANDS
+}
+
+typealias ActionCallback = (unit: UnitInformation, action: Action) -> Unit
+
+class DevicesAdapter(
+ private val units: List<UnitInformation>,
+ private val actionCallback: ActionCallback?
+) : RecyclerView.Adapter<DevicesAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = UnitItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
@@ -26,6 +35,11 @@ class DevicesAdapter(private val units: List<UnitInformation>) :
unitSpeed.text = "${unit.position?.speed ?: "--"} Km/h"
lastAddress.text = unit.position?.address ?: "Unknown location"
lastDate.text = "yyyy/mm/dd, hh:mm"
+ actionCallback?.let { callback ->
+ detailsButton.setOnClickListener { callback(unit, Action.DETAILS) }
+ reportsButton.setOnClickListener { callback(unit, Action.REPORTS) }
+ commandsButton.setOnClickListener { callback(unit, Action.COMMANDS) }
+ }
}
}
@@ -38,9 +52,15 @@ class DevicesAdapter(private val units: List<UnitInformation>) :
}
}
- fun toggleOptions(shouldShow: Boolean) {
- binding.itemOptions.visibility = if (shouldShow) View.VISIBLE else View.GONE
- binding.unitCard.cardElevation = if (shouldShow) 5.0F else 0.0F
+ fun toggleOptions(shouldExpand: Boolean) {
+ val context = binding.root.context
+ binding.unitCard.setCardBackgroundColor(
+ context
+ .resources
+ .getColor(if (shouldExpand) R.color.background else R.color.darkBackground)
+ )
+ binding.itemOptions.visibility = if (shouldExpand) View.VISIBLE else View.GONE
+ binding.unitCard.cardElevation = if (shouldExpand) 5.0F else 0.0F
}
}
} \ 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 4ac5d48..a3ed7a8 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
@@ -10,9 +10,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.databinding.DevicesFragmentBinding
import mx.trackermap.TrackerMap.android.units.UnitsViewModel
+import mx.trackermap.TrackerMap.client.models.UnitInformation
import org.koin.androidx.viewmodel.ext.android.viewModel
-class DevicesFragment: Fragment() {
+class DevicesFragment : Fragment() {
+
private var _binding: DevicesFragmentBinding? = null
private val binding get() = _binding!!
@@ -40,15 +42,25 @@ class DevicesFragment: Fragment() {
}
private fun setupList() {
- binding.devicesList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
- binding.devicesList.adapter = DevicesAdapter(emptyList())
+ binding.devicesList.layoutManager = LinearLayoutManager(
+ context, LinearLayoutManager.VERTICAL,
+ false
+ )
+ binding.devicesList.adapter = DevicesAdapter(emptyList(), null)
}
@DelicateCoroutinesApi
private fun setupObservers() {
unitsViewModel.units.observe(this) { units ->
Log.d("DevicesFragment", "Success $units")
- binding.devicesList.swapAdapter(DevicesAdapter(units), false)
+ binding.devicesList.swapAdapter(
+ DevicesAdapter(units, this::itemAction),
+ false
+ )
}
}
+
+ private fun itemAction(unit: UnitInformation, action: Action) {
+ Log.d("DevicesFragment", "Action: $action - Unit: $unit")
+ }
} \ No newline at end of file