Created
November 13, 2022 19:59
-
-
Save sergei-mikhailovskii-idf/48640ebfc1355ff11dc26bcf39c25c25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actual class PreferencesRepository actual constructor(actual val di: DI) { | |
private val context: Context by di.instance() | |
val preferences by lazy { | |
context.getSharedPreferences("fitnestapp", Context.MODE_PRIVATE) | |
} | |
actual fun <T> saveValue(key: String, value: T?) { | |
println("Saved with Android: key=$key, value=$value") | |
val editor = preferences.edit() | |
when (value) { | |
is String -> editor.putString(key, value) | |
} | |
editor.apply() | |
} | |
actual inline fun <reified T> getValue(key: String, defaultValue: T?): T? { | |
return when (T::class) { | |
String::class -> { | |
preferences.getString(key, defaultValue as String?) as T? | |
} | |
else -> null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment