Skip to content

Commit b961f32

Browse files
committed
[1.7.0-feature] 委托封装sp优化
1 parent 1f59ab3 commit b961f32

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

app/src/main/kotlin/org/ninetripods/mq/study/util/sp/SharedPreferencesDelegate.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SharedPreferencesDelegate<T>(
3232
is Float -> sp.getFloat(finalKey, defaultValue)
3333
is Boolean -> sp.getBoolean(finalKey, defaultValue)
3434
is String -> sp.getString(finalKey, defaultValue)
35+
is Set<*> -> sp.getStringSet(finalKey, defaultValue as? Set<String>)
3536
else -> throw IllegalStateException("Unsupported type")
3637
} as T
3738
}
@@ -45,6 +46,7 @@ class SharedPreferencesDelegate<T>(
4546
is Float -> putFloat(finalKey, value)
4647
is Boolean -> putBoolean(finalKey, value)
4748
is String -> putString(finalKey, value)
49+
is Set<*> -> putStringSet(finalKey, value.map { it.toString() }.toHashSet())
4850
else -> throw IllegalStateException("Unsupported type")
4951
}
5052
apply()

0 commit comments

Comments
 (0)