diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-04 22:37:36 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-04 22:37:36 -0600 |
commit | 3e15173c529b2b307e813288f4728f5110fb5a78 (patch) | |
tree | e0bb58b98b6667a01190ed25b4b24d29a1c71568 /androidApp/src/main/java | |
parent | 793ccb0b907ac4b1364efd3e9a8df558c0346249 (diff) | |
download | etbsa-trackermap-mobile-3e15173c529b2b307e813288f4728f5110fb5a78.tar.gz etbsa-trackermap-mobile-3e15173c529b2b307e813288f4728f5110fb5a78.tar.bz2 etbsa-trackermap-mobile-3e15173c529b2b307e813288f4728f5110fb5a78.zip |
Implemented formatSpeed, redesigned UnitInformationFragment, added button to open device location in map, minor UI tweaks and added translations.
Diffstat (limited to 'androidApp/src/main/java')
3 files changed, 85 insertions, 29 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) |