To interact with UI elements, we will use two great libraries: RxBinding (which can be found at https://github.com/JakeWharton/RxBinding ) and Butterknife (which can be found at https://github.com/JakeWharton/butterknife ).
ButterKnife will let us easily import UI elements into Java code (no more pesky findViewById()!) and RxBinding will let us make all UI interactions RxJava friendly.
To include ButterKnife, let's add these lines:
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
To include RxBinding, put in the following:
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
compile 'com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:2.0.0'
Finally, we will be using the RecyclerView and CardView elements from Android Support Repository, so these will be needed as well:
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
In the future, we might need to mix different versions of RxJava, so this line (under android block) will help when both the libraries will be included at the same time:
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
In the end, the top of the build.gradle file will look like this:
plugins {
id "me.tatarka.retrolambda" version "3.4.0"
}
apply plugin: 'com.android.application'
Also, the android block will be as follows:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "packt.reactivestocks"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-
android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
The dependency block will be set to the following:
dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
compile group: 'io.reactivex.rxjava2', name: 'rxjava', version:
'2.0.3'
compile group: 'io.reactivex.rxjava2', name: 'rxandroid', version:
'2.0.1'
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
compile 'com.jakewharton.rxbinding2:rxbinding-recyclerview-
v7:2.0.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile "com.github.akarnokd:rxjava2-interop:0.8.1"
}