Skip to content
This repository was archived by the owner on Aug 22, 2021. It is now read-only.

Latest commit

 

History

History
35 lines (26 loc) · 733 Bytes

README.md

File metadata and controls

35 lines (26 loc) · 733 Bytes

Kpreferences

This is work in progress.

Concept

Generate a class wrapper for SharedPreferences in Kotlin so we can use its properties to retrieve and set value in SharedPreferences.

interface MyPreferences {
  var userOnboardingDone: Boolean
}

By proxy class (reflection) like Retrofit.

val myPrefs = Kreferences(sharedPreferences).create(MyPreferences::class)
if (myPrefs.userOnboadingDone) {
  showUserOnboarding()
}

By annotation processing and codegen like Dagger and ButterKnife.

@Preferences interface MyPreferences {
  var userOnboardingDone: Boolean
}

val myPrefs = KreferencesMyPreferences(sharedPreferences)
if (myPrefs.userOnboadingDone) {
  showUserOnboarding()
}