aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-04 22:37:36 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-04 22:37:36 -0600
commita43ed464b9dc0f7700e87e70bb60c588628d89a0 (patch)
treec2a98d78d1d82c46390af0717d2249acbd0520bd /androidApp
parentdc7e37b108bd4f63fb67b6d969518d5fbab41a6e (diff)
downloadetbsa-trackermap-mobile-a43ed464b9dc0f7700e87e70bb60c588628d89a0.tar.gz
etbsa-trackermap-mobile-a43ed464b9dc0f7700e87e70bb60c588628d89a0.tar.bz2
etbsa-trackermap-mobile-a43ed464b9dc0f7700e87e70bb60c588628d89a0.zip
Implemented formatSpeed, redesigned UnitInformationFragment, added button to open device location in map, minor UI tweaks and added translations.
Diffstat (limited to 'androidApp')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt85
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt23
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt6
-rw-r--r--androidApp/src/main/res/layout/unit_details_information.xml22
-rw-r--r--androidApp/src/main/res/values-es-rMX/strings.xml29
-rw-r--r--androidApp/src/main/res/values/dimen.xml2
-rw-r--r--androidApp/src/main/res/values/strings.xml21
7 files changed, 129 insertions, 59 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 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<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 ?: ""
+ val details: MutableList<Pair<String, String>> = 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">
<LinearLayout
+ android:id="@+id/detailsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@@ -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" />
-
- <TableLayout
- android:id="@+id/informationTable"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:stretchColumns="*">
- <TableRow
- android:background="@color/colorPrimary">
- <TextView
- android:text="@string/key"
- android:textColor="@color/background"
- android:paddingHorizontal="@dimen/padding"/>
-
- <TextView
- android:text="@string/value"
- android:textColor="@color/background"
- android:paddingHorizontal="@dimen/padding"/>
- </TableRow>
- </TableLayout>
-
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
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 @@
<string name="unit_last_address">Dirección de la última posición</string>
<string name="unit_last_date">Fecha y hora de la última posición</string>
- <string name="unit_speed_format">%1$d km/h</string>
-
+ <!-- Details -->
<string name="unit_details">Detalles</string>
<string name="unit_reports">Reportes</string>
<string name="unit_commands">Comandos</string>
<string name="units_search">Escribe para buscar</string>
- <string name="key">Key</string>
- <string name="value">Value</string>
+ <!-- Unit Information -->
+ <string name="unit_info_contact">Contacto</string>
+ <string name="unit_info_speed">Velocidad</string>
+ <string name="unit_info_address">Dirección</string>
+ <string name="unit_info_latitude">Latitud</string>
+ <string name="unit_info_longitude">Longitud</string>
+ <string name="unit_info_datetime">Fecha y hora</string>
+ <string name="unit_info_protocol">Protocolo</string>
+ <string name="unit_info_map_button">Abrir ubicación en navegador</string>
+
+ <!-- Commands -->
+ <string name="send_command">Enviar comando</string>
+
+ <!-- Reports -->
+ <string name="positions">Posiciones</string>
+ <string name="events">Eventos</string>
+ <string name="stops">Paradas</string>
+ <string name="day_period">Día</string>
+ <string name="week_period">Semana</string>
+ <string name="month_period">Mes</string>
+ <string name="period">Periodo</string>
+ <string name="select_period">Seleccionar</string>
+ <string name="table_event">Evento</string>
+ <string name="table_datetime">Fecha y hora</string>
</resources> \ 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 @@
<dimen name="search_vertical_margin">4dp</dimen>
<!-- Floating Button -->
- <dimen name="fab_margin">16dp</dimen>
+ <dimen name="fab_margin">12dp</dimen>
<dimen name="fab_elevation">8dp</dimen>
</resources> \ 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 @@
<resources>
<string name="app_name">TrackerMap</string>
+ <!-- Non translatables -->
+ <string name="maps_url_template" translatable="false">
+ https://www.google.com/maps/place/%1$f,%2$f?z=19
+ </string>
+
<!-- LoginActivity -->
<string name="login_username">Username</string>
<string name="login_password">Password</string>
@@ -22,17 +27,23 @@
<string name="unit_last_address">Last position address</string>
<string name="unit_last_date">Last position datetime</string>
- <string name="unit_speed_format">%1$d km/h</string>
-
<!-- Details -->
<string name="unit_details">Details</string>
<string name="unit_reports">Reports</string>
<string name="unit_commands">Commands</string>
<string name="units_search">Type to search</string>
- <!-- Commads -->
- <string name="key">Key</string>
- <string name="value">Value</string>
+ <!-- Unit Information -->
+ <string name="unit_info_contact">Contact</string>
+ <string name="unit_info_speed">Speed</string>
+ <string name="unit_info_address">Address</string>
+ <string name="unit_info_latitude">Latitude</string>
+ <string name="unit_info_longitude">Longitude</string>
+ <string name="unit_info_datetime">Datetime</string>
+ <string name="unit_info_protocol">Protocol</string>
+ <string name="unit_info_map_button">Open location in browser</string>
+
+ <!-- Commands -->
<string name="send_command">Send Command</string>
<!-- Reports -->