Files
SimplicityTools/app/src/main/java/com/lt2333/simplicitytools/util/XSPUtils.kt
YuKongA 90466bb3fb Merge pull request #169
* 修复 隐藏网速单位 & 随便精简了下代码

* Update SettingsActivity.kt
2022-05-25 22:04:41 +08:00

49 lines
1.3 KiB
Kotlin

package com.lt2333.simplicitytools.util
import com.lt2333.simplicitytools.BuildConfig
import de.robv.android.xposed.XSharedPreferences
object XSPUtils {
private var prefs = XSharedPreferences(BuildConfig.APPLICATION_ID, "config")
fun getBoolean(key: String, defValue: Boolean): Boolean {
if (prefs.hasFileChanged()) {
prefs.reload()
}
return prefs.getBoolean(key, defValue)
}
fun getInt(key: String, defValue: Int): Int {
if (prefs.hasFileChanged()) {
prefs.reload()
}
return prefs.getInt(key, defValue)
}
fun getFloat(key: String, defValue: Float): Float {
if (prefs.hasFileChanged()) {
prefs.reload()
}
return prefs.getFloat(key, defValue)
}
fun getString(key: String, defValue: String): String? {
if (prefs.hasFileChanged()) {
prefs.reload()
}
return prefs.getString(key, defValue)
}
}
inline fun hasEnable(
key: String,
default: Boolean = false,
noinline extraCondition: (() -> Boolean)? = null,
crossinline block: () -> Unit
) {
val conditionResult = if (extraCondition != null) extraCondition() else true
if (XSPUtils.getBoolean(key, default) && conditionResult) {
block()
}
}