@@ -31,75 +31,75 @@ interface ISharedPreferencesProvider: ContextExtensions {
3131
3232 val sharedPref: SharedPreferences
3333
34- fun stringValue (key : String , defValue : String? = null) = StringSharedPreferenceGetter (key, defValue)
35- fun intValue (key : String , defValue : Int = 0) = IntSharedPreferenceGetter (key, defValue)
36- fun booleanValue (key : String , defValue : Boolean = false) = BooleanSharedPreferenceGetter (key, defValue)
37- fun longValue (key : String , defValue : Long = 0) = LongSharedPreferenceGetter (key, defValue)
38- fun floatValue (key : String , defValue : Float = 0F) = FloatSharedPreferenceGetter (key, defValue)
34+ fun stringValue (key : String? = null , defValue : String? = null) = StringSharedPreferenceGetter (key, defValue)
35+ fun intValue (key : String? = null , defValue : Int = 0) = IntSharedPreferenceGetter (key, defValue)
36+ fun booleanValue (key : String? = null , defValue : Boolean = false) = BooleanSharedPreferenceGetter (key, defValue)
37+ fun longValue (key : String? = null , defValue : Long = 0) = LongSharedPreferenceGetter (key, defValue)
38+ fun floatValue (key : String? = null , defValue : Float = 0F) = FloatSharedPreferenceGetter (key, defValue)
3939
4040}
4141
42- class StringSharedPreferenceGetter internal constructor(private val key : String ,
42+ class StringSharedPreferenceGetter internal constructor(private val key : String? = null ,
4343 private val defValue : String? = null )
4444 : ReadWriteProperty <ISharedPreferencesProvider , String ?>, AndroidExtensions {
4545
4646 override fun getValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >): String?
47- = thisRef.sharedPref[key].asString(defValue)
47+ = thisRef.sharedPref[key ? : property.name ].asString(defValue)
4848
4949 override fun setValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >, value : String? ) {
50- thisRef.sharedPref[key] = value
50+ thisRef.sharedPref[key ? : property.name ] = value
5151 }
5252
5353}
5454
55- class IntSharedPreferenceGetter internal constructor(private val key : String ,
55+ class IntSharedPreferenceGetter internal constructor(private val key : String? = null ,
5656 private val defValue : Int = 0 )
5757 : ReadWriteProperty <ISharedPreferencesProvider , Int >, AndroidExtensions {
5858
5959 override fun getValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >): Int
60- = thisRef.sharedPref[key].asInt(defValue)
60+ = thisRef.sharedPref[key ? : property.name ].asInt(defValue)
6161
6262 override fun setValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >, value : Int ) {
63- thisRef.sharedPref[key] = value
63+ thisRef.sharedPref[key ? : property.name ] = value
6464 }
6565
6666}
6767
68- class BooleanSharedPreferenceGetter internal constructor(private val key : String ,
68+ class BooleanSharedPreferenceGetter internal constructor(private val key : String? = null ,
6969 private val defValue : Boolean = false )
7070 : ReadWriteProperty <ISharedPreferencesProvider , Boolean >, AndroidExtensions {
7171
7272 override fun getValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >): Boolean
73- = thisRef.sharedPref[key].asBoolean(defValue)
73+ = thisRef.sharedPref[key ? : property.name ].asBoolean(defValue)
7474
7575 override fun setValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >, value : Boolean ) {
76- thisRef.sharedPref[key] = value
76+ thisRef.sharedPref[key ? : property.name ] = value
7777 }
7878
7979}
8080
81- class LongSharedPreferenceGetter internal constructor(private val key : String ,
81+ class LongSharedPreferenceGetter internal constructor(private val key : String? = null ,
8282 private val defValue : Long = 0 )
8383 : ReadWriteProperty <ISharedPreferencesProvider , Long >, AndroidExtensions {
8484
8585 override fun getValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >): Long
86- = thisRef.sharedPref[key].asLong(defValue)
86+ = thisRef.sharedPref[key ? : property.name ].asLong(defValue)
8787
8888 override fun setValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >, value : Long ) {
89- thisRef.sharedPref[key] = value
89+ thisRef.sharedPref[key ? : property.name ] = value
9090 }
9191
9292}
9393
94- class FloatSharedPreferenceGetter internal constructor(private val key : String ,
94+ class FloatSharedPreferenceGetter internal constructor(private val key : String? = null ,
9595 private val defValue : Float = 0F )
9696 : ReadWriteProperty <ISharedPreferencesProvider , Float >, AndroidExtensions {
9797
9898 override fun getValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >): Float
99- = thisRef.sharedPref[key].asFloat(defValue)
99+ = thisRef.sharedPref[key ? : property.name ].asFloat(defValue)
100100
101101 override fun setValue (thisRef : ISharedPreferencesProvider , property : KProperty <* >, value : Float ) {
102- thisRef.sharedPref[key] = value
102+ thisRef.sharedPref[key ? : property.name ] = value
103103 }
104104
105105}
0 commit comments