aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt36
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt2
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt10
3 files changed, 31 insertions, 17 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() {