refactor(shared): move SettingsStore to KMP using KvPrefs and remove Android impl
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
package app.klottr.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
object SettingsStore {
|
||||
private const val PREFS = "klottr_settings"
|
||||
|
||||
// Keys (befintliga)
|
||||
const val KEY_ONLY_NEW_HITS = "only_new_hits"
|
||||
const val KEY_SATELLITE_MAP = "satellite_map"
|
||||
const val KEY_NIGHT_MODE = "night_mode"
|
||||
|
||||
const val KEY_SHOW_COORDS = "show_coordinates"
|
||||
|
||||
const val KEY_SHOW_KLOTTER = "show_klotter"
|
||||
|
||||
const val KEY_SHOW_WIKIPEDIA = "show_wikipedia"
|
||||
const val KEY_WIKI_RADIUS = "wiki_radius_m"
|
||||
|
||||
const val KEY_SHOW_DM = "show_digitaltmuseum"
|
||||
const val KEY_DM_RADIUS = "digitaltmuseum_radius_m"
|
||||
|
||||
// Nya: Fornsök
|
||||
const val KEY_SHOW_FORNSOK = "show_fornsok"
|
||||
const val KEY_FORNSOK_RADIUS = "fornsok_radius_m"
|
||||
|
||||
private fun prefs(ctx: Context): SharedPreferences =
|
||||
ctx.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
|
||||
// --- Observers ---
|
||||
|
||||
fun observe(ctx: Context, onChanged: (key: String?) -> Unit): SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
val p = prefs(ctx)
|
||||
val l = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||
onChanged(key)
|
||||
}
|
||||
p.registerOnSharedPreferenceChangeListener(l)
|
||||
return l
|
||||
}
|
||||
|
||||
fun unobserve(ctx: Context, listener: SharedPreferences.OnSharedPreferenceChangeListener?) {
|
||||
if (listener == null) return
|
||||
try { prefs(ctx).unregisterOnSharedPreferenceChangeListener(listener) } catch (_: Exception) {}
|
||||
}
|
||||
|
||||
// --- Only new hits ---
|
||||
|
||||
fun getOnlyNewHits(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_ONLY_NEW_HITS, false)
|
||||
fun setOnlyNewHits(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_ONLY_NEW_HITS, v).apply() }
|
||||
|
||||
// --- Satellite map ---
|
||||
|
||||
fun getSatelliteMap(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_SATELLITE_MAP, false)
|
||||
fun setSatelliteMap(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_SATELLITE_MAP, v).apply() }
|
||||
|
||||
// --- Night mode ---
|
||||
|
||||
fun getNightMode(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_NIGHT_MODE, false)
|
||||
fun setNightMode(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_NIGHT_MODE, v).apply() }
|
||||
|
||||
// -- Show coordinates ---
|
||||
|
||||
fun getShowCoordinates(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_SHOW_COORDS, false)
|
||||
fun setShowCoordinates(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_SHOW_COORDS, v).apply() }
|
||||
|
||||
// --- Klotter ---
|
||||
|
||||
fun getShowKlotter(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_SHOW_KLOTTER, true)
|
||||
fun setShowKlotter(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_SHOW_KLOTTER, v).apply() }
|
||||
|
||||
// --- Wikipedia ---
|
||||
|
||||
fun getShowWikipedia(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_SHOW_WIKIPEDIA, true)
|
||||
fun setShowWikipedia(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_SHOW_WIKIPEDIA, v).apply() }
|
||||
|
||||
fun getWikiRadiusMeters(ctx: Context): Int = prefs(ctx).getInt(KEY_WIKI_RADIUS, 200)
|
||||
fun setWikiRadiusMeters(ctx: Context, meters: Int) { prefs(ctx).edit().putInt(KEY_WIKI_RADIUS, meters).apply() }
|
||||
|
||||
// --- DigitaltMuseum ---
|
||||
|
||||
fun getShowDigitaltMuseum(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_SHOW_DM, false)
|
||||
fun setShowDigitaltMuseum(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_SHOW_DM, v).apply() }
|
||||
|
||||
fun getDigitaltMuseumRadiusMeters(ctx: Context): Int = prefs(ctx).getInt(KEY_DM_RADIUS, 500)
|
||||
fun setDigitaltMuseumRadiusMeters(ctx: Context, meters: Int) {
|
||||
prefs(ctx).edit().putInt(KEY_DM_RADIUS, meters).apply()
|
||||
}
|
||||
|
||||
// --- Fornsök (NYTT) ---
|
||||
|
||||
fun getShowFornsok(ctx: Context): Boolean = prefs(ctx).getBoolean(KEY_SHOW_FORNSOK, false)
|
||||
fun setShowFornsok(ctx: Context, v: Boolean) { prefs(ctx).edit().putBoolean(KEY_SHOW_FORNSOK, v).apply() }
|
||||
|
||||
fun getFornsokRadiusMeters(ctx: Context): Int = prefs(ctx).getInt(KEY_FORNSOK_RADIUS, 200)
|
||||
fun setFornsokRadiusMeters(ctx: Context, meters: Int) {
|
||||
prefs(ctx).edit().putInt(KEY_FORNSOK_RADIUS, meters).apply()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user