First look

There are two main features in this extension: preferences integration and fields in views.

Preferences integration

link

With the integration of shared preferences we can create fields that are bound to a specific key, like so:

val counter = context.defaultPreferences.getIntField("favorite_number", 0) counter.rawValue.value = 73
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); MutableField<Integer> counter = SharedPreferencesUtils.getIntField(sp, "favorite_number", 0); counter.getRawValue().setValue(73);

In this example we created a field that is bound to the "favorite_number" key in the default preferences. This means that we can change it but also listen for changes.

For more information see Shared preferences.

Fields in views

link

The most important feature is the ability to directly set a Field in a View. This works by attaching a LifecyleOwner instance to the view through tags. Most common functions are available:

val tv = TextView(context) tv.setText(movie.name) //movie.name is a Field<String> tv.setVisible(movie.name.isNotBlank())
TextView tv = new TextView(getContext()); ViewUtils.setText(tv, movie.name); ViewUtils.setVisible(tv, CharSequenceFieldUtils.isNotBlank(movie.getName()));

For more information see View binding.