Skip to content

Instantly share code, notes, and snippets.

@Krosxx
Created June 29, 2020 09:03
Show Gist options
  • Save Krosxx/c2b36b92121780c845232de4db45c482 to your computer and use it in GitHub Desktop.
Save Krosxx/c2b36b92121780c845232de4db45c482 to your computer and use it in GitHub Desktop.
PreferenceDataStore for SmartKey
import androidx.preference.PreferenceDataStore
import cn.vove7.smartkey.BaseConfig
import cn.vove7.smartkey.get
/**
* # SmartKeyDataStore
*
* Created on 2020/6/29
* @author Vove
*/
class SmartKeyDataStore(
private val config: BaseConfig
) : PreferenceDataStore() {
override fun getBoolean(key: String?, defValue: Boolean): Boolean {
return config[key!!, false, defValue]
}
override fun putLong(key: String?, value: Long) {
config[key!!] = value
}
override fun putInt(key: String?, value: Int) {
config[key!!] = value
}
override fun getInt(key: String?, defValue: Int): Int {
return config[key!!, defValue]
}
override fun putBoolean(key: String?, value: Boolean) {
config[key!!] = value
}
override fun getLong(key: String?, defValue: Long): Long {
return config[key!!, defValue]
}
override fun getFloat(key: String?, defValue: Float): Float {
return config[key!!, defValue]
}
override fun putFloat(key: String?, value: Float) {
config[key!!] = value
}
override fun getString(key: String?, defValue: String?): String? {
return config[key!!, defValue]
}
override fun putString(key: String?, value: String?) {
config[key!!] = value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment