diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-13 04:18:54 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-13 04:18:54 -0600 |
commit | 15c8f18da01b661d4f23dc25bee0b4b31355bbea (patch) | |
tree | 28b4e3f62bc8e707572e9710675e92f741fc3113 /androidApp/src/main/java/mx/trackermap | |
parent | 5e07a10d16501ec047a021ddef52d22474375a2a (diff) | |
download | etbsa-trackermap-mobile-15c8f18da01b661d4f23dc25bee0b4b31355bbea.tar.gz etbsa-trackermap-mobile-15c8f18da01b661d4f23dc25bee0b4b31355bbea.tar.bz2 etbsa-trackermap-mobile-15c8f18da01b661d4f23dc25bee0b4b31355bbea.zip |
Added device icon to unit_item.xml (+ a11y) and moved category logic to MarkerTransformations
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap')
4 files changed, 81 insertions, 29 deletions
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 d42a8aa..175e908 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 @@ -28,6 +28,7 @@ class DevicesAdapter( UnitRenderData.render( UnitRenderData.UnitRenderViewHolder( unitName = unitName, + unitIcon = unitIcon, statusIcon = statusIcon, engineStopIcon = engineStopIcon, gridLayout = gridLayout, diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt index 39ef472..beeba6f 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt @@ -13,6 +13,7 @@ import androidx.cardview.widget.CardView import androidx.core.content.ContextCompat import com.zerobranch.layout.SwipeLayout import mx.trackermap.TrackerMap.android.R +import mx.trackermap.TrackerMap.android.map.MarkerTransformations import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.utils.Formatter import mx.trackermap.TrackerMap.utils.SpeedUnit @@ -22,6 +23,7 @@ typealias ActionCallback = (unit: UnitInformation, action: Action) -> Unit class UnitRenderData { data class UnitRenderViewHolder( val unitName: TextView, + val unitIcon: ImageView? = null, val statusIcon: ImageView, val engineStopIcon: ImageView, val gridLayout: GridLayout, @@ -45,6 +47,14 @@ class UnitRenderData { /* Device name */ unitName.text = unit.device.name + /* Device icon */ + unitIcon?.setImageResource( + MarkerTransformations.categoryToResourceId(unit.device.category) + ) + unitIcon?.contentDescription = context.getString( + MarkerTransformations.categoryToStringId(unit.device.category) + ) + /* Contact */ unit.device.contact?.let { contact -> if (contact.isNotEmpty()) { diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt index 002b981..34ff655 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt @@ -317,32 +317,7 @@ class MapFragment : GlobeMapFragment() { private fun getIcon(markerType: MarkerType): Bitmap { return ResourcesCompat.getDrawable( activity!!.resources, - when (markerType) { - MarkerType.ANIMAL -> R.drawable.map_animal - MarkerType.BICYCLE -> R.drawable.map_bicycle - MarkerType.BOAT -> R.drawable.map_boat - MarkerType.BUS -> R.drawable.map_bus - MarkerType.CAR -> R.drawable.map_car - MarkerType.CRANE -> R.drawable.map_crane - MarkerType.DEFAULT -> R.drawable.map_default - MarkerType.HELICOPTER -> R.drawable.map_helicopter - MarkerType.MOTORCYCLE -> R.drawable.map_motorcycle - MarkerType.OFFROAD -> R.drawable.map_offroad - MarkerType.PERSON -> R.drawable.map_person - MarkerType.PICKUP -> R.drawable.map_pickup - MarkerType.PLANE -> R.drawable.map_plane - MarkerType.SCOOTER -> R.drawable.map_scooter - MarkerType.SHIP -> R.drawable.map_ship - MarkerType.TRACTOR -> R.drawable.map_tractor - MarkerType.TRAIN -> R.drawable.map_train - MarkerType.TRAM -> R.drawable.map_tram - MarkerType.TROLLEYBUS -> R.drawable.map_trolleybus - MarkerType.TRUCK -> R.drawable.map_truck - MarkerType.VAN -> R.drawable.map_van - - MarkerType.REPORT_POSITION -> R.drawable.map_report_position - MarkerType.REPORT_START -> R.drawable.map_report_start - MarkerType.REPORT_END -> R.drawable.map_report_end - }, activity!!.theme)!!.toBitmap(144, 144) + MarkerTransformations.markerTypeToResourceId(markerType), + activity!!.theme)!!.toBitmap(144, 144) } }
\ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt index b1d52fb..e77471b 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt @@ -1,5 +1,6 @@ package mx.trackermap.TrackerMap.android.map +import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.client.models.Position import mx.trackermap.TrackerMap.client.models.Stop import mx.trackermap.TrackerMap.client.models.UnitInformation @@ -46,8 +47,8 @@ object MarkerTransformations { ) } - private fun categoryToMarkerType(category: String): MarkerType { - return when (category.lowercase()) { + private fun categoryToMarkerType(category: String?): MarkerType { + return when (category?.lowercase()) { "animal" -> MarkerType.ANIMAL "bicycle" -> MarkerType.BICYCLE "boat" -> MarkerType.BOAT @@ -71,4 +72,69 @@ object MarkerTransformations { else -> MarkerType.DEFAULT } } + + fun markerTypeToResourceId(markerType: MarkerType): Int { + return when (markerType) { + MarkerType.ANIMAL -> R.drawable.map_animal + MarkerType.BICYCLE -> R.drawable.map_bicycle + MarkerType.BOAT -> R.drawable.map_boat + MarkerType.BUS -> R.drawable.map_bus + MarkerType.CAR -> R.drawable.map_car + MarkerType.CRANE -> R.drawable.map_crane + MarkerType.DEFAULT -> R.drawable.map_default + MarkerType.HELICOPTER -> R.drawable.map_helicopter + MarkerType.MOTORCYCLE -> R.drawable.map_motorcycle + MarkerType.OFFROAD -> R.drawable.map_offroad + MarkerType.PERSON -> R.drawable.map_person + MarkerType.PICKUP -> R.drawable.map_pickup + MarkerType.PLANE -> R.drawable.map_plane + MarkerType.SCOOTER -> R.drawable.map_scooter + MarkerType.SHIP -> R.drawable.map_ship + MarkerType.TRACTOR -> R.drawable.map_tractor + MarkerType.TRAIN -> R.drawable.map_train + MarkerType.TRAM -> R.drawable.map_tram + MarkerType.TROLLEYBUS -> R.drawable.map_trolleybus + MarkerType.TRUCK -> R.drawable.map_truck + MarkerType.VAN -> R.drawable.map_van + + MarkerType.REPORT_POSITION -> R.drawable.map_report_position + MarkerType.REPORT_START -> R.drawable.map_report_start + MarkerType.REPORT_END -> R.drawable.map_report_end + } + } + + fun markerTypeToStringId(markerType: MarkerType): Int { + return when (markerType) { + MarkerType.ANIMAL -> R.string.unit_category_animal + MarkerType.BICYCLE -> R.string.unit_category_bicycle + MarkerType.BOAT -> R.string.unit_category_boat + MarkerType.BUS -> R.string.unit_category_bus + MarkerType.CAR -> R.string.unit_category_car + MarkerType.CRANE -> R.string.unit_category_crane + MarkerType.DEFAULT -> R.string.unit_category_default + MarkerType.HELICOPTER -> R.string.unit_category_helicopter + MarkerType.MOTORCYCLE -> R.string.unit_category_motorcycle + MarkerType.OFFROAD -> R.string.unit_category_offroad + MarkerType.PERSON -> R.string.unit_category_person + MarkerType.PICKUP -> R.string.unit_category_pickup + MarkerType.PLANE -> R.string.unit_category_plane + MarkerType.SCOOTER -> R.string.unit_category_scooter + MarkerType.SHIP -> R.string.unit_category_ship + MarkerType.TRACTOR -> R.string.unit_category_tractor + MarkerType.TRAIN -> R.string.unit_category_train + MarkerType.TRAM -> R.string.unit_category_tram + MarkerType.TROLLEYBUS -> R.string.unit_category_trolleybus + MarkerType.TRUCK -> R.string.unit_category_truck + MarkerType.VAN -> R.string.unit_category_van + else -> R.string.unit_category_default + } + } + + fun categoryToResourceId(category: String?): Int { + return markerTypeToResourceId(categoryToMarkerType(category)) + } + + fun categoryToStringId(category: String?): Int { + return markerTypeToResourceId(categoryToMarkerType(category)) + } }
\ No newline at end of file |