aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2021-12-16 04:01:24 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2021-12-16 04:01:24 -0600
commit10baf799882d7c97735334bc12b2bb987155514c (patch)
tree8f2aa0761a38a6d21f04023c78c64b9718877d2b /androidApp/src/main/java/mx
parent323e94c3a3852c63ebe00e8448f3611b59b39b97 (diff)
downloadetbsa-trackermap-mobile-10baf799882d7c97735334bc12b2bb987155514c.tar.gz
etbsa-trackermap-mobile-10baf799882d7c97735334bc12b2bb987155514c.tar.bz2
etbsa-trackermap-mobile-10baf799882d7c97735334bc12b2bb987155514c.zip
Adds an ugly table to show details
Diffstat (limited to 'androidApp/src/main/java/mx')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt40
1 files changed, 33 insertions, 7 deletions
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 1af8ec3..758ba36 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
@@ -5,9 +5,13 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.TableRow
+import android.widget.TextView
import androidx.fragment.app.Fragment
+import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.UnitDetailsInformationBinding
import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter
+import mx.trackermap.TrackerMap.client.models.UnitInformation
import org.koin.androidx.viewmodel.ext.android.viewModel
class UnitInformationFragment : Fragment() {
@@ -42,13 +46,7 @@ class UnitInformationFragment : Fragment() {
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 ?: "--"
+ displayInformation(it)
}
}
}
@@ -57,4 +55,32 @@ class UnitInformationFragment : Fragment() {
val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG)
unitInformationViewModel.fetchUnit(id ?: 0)
}
+
+ private fun displayInformation(unit: UnitInformation) {
+ val context = context!!
+ val details: MutableMap<String, String> = mutableMapOf()
+ details["Contact"] = unit.device.contact ?: ""
+ details["Speed"] = context.getString(
+ R.string.unit_speed_format,
+ unit.position?.speed?.toInt() ?: 0
+ )
+ details["Address"] = unit.position?.address ?: ""
+ details["Latitude"] = "${unit.position?.latitude}"
+ details["Longitude"] = "${unit.position?.longitude}"
+ details["Protocol"] = unit.position?.protocol ?: ""
+
+ binding.nameDetail.text = unit.device.name
+ details.forEach { entry ->
+ val row = TableRow(context)
+ val keyText = TextView(context)
+ val valueText = TextView(context)
+
+ row.addView(keyText)
+ row.addView(valueText)
+ binding.informationTable.addView(row)
+
+ keyText.text = entry.key
+ valueText.text = entry.value
+ }
+ }
} \ No newline at end of file