Move osm settings to its own settings page

This commit is contained in:
MM20
2024-06-30 14:38:33 +02:00
parent 429025e5ac
commit e96a382b00
10 changed files with 145 additions and 62 deletions
@@ -141,8 +141,8 @@ data class LauncherSettingsData internal constructor(
val locationSearchImperialUnits: Boolean = false,
val locationSearchRadius: Int = 1500,
val locationSearchHideUncategorized: Boolean = true,
val locationSearchOverpassUrl: String = LocationSearchSettings.DefaultOverpassUrl,
val locationSearchTileServer: String = LocationSearchSettings.DefaultTileServerUrl,
val locationSearchOverpassUrl: String? = null,
val locationSearchTileServer: String? = null,
val locationSearchShowMap: Boolean = true,
val locationSearchShowPositionOnMap: Boolean = false,
val locationSearchThemeMap: Boolean = true,
@@ -72,18 +72,39 @@ class LocationSearchSettings internal constructor(
val overpassUrl
get() = launcherDataStore.data.map { it.locationSearchOverpassUrl }
fun setOverpassUrl(overpassUrl: String) {
fun setOverpassUrl(overpassUrl: String?) {
var url = overpassUrl
if (url != null) {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://$url"
}
if (url.endsWith('/')) {
url = url.substringBeforeLast('/')
}
if (url.endsWith("/api/interpreter")) {
url = url.substringBeforeLast("/api/interpreter")
}
}
launcherDataStore.update {
it.copy(locationSearchOverpassUrl = overpassUrl)
it.copy(locationSearchOverpassUrl = url)
}
}
val tileServer
get() = launcherDataStore.data.map { it.locationSearchTileServer }
fun setTileServer(tileServer: String) {
fun setTileServer(tileServer: String?) {
var url = tileServer
if (url != null) {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://$url"
}
if (!url.contains("\${z}") || !url.contains("\${x}") || !url.contains("\${y}")) {
url = "$url/\${z}/\${x}/\${y}.png"
}
}
launcherDataStore.update {
it.copy(locationSearchTileServer = tileServer)
it.copy(locationSearchTileServer = url)
}
}
@@ -125,8 +146,8 @@ data class LocationSearchSettingsData(
val providers: Set<String> = setOf("openstreetmaps"),
val searchRadius: Int = 1500,
val hideUncategorized: Boolean = true,
val overpassUrl: String = LocationSearchSettings.DefaultOverpassUrl,
val tileServer: String = LocationSearchSettings.DefaultTileServerUrl,
val overpassUrl: String? = null,
val tileServer: String? = null,
val imperialUnits: Boolean = false,
val showMap: Boolean = false,
val showPositionOnMap: Boolean = false,