This commit is contained in:
Lorenz Hohermuth 2025-03-25 13:19:36 +01:00
parent 3af4543949
commit f10e030647
1 changed files with 4 additions and 2 deletions

View File

@ -53,6 +53,8 @@ var plzArrayStatus: List<String> = listOf(
"Loading...",
)
val defaultPlzList = listOf("8005", "8005", "8005", "8400", "8400", "8500", "8500")
// ### Start ChatGPT + Fixing
val SHARED_PLZ_KEY = stringPreferencesKey("shared-plz")
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
@ -65,14 +67,14 @@ suspend fun setLocations(context: Context, array: List<String>) {
suspend fun getLocations(context: Context): List<String> {
val preferences = context.dataStore.data.first()
return preferences[SHARED_PLZ_KEY]?.let { Json.decodeFromString(it) } ?: emptyList()
return preferences[SHARED_PLZ_KEY]?.let { Json.decodeFromString(it) } ?: defaultPlzList
}
// ### End ChatGPT
suspend fun getPLZ(index: Int, ctx: Context): String {
var arr = getLocations(ctx)
if (arr.isEmpty() || arr.size != 7) {
arr = listOf("8005", "8005", "8005", "8400", "8400", "8500", "8500")
arr = defaultPlzList
}
plzArrayStatus = arr
return arr[index]