diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-12 22:39:04 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-12 22:39:04 -0600 |
commit | a13e418f74397653e028e38084f0f8f09492419e (patch) | |
tree | 7d9e848c5bd836182a9fb8592271b553ee1b3895 /androidApp/src/main | |
parent | da52a594e73b4fa118dbe7349565a8902755d506 (diff) | |
download | etbsa-trackermap-mobile-a13e418f74397653e028e38084f0f8f09492419e.tar.gz etbsa-trackermap-mobile-a13e418f74397653e028e38084f0f8f09492419e.tar.bz2 etbsa-trackermap-mobile-a13e418f74397653e028e38084f0f8f09492419e.zip |
Implemented map layer switching and updated strings.xml
Diffstat (limited to 'androidApp/src/main')
10 files changed, 123 insertions, 15 deletions
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<List<UnitInformation>>() private var _selectedUnit = MutableLiveData<UnitInformation?>() + private var _mapTileInfo = MutableLiveData<TileInfoNew>() private var _geofences = MutableLiveData<Map<Int, Geofence>>() val searchQuery: LiveData<String> get() = _searchQuery val unitsDisplayMode: LiveData<UnitsDisplayMode> get() = _unitsDisplayMode val units: LiveData<List<UnitInformation>> get() = _units val selectedUnit: LiveData<UnitInformation?> get() = _selectedUnit + val mapTileInfo: LiveData<TileInfoNew> get() = _mapTileInfo val geofences: LiveData<Map<Int, Geofence>> 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 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M11.99,18.54l-7.37,-5.73L3,14.07l9,7 9,-7 -1.63,-1.27 -7.38,5.74zM12,16l7.36,-5.73L21,9l-9,-7 -9,7 1.63,1.27L12,16z"/> +</vector> 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"> @@ -58,6 +58,21 @@ </com.google.android.material.card.MaterialCardView> <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/mapLayerToggle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/fab_margin" + android:layout_marginEnd="@dimen/fab_margin" + android:backgroundTint="@android:color/white" + android:contentDescription="@string/switch_layer" + android:src="@drawable/icon_layers" + app:borderWidth="0dp" + app:elevation="@dimen/fab_elevation" + app:fabSize="mini" + app:layout_constraintEnd_toStartOf="@id/displayModeToggle" + app:layout_constraintTop_toTopOf="parent" /> + + <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/displayModeToggle" android:layout_width="wrap_content" android:layout_height="wrap_content" diff --git a/androidApp/src/main/res/menu/map_layers.xml b/androidApp/src/main/res/menu/map_layers.xml new file mode 100644 index 0000000..6830ff7 --- /dev/null +++ b/androidApp/src/main/res/menu/map_layers.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu + xmlns:android="http://schemas.android.com/apk/res/android"> + + <item + android:id="@+id/layerStreets" + android:title="@string/layer_streets"/> + + <item + android:id="@+id/layerSatellite" + android:title="@string/layer_satellite"/> + + <item + android:id="@+id/layerHybrid" + android:title="@string/layer_hybrid"/> + +</menu>
\ 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 @@ <!-- UnitsActivity --> <string name="toggle_list">Cambiar a lista de dispositivos</string> <string name="toggle_map">Cambiar a mapa</string> + <string name="switch_layer">Cambiar capa del mapa</string> <string name="open_profile">Ver información de cuenta</string> + <string name="layer_streets">Streets</string> + <string name="layer_satellite">Satellite</string> + <string name="layer_hybrid">Hybrid</string> + <string name="menu_account">Cuenta</string> <string name="menu_about">Acerca de</string> <string name="menu_logout">Cerrar sesión</string> 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 @@ <string name="app_name">TrackerMap</string> <!-- Non translatables --> - <string name="maps_tile_url" translatable="false"> - https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga - </string> <string name="maps_url_template" translatable="false"> https://www.google.com/maps/place/%1$f,%2$f?z=19 </string> + <string name="maps_streets_tile_url" translatable="false"> + https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga + </string> + <string name="maps_satellite_url" translatable="false"> + https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga + </string> + <string name="maps_hybrid_url" translatable="false"> + https://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Ga + </string> + <!-- LoginActivity --> <string name="login_username">Username</string> <string name="login_password">Password</string> @@ -18,8 +25,13 @@ <!-- UnitsActivity --> <string name="toggle_list">Switch to device list</string> <string name="toggle_map">Switch to map</string> + <string name="switch_layer">Switch map layer</string> <string name="open_profile">View account info</string> + <string name="layer_streets">Streets</string> + <string name="layer_satellite">Satellite</string> + <string name="layer_hybrid">Hybrid</string> + <string name="menu_account">Account</string> <string name="menu_about">About</string> <string name="menu_logout">Logout</string> |