pull/1835/head
kunfei 3 years ago
parent da269c384a
commit bb1ddba35b
  1. 46
      app/src/main/java/io/legado/app/utils/PreferencesExtensions.kt

@ -1,11 +1,57 @@
@file:Suppress("unused")
package io.legado.app.utils package io.legado.app.utils
import android.content.SharedPreferences import android.content.SharedPreferences
import androidx.core.content.edit import androidx.core.content.edit
fun SharedPreferences.getString(key: String): String? {
return getString(key, null)
}
fun SharedPreferences.putString(key: String, value: String) {
edit {
putString(key, value)
}
}
fun SharedPreferences.getBoolean(key: String): Boolean {
return getBoolean(key, false)
}
fun SharedPreferences.putBoolean(key: String, value: Boolean) {
edit {
putBoolean(key, value)
}
}
fun SharedPreferences.getInt(key: String): Int {
return getInt(key, 0)
}
fun SharedPreferences.putInt(key: String, value: Int) {
edit {
putInt(key, value)
}
}
fun SharedPreferences.getLong(key: String): Long {
return getLong(key, 0)
}
fun SharedPreferences.putLong(key: String, value: Long) { fun SharedPreferences.putLong(key: String, value: Long) {
edit { edit {
putLong(key, value) putLong(key, value)
} }
}
fun SharedPreferences.getFloat(key: String): Float {
return getFloat(key, 0f)
}
fun SharedPreferences.putFloat(key: String, value: Float) {
edit {
putFloat(key, value)
}
} }
Loading…
Cancel
Save