Dataflow for Android¢â€‍¢ reference Dataflow for...

Click here to load reader

download Dataflow for Android¢â€‍¢ reference Dataflow for Android¢â€‍¢ reference v1, revision 1 Dataflow for Android¢â€‍¢

of 27

  • date post

    26-Aug-2020
  • Category

    Documents

  • view

    2
  • download

    0

Embed Size (px)

Transcript of Dataflow for Android¢â€‍¢ reference Dataflow for...

  • Dataflow for Android™ reference

    FEMA Studios S.r.l.s. Version 1, revision 1

  • © 2019 FEMA Studios S.r.l.s. IT 04220370276 I/III

    Dataflow for Android™ reference v1, revision 1

    Table of Contents Dataflow for Android™ 1 ..................................................................................................................... Getting started 2 .................................................................................................................................

    Setup 2 ........................................................................................................................................... Proguard and Multidexing 2 ......................................................................................................

    First look 3 ..................................................................................................................................... Preferences integration 3 .......................................................................................................... Fields in views 3 ........................................................................................................................

    Shared preferences 5 .......................................................................................................................... RawPreferenceField 5 ..................................................................................................................

    Creating a RawPreferenceField 5 .............................................................................................. Abstracting values 5 .................................................................................................................

    PreferenceField 6 .......................................................................................................................... Creating a PreferenceField 6 ..................................................................................................... Changing the value of a PreferenceField 7 ...............................................................................

    Problems of [unsafeMutable](§dataflow- android/com.femastudios.dataflow.android.preferences/-preference-field/unsafe- mutable) 7 .................................................................................................................. Problem 1: unable to remove preference 7 ................................................................. Problem 2: unable to save preference with the default value 8 ..................................

    Abstracting more complex values 8 .......................................................................................... View binding 9 ......................................................................................................................................

    Listening fields on views 9 .......................................................................................................... Views as lifecycle owners 9 ....................................................................................................... Utility functions 9 ......................................................................................................................

    View state 10 ................................................................................................................................. Creating a view state 10 ........................................................................................................... Summing view states 10 ........................................................................................................... Default view states 11 .............................................................................................................. Adding a view state permanently 11 ........................................................................................ Setting and removing a view state 11 ...................................................................................... Utility functions 13 ....................................................................................................................

    Other bindings 15 ................................................................................................................................ Activity and Fragment binding 15 ..............................................................................................

    Example 15 ........................................................................................................................ AlertDialog binding 16 .................................................................................................................

    Adapters 17 ........................................................................................................................................... FieldListViewAdapter 17 .............................................................................................................. FieldListViewArrayAdapter 17 .................................................................................................... RecyclerView FieldAdapter 19 ....................................................................................................

    The [ViewType](§dataflow-android/com.femastudios.dataflow.android.recycler-view/-view- type) class 19 .....................................................................................................................

    The [ViewTypeField](§dataflow-android/com.femastudios.dataflow.android.recycler-view/- view-type-field) class 20 ....................................................................................................

    The [ItemInfo](§dataflow-android/com.femastudios.dataflow.android.recycler-view/-item-info)

  • © 2019 FEMA Studios S.r.l.s. IT 04220370276 II/III

    Dataflow for Android™ reference v1, revision 1

    class 21 .............................................................................................................................. Creation of a [FieldAdapter](§dataflow-android/com.femastudios.dataflow.android.recycler-

    view/-field-adapter) 21 ....................................................................................................... For a single view type 21 ................................................................................................... For multiple view types 21 .................................................................................................

  • © 2019 FEMA Studios S.r.l.s. IT 04220370276 1/23

    Dataflow for Android™ reference v1, revision 1

    Dataflow for Android™ This extension allows to seamlessly integrate fields within the Android™ environment.

    The main features are:

    Preferences integration: read and write preferences through fields. Set fields in views: bind a field to a view in order to display its content.

    This library also makes use of a library that adds some basic utilities to Android™ classes.

  • © 2019 FEMA Studios S.r.l.s. IT 04220370276 2/23

    Dataflow for Android™ reference v1, revision 1

    Getting started

    Setup To add this extension all you have to do is add the following dependency:

    Gradle

    implementation 'com.femastudios:dataflow-android:1.0.0'

    Also you'll need to add the following compile and packaging options:

    Gradle

    android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' freeCompilerArgs += '-Xjvm-default=enable' } packagingOptions { exclude 'META-INF/library_release.kotlin_module' } }

    Remember also to add our server to the repositories, as explained here

    Proguard and Multidexing Since our libraries contain a lot of methods it is suggested to use Proguard to automatically remove the ones you don't use.

    To enable proguard:

    Gradle

    buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard- rules.pro' } debug { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules- debug.pro' } }

    Also, add these lines to your proguard-rules-debug.pro if you want to keep seeing methods and

    https://dataflow.femastudios.com/reference/dataflow/v1/getting-started/setup#adding-the-library-to-your-project https://developer.android.com/studio/build/shrink-code

  • © 2019 FEMA Studios S.r.l.s. IT 04220370276 3/23

    Dataflow for Android™ reference v1, revision 1

    class names during debug:

    -keepattributes SourceFile,LineNumberTable -keepattributes LocalVariableTable,LocalVariableTypeTable -keepnames class ** { *; }

    If even after applying Proguard you still exceed the Android™'s limited 64K number of methods you should enable multidexing.

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

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

    Kotlin

    val counter = context.defaultPreferences.getIntField("favorite_number", 0)

    counter.rawValue.value = 73

    Java

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); MutableField counter = SharedPreferencesUtils.getIntField(sp, "favorite_number", 0);

    counter.getRawValue().setValue(7