From a13e418f74397653e028e38084f0f8f09492419e Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Wed, 12 Jan 2022 22:39:04 -0600 Subject: Implemented map layer switching and updated strings.xml --- .../TrackerMap/android/details/DetailsActivity.kt | 7 ++--- .../TrackerMap/android/map/MapFragment.kt | 17 +++++++----- .../TrackerMap/android/map/UnitMapFragment.kt | 8 +++++- .../TrackerMap/android/units/UnitsActivity.kt | 30 ++++++++++++++++++++++ .../TrackerMap/android/units/UnitsViewModel.kt | 9 +++++++ androidApp/src/main/res/drawable/icon_layers.xml | 10 ++++++++ androidApp/src/main/res/layout/units_activity.xml | 17 +++++++++++- androidApp/src/main/res/menu/map_layers.xml | 17 ++++++++++++ androidApp/src/main/res/values-es-rMX/strings.xml | 5 ++++ androidApp/src/main/res/values/strings.xml | 18 ++++++++++--- 10 files changed, 123 insertions(+), 15 deletions(-) create mode 100644 androidApp/src/main/res/drawable/icon_layers.xml create mode 100644 androidApp/src/main/res/menu/map_layers.xml diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt index 27d8756..504cac8 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.util.Log import androidx.appcompat.app.AppCompatActivity import com.google.android.material.tabs.TabLayoutMediator +import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.DetailsActivityBinding import mx.trackermap.TrackerMap.android.devices.Action @@ -44,9 +45,9 @@ class DetailsActivity : AppCompatActivity() { binding.detailsPager.adapter = adapter TabLayoutMediator(binding.detailsTabs, binding.detailsPager) { tab, position -> tab.text = when (position) { - 0 -> "Details" - 1 -> "Reports" - else -> "Commands" + 0 -> getString(R.string.unit_details) + 1 -> getString(R.string.unit_reports) + else -> getString(R.string.unit_commands) } }.attach() binding.detailsPager.setCurrentItem( 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 5714aae..9b4d24a 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 @@ -23,6 +23,8 @@ typealias MarkerCallback = (Int?) -> Unit class MapFragment : GlobeMapFragment() { + private var loader: QuadImageLoader? = null + data class Marker( val id: Int, val latitude: Double, @@ -54,7 +56,7 @@ class MapFragment : GlobeMapFragment() { cacheDir.mkdir() val tileInfo = RemoteTileInfoNew( - getString(R.string.maps_tile_url), + getString(R.string.maps_streets_tile_url), 0, 21 ) @@ -69,8 +71,8 @@ class MapFragment : GlobeMapFragment() { params.singleLevel = true params.maxTiles = 25 - val loader = QuadImageLoader(params, tileInfo, baseControl) - loader.setImageFormat(RenderController.ImageFormat.MaplyImageUShort565) + loader = QuadImageLoader(params, tileInfo, baseControl) + loader?.setImageFormat(RenderController.ImageFormat.MaplyImageUShort565) val clusterGenerator = BasicClusterGenerator( intArrayOf( @@ -232,7 +234,6 @@ class MapFragment : GlobeMapFragment() { geofences.forEach { geofence -> geofence.area?.let { area -> - Log.d("MainFragment", "Geofence ${geofence.name} = ${geofence.area}") try { val geometry = GeometryReader.readGeometry(area) if (!geometry.isEmpty) { @@ -254,9 +255,7 @@ class MapFragment : GlobeMapFragment() { } } } - } catch (e: SFException) { - e.printStackTrace() - } + } catch (e: SFException) {} } } @@ -289,6 +288,10 @@ class MapFragment : GlobeMapFragment() { } } + fun setTileInfo(tileInfo: TileInfoNew) { + loader?.changeTileInfo(tileInfo) + } + private fun getIcon(markerType: MarkerType): Bitmap { return ResourcesCompat.getDrawable( activity!!.resources, 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 30e3cea..06e5713 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 @@ -93,15 +93,21 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment } } + unitsViewModel.mapTileInfo.observe(viewLifecycleOwner) { tileInfo -> + Log.d("UnitMapFragment", "Loading layer!") + unitsMapFragment.setTileInfo(tileInfo) + } + unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> unitsMapFragment.displayGeofences(geofences.values.toTypedArray()) } } private fun removeObservers() { - Log.d("MapFragment", "removeObservers()") + Log.d("UnitMapFragment", "removeObservers()") unitsViewModel.units.removeObservers(viewLifecycleOwner) unitsViewModel.selectedUnit.removeObservers(viewLifecycleOwner) + unitsViewModel.mapTileInfo.removeObservers(viewLifecycleOwner) unitsViewModel.geofences.removeObservers(viewLifecycleOwner) } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt index 5213577..5a9f9ad 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt @@ -3,7 +3,9 @@ package mx.trackermap.TrackerMap.android.units import android.content.Intent import android.os.Bundle import android.util.Log +import android.view.View import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.PopupMenu import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.commit import kotlinx.coroutines.DelicateCoroutinesApi @@ -62,12 +64,32 @@ class UnitsActivity : AppCompatActivity() { binding.displayModeToggle.setOnClickListener { unitsViewModel.toggleDisplayMode() } + binding.mapLayerToggle.setOnClickListener { + showLayersPopUp(it) + } binding.searchInput.doAfterTextChanged { Log.d("UnitsActivity", "Search changed to ${it.toString()}") unitsViewModel.search(it.toString()) } } + private fun showLayersPopUp(view: View) { + val popOver = PopupMenu(this, view) + popOver.menuInflater.inflate(R.menu.map_layers, popOver.menu) + popOver.setOnMenuItemClickListener { item -> + unitsViewModel.setMapLayer( + when (item.itemId) { + R.id.layerStreets -> getString(R.string.maps_streets_tile_url) + R.id.layerSatellite -> getString(R.string.maps_satellite_url) + R.id.layerHybrid -> getString(R.string.maps_hybrid_url) + else -> getString(R.string.maps_streets_tile_url) + } + ) + true + } + popOver.show() + } + private fun setupObservers() { unitsViewModel.unitsDisplayMode.observe(this) { displayMode -> binding.displayModeToggle.setImageResource( @@ -85,10 +107,18 @@ class UnitsActivity : AppCompatActivity() { } ) + binding.mapLayerToggle.visibility = + when (displayMode) { + UnitsViewModel.UnitsDisplayMode.LIST -> View.GONE + UnitsViewModel.UnitsDisplayMode.MAP -> View.VISIBLE + else -> View.GONE + } + val newFragment = when (displayMode) { UnitsViewModel.UnitsDisplayMode.LIST -> devicesFragment UnitsViewModel.UnitsDisplayMode.MAP -> mapFragment + else -> devicesFragment } supportFragmentManager.commit { replace(R.id.displayContainer, newFragment) diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt index c0dc7c6..6a04cf4 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt @@ -2,6 +2,8 @@ package mx.trackermap.TrackerMap.android.units import android.util.Log import androidx.lifecycle.* +import com.mousebird.maply.RemoteTileInfoNew +import com.mousebird.maply.TileInfoNew import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch @@ -28,12 +30,14 @@ class UnitsViewModel( private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.LIST) private var _units = MutableLiveData>() private var _selectedUnit = MutableLiveData() + private var _mapTileInfo = MutableLiveData() private var _geofences = MutableLiveData>() val searchQuery: LiveData get() = _searchQuery val unitsDisplayMode: LiveData get() = _unitsDisplayMode val units: LiveData> get() = _units val selectedUnit: LiveData get() = _selectedUnit + val mapTileInfo: LiveData get() = _mapTileInfo val geofences: LiveData> get() = _geofences init { @@ -82,6 +86,11 @@ class UnitsViewModel( _unitsDisplayMode.postValue(displayMode) } + fun setMapLayer(url: String, minZoom: Int = 0, maxZoom: Int = 21) { + val tileInfo = RemoteTileInfoNew(url, minZoom, maxZoom) + _mapTileInfo.postValue(tileInfo) + } + fun toggleDisplayMode() { Log.d("UnitsViewModel", "Toggling Display mode") val newDisplayMode = diff --git a/androidApp/src/main/res/drawable/icon_layers.xml b/androidApp/src/main/res/drawable/icon_layers.xml new file mode 100644 index 0000000..478fe9d --- /dev/null +++ b/androidApp/src/main/res/drawable/icon_layers.xml @@ -0,0 +1,10 @@ + + + diff --git a/androidApp/src/main/res/layout/units_activity.xml b/androidApp/src/main/res/layout/units_activity.xml index 07b5dad..475598f 100644 --- a/androidApp/src/main/res/layout/units_activity.xml +++ b/androidApp/src/main/res/layout/units_activity.xml @@ -40,7 +40,7 @@ app:cardCornerRadius="@dimen/card_border_radius" app:cardElevation="@dimen/card_elevation" app:layout_constraintBottom_toBottomOf="@id/displayModeToggle" - app:layout_constraintEnd_toStartOf="@id/displayModeToggle" + app:layout_constraintEnd_toStartOf="@id/mapLayerToggle" app:layout_constraintStart_toEndOf="@id/userButton" app:layout_constraintTop_toTopOf="@id/displayModeToggle"> @@ -57,6 +57,21 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml index 823ddde..be656ad 100644 --- a/androidApp/src/main/res/values-es-rMX/strings.xml +++ b/androidApp/src/main/res/values-es-rMX/strings.xml @@ -10,8 +10,13 @@ Cambiar a lista de dispositivos Cambiar a mapa + Cambiar capa del mapa Ver información de cuenta + Streets + Satellite + Hybrid + Cuenta Acerca de Cerrar sesión diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 4a7d03b..c59bb9f 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -3,13 +3,20 @@ TrackerMap - - https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga - https://www.google.com/maps/place/%1$f,%2$f?z=19 + + https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga + + + https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga + + + https://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Ga + + Username Password @@ -18,8 +25,13 @@ Switch to device list Switch to map + Switch map layer View account info + Streets + Satellite + Hybrid + Account About Logout -- cgit v1.2.3