TypedValue is a tiny library project to simplify access to SharedPreferences, Bundle or any other key-value storage with it's own KeyValueDelegate
Common values are available out of the box:
- BoolValue
- StringValue
- IntValue
- LongValue
- FloatValue
- DoubleValue
- ParcelableValue
- StringListValue
- StringSetValue
Date module contains custom TypedValues for managing dates:
For java.time
entities ThreeTen library is used.
The sample
application demonstrates:
-
Convenient way to manage application preferences: AppPreferences and AppPreferencesImpl
Any calls (
get()
,set()
,asObservable()
, etc.) of each preference can be easily find via interface propertiesinterface AppPreferences { val animationTypeValue: AnimationTypeValue val scaleValue: FloatValue val messageShownValue: BoolValue }
class AppPreferencesImpl(app: Application) : AppPreferences { private val delegate = PreferenceDelegate(PreferenceManager.getDefaultSharedPreferences(app)) override val animationTypeValue: AnimationTypeValue by lazy { AnimationTypeValue(delegate, KEY_ANIMATION_TYPE, AnimationType.CONFETTI) } override val scaleValue: FloatValue by lazy { FloatValue(delegate, KEY_SCALE, 0.8f) } override val messageShownValue: BoolValue by lazy { BoolValue(delegate, KEY_MESSAGE_SHOWN) } private companion object { const val KEY_ANIMATION_TYPE = ".key_animation_type" const val KEY_SCALE = ".key_scale" const val KEY_MESSAGE_SHOWN = ".key_message_shown" } }
-
benefits of observable SharedPreferences with uni-directional data flow of 'SettingsPresenter'
-
custom TypedValue: AnimationTypeValue
Add the following dependency to your build.gradle
file:
dependencies {
implementation 'io.denison:typedvalue:${LATEST_VERSION}'
implementation 'io.denison:typedvalue-date:${LATEST_VERSION}'
}
Please see LICENSE