diff options
5 files changed, 34 insertions, 20 deletions
diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 07fe740..cd63ac0 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -39,7 +39,7 @@ val googleImplementation by configurations dependencies { implementation(project(":shared")) - implementation("com.google.android.material:material:1.4.0") + implementation("com.google.android.material:material:1.5.0") implementation("androidx.appcompat:appcompat:1.4.0") implementation("androidx.constraintlayout:constraintlayout:2.1.2") implementation("com.squareup.okhttp3:okhttp:4.9.1") @@ -56,6 +56,7 @@ dependencies { implementation("com.github.zerobranch:SwipeLayout:1.3.1") implementation("com.github.addisonElliott:SegmentedButton:3.1.9") implementation("mil.nga.sf:sf-wkt:1.0.1") + implementation("com.soywiz.korlibs.krypto:krypto:2.4.12") implementation(group = "", name = "WhirlyGlobeMaply", ext = "aar") googleImplementation(platform("com.google.firebase:firebase-bom:29.0.3")) 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> |