From 3e15173c529b2b307e813288f4728f5110fb5a78 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 4 Jan 2022 22:37:36 -0600 Subject: Implemented formatSpeed, redesigned UnitInformationFragment, added button to open device location in map, minor UI tweaks and added translations. --- .../details/information/UnitInformationFragment.kt | 85 +++++++++++++++++----- .../TrackerMap/android/devices/DevicesAdapter.kt | 23 ++++-- .../TrackerMap/android/map/UnitMapFragment.kt | 6 +- .../main/res/layout/unit_details_information.xml | 22 +----- androidApp/src/main/res/values-es-rMX/strings.xml | 29 +++++++- androidApp/src/main/res/values/dimen.xml | 2 +- androidApp/src/main/res/values/strings.xml | 21 ++++-- 7 files changed, 129 insertions(+), 59 deletions(-) (limited to 'androidApp/src') 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 758ba36..5addb51 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,19 +1,25 @@ package mx.trackermap.TrackerMap.android.details.information +import android.content.Intent +import android.net.Uri import android.os.Bundle 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 android.widget.* +import androidx.core.widget.TextViewCompat import androidx.fragment.app.Fragment +import kotlinx.coroutines.DelicateCoroutinesApi 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 mx.trackermap.TrackerMap.utils.Formatter +import mx.trackermap.TrackerMap.utils.SpeedUnit import org.koin.androidx.viewmodel.ext.android.viewModel +@DelicateCoroutinesApi class UnitInformationFragment : Fragment() { private var _binding: UnitDetailsInformationBinding? = null @@ -58,29 +64,68 @@ class UnitInformationFragment : Fragment() { private fun displayInformation(unit: UnitInformation) { val context = context!! - val details: MutableMap = 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 ?: "" + val details: MutableList> = mutableListOf() + unit.device.contact?.let { contact -> + details.add(getString(R.string.unit_info_contact) to contact) + } + unit.position?.fixTime?.let { fixTime -> + details.add(getString(R.string.unit_info_datetime) to Formatter.formatDate(fixTime)) + } + unit.position?.latitude?.let { latitude -> + details.add(getString(R.string.unit_info_latitude) to "$latitude") + } + unit.position?.longitude?.let { longitude -> + details.add(getString(R.string.unit_info_longitude) to "$longitude") + } + unit.position?.speed?.let { speed -> + details.add( + getString(R.string.unit_info_speed) to Formatter.formatSpeed( + speed, + SpeedUnit.KMH + ) + ) + } + unit.position?.address?.let { address -> + details.add(getString(R.string.unit_info_address) to address) + } + unit.position?.protocol?.let { protocol -> + details.add(getString(R.string.unit_info_protocol) to protocol) + } binding.nameDetail.text = unit.device.name details.forEach { entry -> - val row = TableRow(context) - val keyText = TextView(context) - val valueText = TextView(context) + val layout = LinearLayout(context) + layout.orientation = LinearLayout.VERTICAL + + val params = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ) + params.setMargins(0, 0, 0, resources.getDimensionPixelSize(R.dimen.padding)) + layout.layoutParams = params + + val text1 = TextView(context) + TextViewCompat.setTextAppearance(text1, R.style.TextAppearance_AppCompat_Body2) + text1.text = entry.first - row.addView(keyText) - row.addView(valueText) - binding.informationTable.addView(row) + val text2 = TextView(context) + text2.text = entry.second - keyText.text = entry.key - valueText.text = entry.value + layout.addView(text1) + layout.addView(text2) + binding.detailsLayout.addView(layout) + } + + if (unit.position?.latitude != null && unit.position?.longitude != null) { + val mapButton = Button(context) + mapButton.text = getString(R.string.unit_info_map_button) + mapButton.setOnClickListener { + val latitude = unit.position!!.latitude + val longitude = unit.position!!.longitude + val url = getString(R.string.maps_url_template, latitude, longitude) + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) + } + binding.detailsLayout.addView(mapButton) } } } \ 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 b38b20b..d715e8d 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 @@ -9,6 +9,7 @@ import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitItemBinding import mx.trackermap.TrackerMap.utils.Formatter import mx.trackermap.TrackerMap.client.models.UnitInformation +import mx.trackermap.TrackerMap.utils.SpeedUnit enum class Action { CLICK, DETAILS, REPORTS, COMMANDS @@ -67,16 +68,28 @@ class DevicesAdapter( unitName.text = unit.device.name driverName.text = unit.device.contact - unitSpeed.text = context.getString(R.string.unit_speed_format, unit.position?.speed?.toInt() ?: 0) + unitSpeed.text = Formatter.formatSpeed(unit.position?.speed ?: 0.0, SpeedUnit.KMH) lastAddress.text = unit.position?.address unit.position?.fixTime?.let { lastDate.text = Formatter.formatDate(it) } actionCallback?.let { callback -> - unitCard.setOnClickListener { callback(unit, Action.CLICK) } - detailsButton.setOnClickListener { callback(unit, Action.DETAILS) } - reportsButton.setOnClickListener { callback(unit, Action.REPORTS) } - commandsButton.setOnClickListener { callback(unit, Action.COMMANDS) } + unitCard.setOnClickListener { + swipeLayout.close() + callback(unit, Action.CLICK) + } + detailsButton.setOnClickListener { + swipeLayout.close() + callback(unit, Action.DETAILS) + } + reportsButton.setOnClickListener { + swipeLayout.close() + callback(unit, Action.REPORTS) + } + commandsButton.setOnClickListener { + swipeLayout.close() + callback(unit, Action.COMMANDS) + } } } } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt index 0d046c4..20dd59b 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt @@ -17,6 +17,7 @@ import mx.trackermap.TrackerMap.android.units.UnitsViewModel import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.utils.Formatter import mx.trackermap.TrackerMap.utils.MarkerType +import mx.trackermap.TrackerMap.utils.SpeedUnit import org.koin.androidx.viewmodel.ext.android.viewModel @DelicateCoroutinesApi @@ -106,10 +107,7 @@ class UnitMapFragment : Fragment() { unitName.text = unit.device.name driverName.text = unit.device.contact - unitSpeed.text = context.getString( - R.string.unit_speed_format, - unit.position?.speed?.toInt() ?: 0 - ) + unitSpeed.text = Formatter.formatSpeed(unit.position?.speed ?: 0.0, SpeedUnit.KMH) lastAddress.text = unit.position?.address unit.position?.fixTime?.let { lastDate.text = Formatter.formatDate(it) diff --git a/androidApp/src/main/res/layout/unit_details_information.xml b/androidApp/src/main/res/layout/unit_details_information.xml index f4b6fae..24f792c 100644 --- a/androidApp/src/main/res/layout/unit_details_information.xml +++ b/androidApp/src/main/res/layout/unit_details_information.xml @@ -17,6 +17,7 @@ app:contentPadding="@dimen/card_padding"> @@ -27,27 +28,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/colorPrimaryDark" + android:layout_marginBottom="@dimen/padding" tools:text="1AAUTO" /> - - - - - - - - - diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml index 69ca1a8..7397599 100644 --- a/androidApp/src/main/res/values-es-rMX/strings.xml +++ b/androidApp/src/main/res/values-es-rMX/strings.xml @@ -22,13 +22,34 @@ Dirección de la última posición Fecha y hora de la última posición - %1$d km/h - + Detalles Reportes Comandos Escribe para buscar - Key - Value + + Contacto + Velocidad + Dirección + Latitud + Longitud + Fecha y hora + Protocolo + Abrir ubicación en navegador + + + Enviar comando + + + Posiciones + Eventos + Paradas + Día + Semana + Mes + Periodo + Seleccionar + Evento + Fecha y hora \ No newline at end of file diff --git a/androidApp/src/main/res/values/dimen.xml b/androidApp/src/main/res/values/dimen.xml index 18fd0eb..283f476 100644 --- a/androidApp/src/main/res/values/dimen.xml +++ b/androidApp/src/main/res/values/dimen.xml @@ -15,6 +15,6 @@ 4dp - 16dp + 12dp 8dp \ No newline at end of file diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 453bc16..b50d096 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -2,6 +2,11 @@ TrackerMap + + + https://www.google.com/maps/place/%1$f,%2$f?z=19 + + Username Password @@ -22,17 +27,23 @@ Last position address Last position datetime - %1$d km/h - Details Reports Commands Type to search - - Key - Value + + Contact + Speed + Address + Latitude + Longitude + Datetime + Protocol + Open location in browser + + Send Command -- cgit v1.2.3