add a few more helpers

This commit is contained in:
Hailey
2024-06-26 11:37:02 -07:00
parent 37ff335a12
commit ac0ba3ade7
2 changed files with 37 additions and 15 deletions
@@ -159,4 +159,22 @@ class Preferences(private val context: Context) {
val set = safeInstance.getStringSet(key, setOf()) ?: setOf()
return set.contains(value)
}
fun hasValue(key: String): Boolean {
val safeInstance = getInstance(context)
return safeInstance.contains(key)
}
fun getValues(keys: Set<String>): Map<String, Any?> {
val safeInstance = getInstance(context)
return keys.associateWith { key ->
when (val value = safeInstance.all[key]) {
is String -> value
is Float -> value
is Boolean -> value
is Set<*> -> value
else -> null
}
}
}
}
@@ -82,4 +82,8 @@ public class SharedPrefs {
public func hasValue(_ key: String) -> Bool {
return getDefaults(key)?.value(forKey: key) != nil
}
public func getValues(_ keys: [String]) -> [String:Any?]? {
return getDefaults("keys:\(keys)")?.dictionaryWithValues(forKeys: keys)
}
}