diff options
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/details')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt | 85 |
1 files changed, 65 insertions, 20 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 |