TypedValue

Additional

Language
Kotlin
Version
v0.9.2 (Sep 18, 2018)
Created
Mar 27, 2018
Updated
Dec 13, 2018 (Retired)
Owner
Yuri Denison (YuriDenison)
Contributor
Yuri Denison (YuriDenison)
1
Activity
Badge
Generate
Download
Source code

TypedValue

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:

Date module contains custom TypedValues for managing dates:

For java.time entities ThreeTen library is used.

Demo app

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 properties

     interface 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

Installation

Add the following dependency to your build.gradle file:

dependencies {
    implementation 'io.denison:typedvalue:${LATEST_VERSION}'
    implementation 'io.denison:typedvalue-date:${LATEST_VERSION}'
}

License

Please see LICENSE