Skip to content

v1.7.0

Compare
Choose a tag to compare
@jeluchu jeluchu released this 08 Jul 00:35
· 25 commits to main since this release

This is the new major version of the jchucomponents, which will also include the availability of documentation, as well as a complete refactoring of all the functions that are currently in the rest of the projects and the grouping of all the previous ones.

What has changed

A new preferences module (jchucomponents-prefs) has been included, this way there will be the possibility to use SharedPreferences or DataStore according to the developer's preference in a simple way.

Initialize the module in the onCreate method of your Activity:

initDataStore(context: Context) // for DataStore

or

initSharedPrefs(context: Context) // for SharedPreferences

A class has been created that will allow you to easily access to save your preferences, with a key and the value, in addition, when accessing to retrieve that information, you can pass by parameter a default value, so that in case that value does not exist, it will return something by default.

To access this, we can simply create an object and create a variable with lazy

val preferences by lazy { DataStoreHelpers() }  // for DataStore

or

val preferences by lazy { SharedPrefsHelpers() } // for SharedPreferences

And from there we call the getPreference or savePreference methods depending on what we want to do. For example:

val getAppVersion
  get() = getPreference(KEY_APP_VERSION)

fun savePreference(
   tag: Preferences.Key<Long>,
   value: Long
) = preferences.savePreference(tag, value)

There is also support for Jetpack Compose, as it includes a way to call our preferences via a remember, which would be used as follows:

val badge by rememberPreference(
    KEY_APP_VERSION,
    "1.0.0"
)

If you have any problems, or suggestions for adding new components, don't hesitate to open an issue