diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-16 00:00:20 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-16 00:00:20 -0600 |
commit | 4eef1b0dd5f328ee5ed3d30d3f270af4e15d81a8 (patch) | |
tree | 22bf05bb94f0809811fe1fcec57aba53f91f315b /androidApp/src/main | |
parent | 96050de8752321bc194c0611b2098ab8612b4b55 (diff) | |
download | etbsa-trackermap-mobile-4eef1b0dd5f328ee5ed3d30d3f270af4e15d81a8.tar.gz etbsa-trackermap-mobile-4eef1b0dd5f328ee5ed3d30d3f270af4e15d81a8.tar.bz2 etbsa-trackermap-mobile-4eef1b0dd5f328ee5ed3d30d3f270af4e15d81a8.zip |
Default map changed to OpenStreetMap.fr (because .org one doesn't work), and now each map URL has its own cache dir
Diffstat (limited to 'androidApp/src/main')
4 files changed, 32 insertions, 19 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 60c8a47..e4fb8ea 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 @@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.drawable.toBitmap import com.mousebird.maply.* +import com.soywiz.krypto.md5 import mil.nga.sf.Polygon import mil.nga.sf.util.SFException import mil.nga.sf.wkt.GeometryReader @@ -56,17 +57,10 @@ class MapFragment : GlobeMapFragment() { override fun controlHasStarted() { Log.d("MapFragment", "controlHasStarted") - val cacheDirName = "stamen_watercolor6" - val cacheDir = File(activity!!.cacheDir, cacheDirName) - cacheDir.mkdir() - if (tileInfo == null) { - tileInfo = RemoteTileInfoNew( - getString(R.string.maps_streets_tile_url), - 0, - 21 - ) - (tileInfo as RemoteTileInfoNew).cacheDir = cacheDir + val mapUrl = getString(R.string.maps_streets_tile_url) + val tmpInfo = RemoteTileInfoNew(mapUrl, 0, 21) + tileInfo = makeTileInfo(getString(R.string.maps_streets_tile_url), tmpInfo) } val params = SamplingParams() @@ -318,9 +312,25 @@ class MapFragment : GlobeMapFragment() { } } - fun updateTileInfo(tileInfo: TileInfoNew) { - this.tileInfo = tileInfo - loader?.changeTileInfo(tileInfo) + private fun makeTileInfo(url: String, tileInfo: TileInfoNew): TileInfoNew? { + return context?.let { + val cacheDirName = url.toByteArray(Charsets.UTF_8).md5().hex + val cacheDirMap = File(it.cacheDir, cacheDirName) + cacheDirMap.mkdir() + Log.d("MapFragment", "Cache dir for $url = ${cacheDirMap.absolutePath}") + + (tileInfo as? RemoteTileInfoNew)?.cacheDir = cacheDirMap + tileInfo + } + } + + fun updateTileInfo(url: String, tileInfo: TileInfoNew) { + context?.let { + this.tileInfo = makeTileInfo(url, tileInfo) + this.tileInfo?.let { + loader?.changeTileInfo(it) + } + } } private fun getIcon(markerType: MarkerType): Bitmap { 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 09f41a8..c17e6a4 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 @@ -96,7 +96,7 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment unitsViewModel.mapTileInfo.observe(viewLifecycleOwner) { tileInfo -> Log.d("UnitMapFragment", "Loading layer!") - unitsMapFragment.updateTileInfo(tileInfo) + unitsMapFragment.updateTileInfo(tileInfo.first, tileInfo.second) } unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> 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 08d35a2..94e22fa 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 @@ -4,6 +4,10 @@ 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 @@ -30,14 +34,14 @@ class UnitsViewModel( private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP) private var _units = MutableLiveData<List<UnitInformation>>() private var _selectedUnit = MutableLiveData<UnitInformation?>() - private var _mapTileInfo = MutableLiveData<TileInfoNew>() + private var _mapTileInfo = MutableLiveData<Pair<String, 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 mapTileInfo: LiveData<Pair<String, TileInfoNew>> get() = _mapTileInfo val geofences: LiveData<Map<Int, Geofence>> get() = _geofences init { @@ -88,7 +92,7 @@ class UnitsViewModel( fun setMapLayer(url: String, minZoom: Int = 0, maxZoom: Int = 21) { val tileInfo = RemoteTileInfoNew(url, minZoom, maxZoom) - _mapTileInfo.postValue(tileInfo) + _mapTileInfo.postValue(url to tileInfo) } fun toggleDisplayMode() { diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 20f5b21..025a7b9 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -11,7 +11,7 @@ </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 + https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png </string> <string name="maps_satellite_url" translatable="false"> https://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Ga @@ -41,7 +41,6 @@ <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> |