From bb1ddba35be5f9820eb3b78e792e74e1cb9bbd9b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 30 Apr 2022 19:17:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/utils/PreferencesExtensions.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/app/src/main/java/io/legado/app/utils/PreferencesExtensions.kt b/app/src/main/java/io/legado/app/utils/PreferencesExtensions.kt index b8370d526..58498a28a 100644 --- a/app/src/main/java/io/legado/app/utils/PreferencesExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/PreferencesExtensions.kt @@ -1,11 +1,57 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.content.SharedPreferences 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) { edit { putLong(key, value) } +} + +fun SharedPreferences.getFloat(key: String): Float { + return getFloat(key, 0f) +} + +fun SharedPreferences.putFloat(key: String, value: Float) { + edit { + putFloat(key, value) + } } \ No newline at end of file