diff options
Diffstat (limited to 'androidApp/src/main')
11 files changed, 70 insertions, 38 deletions
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 e30885d..c4e5fc8 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 @@ -18,6 +18,7 @@ import mil.nga.sf.wkt.GeometryReader import java.io.File import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.client.models.Geofence +import mx.trackermap.TrackerMap.client.models.MapLayer import mx.trackermap.TrackerMap.utils.MapCalculus import mx.trackermap.TrackerMap.utils.MarkerType @@ -59,7 +60,8 @@ class MapFragment : GlobeMapFragment() { Log.d("MapFragment", "controlHasStarted") if (tileInfo == null) { - val layer = resources.getStringArray(R.array.maps_streets_tile_url) + // Load default map layer + val layer = resources.getStringArray(R.array.maps_streets_tile) val tmpInfo = RemoteTileInfoNew(layer[0], layer[1].toInt(), layer[2].toInt()) tileInfo = tileInfoSetCacheDir(layer[0], tmpInfo) tileInfo?.let { @@ -344,6 +346,15 @@ class MapFragment : GlobeMapFragment() { } } + fun updateTileInfo(layer: MapLayer) { + val tileInfo = RemoteTileInfoNew(layer.url, layer.minZoom, layer.maxZoom) + this.tileInfo = tileInfoSetCacheDir(layer.url, tileInfo) + this.tileInfo?.let { + loader?.changeTileInfo(it) + setZoomLimits(tileInfo.minZoom, tileInfo.maxZoom) + } + } + private fun setZoomLimits(minZoom: Int, maxZoom: Int) { mapControl?.let { it.setZoomLimits( @@ -359,16 +370,6 @@ class MapFragment : GlobeMapFragment() { } } - fun updateTileInfo(url: String, tileInfo: TileInfoNew) { - context?.let { - this.tileInfo = tileInfoSetCacheDir(url, tileInfo) - this.tileInfo?.let { - loader?.changeTileInfo(it) - setZoomLimits(tileInfo.minZoom, tileInfo.maxZoom) - } - } - } - 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 c17e6a4..66ccc7a 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 @@ -6,6 +6,7 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.text.HtmlCompat import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitMapFragmentBinding @@ -14,6 +15,7 @@ import mx.trackermap.TrackerMap.android.devices.Action import mx.trackermap.TrackerMap.android.devices.UnitRenderData import mx.trackermap.TrackerMap.android.units.UnitFragment import mx.trackermap.TrackerMap.android.units.UnitsViewModel +import mx.trackermap.TrackerMap.client.models.MapLayer import mx.trackermap.TrackerMap.client.models.UnitInformation @DelicateCoroutinesApi @@ -53,6 +55,11 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment private fun initializeMap() { unitsMapFragment = childFragmentManager.findFragmentById(R.id.unitsMap) as MapFragment unitsMapFragment.markerCallback = unitsViewModel::selectUnitWith + + val layer = resources.getStringArray(R.array.maps_streets_tile) + unitsViewModel.setMapLayer(MapLayer( + layer[0], layer[1].toInt(), layer[2].toInt(), layer[3] + )) } private fun setupObservers() { @@ -94,9 +101,10 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment } } - unitsViewModel.mapTileInfo.observe(viewLifecycleOwner) { tileInfo -> + unitsViewModel.mapLayer.observe(viewLifecycleOwner) { layer -> Log.d("UnitMapFragment", "Loading layer!") - unitsMapFragment.updateTileInfo(tileInfo.first, tileInfo.second) + unitsMapFragment.updateTileInfo(layer) + binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0) } unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> @@ -108,7 +116,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment Log.d("UnitMapFragment", "removeObservers()") unitsViewModel.units.removeObservers(viewLifecycleOwner) unitsViewModel.selectedUnit.removeObservers(viewLifecycleOwner) - unitsViewModel.mapTileInfo.removeObservers(viewLifecycleOwner) + unitsViewModel.mapLayer.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 cbd543a..1bbcb80 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 @@ -17,6 +17,7 @@ import mx.trackermap.TrackerMap.android.databinding.UnitsActivityBinding import mx.trackermap.TrackerMap.android.devices.DevicesFragment import mx.trackermap.TrackerMap.android.map.UnitMapFragment import mx.trackermap.TrackerMap.android.session.UserInformationActivity +import mx.trackermap.TrackerMap.client.models.MapLayer import org.koin.androidx.viewmodel.ext.android.viewModel @DelicateCoroutinesApi @@ -92,12 +93,14 @@ class UnitsActivity : AppCompatActivity() { popOver.setOnMenuItemClickListener { item -> val layer = resources.getStringArray( when (item.itemId) { - R.id.layerStreets -> R.array.maps_streets_tile_url - R.id.layerSatellite -> R.array.maps_satellite_tile_url - else -> R.array.maps_streets_tile_url + R.id.layerStreets -> R.array.maps_streets_tile + R.id.layerSatellite -> R.array.maps_satellite_tile + else -> R.array.maps_streets_tile } ) - unitsViewModel.setMapLayer(layer[0], layer[1].toInt(), layer[2].toInt()) + unitsViewModel.setMapLayer(MapLayer( + layer[0], layer[1].toInt(), layer[2].toInt(), layer[3] + )) true } popOver.show() 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 94e22fa..d3060f0 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,16 +2,11 @@ package mx.trackermap.TrackerMap.android.units import android.util.Log import androidx.lifecycle.* -import com.mousebird.maply.RemoteTileInfoNew -import com.mousebird.maply.TileInfoNew -import com.soywiz.krypto.Hash -import com.soywiz.krypto.Hasher -import com.soywiz.krypto.HasherFactory -import com.soywiz.krypto.md5 import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.models.Geofence +import mx.trackermap.TrackerMap.client.models.MapLayer import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.controllers.GeofencesController import mx.trackermap.TrackerMap.controllers.UnitsController @@ -34,14 +29,14 @@ class UnitsViewModel( private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP) private var _units = MutableLiveData<List<UnitInformation>>() private var _selectedUnit = MutableLiveData<UnitInformation?>() - private var _mapTileInfo = MutableLiveData<Pair<String, TileInfoNew>>() + private var _mapLayer = MutableLiveData<MapLayer>() 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<Pair<String, TileInfoNew>> get() = _mapTileInfo + val mapLayer: LiveData<MapLayer> get() = _mapLayer val geofences: LiveData<Map<Int, Geofence>> get() = _geofences init { @@ -90,9 +85,8 @@ class UnitsViewModel( _unitsDisplayMode.postValue(displayMode) } - fun setMapLayer(url: String, minZoom: Int = 0, maxZoom: Int = 21) { - val tileInfo = RemoteTileInfoNew(url, minZoom, maxZoom) - _mapTileInfo.postValue(url to tileInfo) + fun setMapLayer(layer: MapLayer) { + _mapLayer.postValue(layer) } fun toggleDisplayMode() { diff --git a/androidApp/src/main/res/layout/unit_map_fragment.xml b/androidApp/src/main/res/layout/unit_map_fragment.xml index 486f1ce..8395013 100644 --- a/androidApp/src/main/res/layout/unit_map_fragment.xml +++ b/androidApp/src/main/res/layout/unit_map_fragment.xml @@ -14,7 +14,8 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" - android:name="mx.trackermap.TrackerMap.android.map.MapFragment"/> + android:name="mx.trackermap.TrackerMap.android.map.MapFragment" + tools:visibility="invisible"/> <androidx.cardview.widget.CardView android:id="@+id/mapUnitCard" @@ -121,4 +122,24 @@ </androidx.cardview.widget.CardView> + <!-- Attribution --> + <FrameLayout + android:layout_width="0dp" + android:layout_height="wrap_content" + android:background="@color/colorAttributionBackground" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintBottom_toBottomOf="parent"> + + <TextView + android:id="@+id/attributionText" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:text="Copyright (C) OpenStreetMap" + android:textSize="@dimen/attribution_text_size" + android:textColor="@color/colorAttributionText" + android:layout_margin="6dp" /> + + </FrameLayout> + </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/androidApp/src/main/res/values-es-rMX/map_layers.xml b/androidApp/src/main/res/values-es-rMX/map_layers.xml new file mode 100644 index 0000000..eff37d9 --- /dev/null +++ b/androidApp/src/main/res/values-es-rMX/map_layers.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="layer_streets">Calles</string> + <string name="layer_satellite">Satélite</string> +</resources>
\ 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 809b64c..5e41768 100644 --- a/androidApp/src/main/res/values-es-rMX/strings.xml +++ b/androidApp/src/main/res/values-es-rMX/strings.xml @@ -19,9 +19,6 @@ <string name="switch_layer">Cambiar capa del mapa</string> <string name="open_profile">Ver información de cuenta</string> - <string name="layer_streets">Calles</string> - <string name="layer_satellite">Satélite</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/colors.xml b/androidApp/src/main/res/values/colors.xml index bb4ab14..23fe6fb 100644 --- a/androidApp/src/main/res/values/colors.xml +++ b/androidApp/src/main/res/values/colors.xml @@ -12,6 +12,8 @@ <color name="colorGeofenceLabel">#1976D2</color> <color name="colorGeofenceLabelOutline">#FFFFFF</color> <color name="colorReport">#388E3C</color> + <color name="colorAttributionText">#66000000</color> + <color name="colorAttributionBackground">#4DFFFFFF</color> <color name="colorOnline">#388E3C</color> <color name="colorOffline">#D32F2F</color> diff --git a/androidApp/src/main/res/values/dimen.xml b/androidApp/src/main/res/values/dimen.xml index 271a12b..92d5242 100644 --- a/androidApp/src/main/res/values/dimen.xml +++ b/androidApp/src/main/res/values/dimen.xml @@ -33,6 +33,7 @@ <dimen name="geofence_label_text_size">11sp</dimen> <dimen name="geofence_label_width">4dp</dimen> <dimen name="report_label_width">10dp</dimen> + <dimen name="attribution_text_size">11sp</dimen> <!-- User Information --> <dimen name="fields_spacing">8dp</dimen> diff --git a/androidApp/src/main/res/values/map_layers.xml b/androidApp/src/main/res/values/map_layers.xml index c0e83a5..bffceb9 100644 --- a/androidApp/src/main/res/values/map_layers.xml +++ b/androidApp/src/main/res/values/map_layers.xml @@ -1,19 +1,22 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + <string name="layer_streets">Streets</string> + <string name="layer_satellite">Satellite</string> + <!-- Tile URLs --> <!-- [0] = tile server URL --> <!-- [1] = min zoom --> <!-- [2] = max zoom --> <!-- [3] = attribution text --> - <string-array name="maps_streets_tile_url" translatable="false"> + <string-array name="maps_streets_tile" translatable="false"> <item>https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png</item> <item>0</item> <item>21</item> <item>© OpenStreetMap France | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors</item> </string-array> - <string-array name="maps_satellite_tile_url" translatable="false"> + <string-array name="maps_satellite_tile" translatable="false"> <item>https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}</item> <item>0</item> <item>20</item> diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index a3d2f28..11c914f 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -32,9 +32,6 @@ <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="menu_account">Account</string> <string name="menu_about">About</string> <string name="menu_logout">Logout</string> |