Working on cache downloader

This commit is contained in:
PWRxPSYCHO 2022-09-22 08:35:33 -04:00
parent 4d81689f21
commit 9b1dfb0d02
5 changed files with 424 additions and 16 deletions

View file

@ -37,6 +37,9 @@ import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.osmdroid.bonuspack.kml.KmlDocument
import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.FolderOverlay
import java.io.BufferedWriter
import java.io.FileNotFoundException
import java.io.FileWriter
@ -480,6 +483,31 @@ class UIViewModel @Inject constructor(
}
}
fun parseUrl(url: String, map: MapView) {
viewModelScope.launch(Dispatchers.IO) {
parseIt(url, map)
}
}
// For Future Use
// model.parseUrl(
// "https://www.google.com/maps/d/kml?forcekml=1&mid=1FmqWhZG3PG3dY92x9yf2RlREcK7kMZs&lid=-ivSjBCePsM",
// map
// )
private fun parseIt(url: String, map: MapView) {
val kmlDoc = KmlDocument()
try {
kmlDoc.parseKMLUrl(url)
val kmlOverlay = kmlDoc.mKmlRoot.buildOverlay(map, null, null, kmlDoc) as FolderOverlay
kmlDoc.mKmlRoot.mItems
kmlDoc.mKmlRoot.mName
map.overlayManager.overlays().add(kmlOverlay)
} catch (ex: Exception) {
debug("Failed to download .kml $ex")
}
}
fun addQuickChatAction(name: String, value: String, mode: QuickChatAction.Mode) {
viewModelScope.launch(Dispatchers.Main) {
val action = QuickChatAction(0, name, value, mode, _quickChatActions.value.size)