├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── dimens.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── github │ │ │ │ └── lzyzsd │ │ │ │ └── rxexamples │ │ │ │ ├── NetworkService.java │ │ │ │ ├── operators │ │ │ │ ├── TransformDemo.java │ │ │ │ └── LiftDemo.java │ │ │ │ ├── DemoUtils.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── lzyzsd │ │ │ └── rxexamples │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── github │ │ └── lzyzsd │ │ └── rxexamples │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .gitignore ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Some RxJava & RxAndroid use cases. 2 | 3 | Hope it can help understand Rx better. -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uknownothingsnow/RxJavaExamples/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uknownothingsnow/RxJavaExamples/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uknownothingsnow/RxJavaExamples/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uknownothingsnow/RxJavaExamples/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uknownothingsnow/RxJavaExamples/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uknownothingsnow/RxJavaExamples/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RxExamples 3 | MainActivity 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Nov 13 21:37:10 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/github/lzyzsd/rxexamples/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.rxexamples; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/github/lzyzsd/rxexamples/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.rxexamples; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/github/lzyzsd/rxexamples/NetworkService.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.rxexamples; 2 | 3 | import rx.Observable; 4 | 5 | /** 6 | * Created by bruce on 11/18/15. 7 | */ 8 | public class NetworkService { 9 | public static Observable getToken(String userName, String pwd) { 10 | return Observable.just("token"); 11 | } 12 | 13 | public static Observable getMessage(String token) { 14 | return Observable.just("message"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/lzyzsd/rxexamples/operators/TransformDemo.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.rxexamples.operators; 2 | 3 | import rx.Observable; 4 | 5 | /** 6 | * Created by bruce on 11/20/15. 7 | */ 8 | public class TransformDemo { 9 | public static void complexTransform() { 10 | Observable.just("1", "2", "2", "3", "4", "5") 11 | .map(Integer::parseInt) 12 | .filter(s -> s > 1) 13 | .distinct() 14 | .take(3) 15 | .reduce((integer, integer2) -> integer.intValue() + integer2.intValue()) 16 | .subscribe(System.out::println);//9 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/bruce/Downloads/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #built application files 2 | *.apk 3 | *.ap_ 4 | 5 | 6 | # files for the dex VM 7 | *.dex 8 | 9 | 10 | # Java class files 11 | *.class 12 | 13 | 14 | # generated files 15 | bin/ 16 | gen/ 17 | 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | 23 | # Windows thumbnail db 24 | Thumbs.db 25 | 26 | 27 | # OSX files 28 | .DS_Store 29 | 30 | 31 | # Eclipse project files 32 | .classpath 33 | .project 34 | 35 | 36 | # Android Studio 37 | .idea 38 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 39 | .gradle 40 | build/ 41 | 42 | 43 | # Signing files 44 | .signing/ 45 | 46 | 47 | # User-specific configurations 48 | .idea/libraries/ 49 | .idea/workspace.xml 50 | .idea/tasks.xml 51 | .idea/.name 52 | .idea/compiler.xml 53 | .idea/copyright/profiles_settings.xml 54 | .idea/encodings.xml 55 | .idea/misc.xml 56 | .idea/modules.xml 57 | .idea/scopes/scope_settings.xml 58 | .idea/vcs.xml 59 | *.iml -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'me.tatarka.retrolambda' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.2" 7 | 8 | defaultConfig { 9 | applicationId "com.github.lzyzsd.rxexamples" 10 | minSdkVersion 15 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(dir: 'libs', include: ['*.jar']) 29 | testCompile 'junit:junit:4.12' 30 | compile 'io.reactivex:rxjava:1.0.14' 31 | compile 'io.reactivex:rxandroid:1.0.1' 32 | compile 'com.jakewharton:butterknife:7.0.1' 33 | compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1' 34 | compile 'com.jakewharton.rxbinding:rxbinding:0.3.0' 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/lzyzsd/rxexamples/operators/LiftDemo.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.rxexamples.operators; 2 | 3 | import rx.Observable; 4 | import rx.Subscriber; 5 | 6 | /** 7 | * Created by bruce on 11/20/15. 8 | * 展示如何使用lift自定义operator 9 | * 好处是可以让原有的Observable链式调用不被打断,继续保持链式调用的形式 10 | */ 11 | public class LiftDemo { 12 | /** 13 | * 这里展示了如何自定义一个operator,用来将每个发出来的字符串转换成一个整数 14 | */ 15 | public static void createCustomOperator() { 16 | Observable.just("1", "2", "3") 17 | .lift(subscriber -> new Subscriber() { 18 | @Override 19 | public void onCompleted() { 20 | subscriber.onCompleted(); 21 | } 22 | 23 | @Override 24 | public void onError(Throwable e) { 25 | subscriber.onError(e); 26 | } 27 | 28 | @Override 29 | public void onNext(String s) { 30 | subscriber.onNext(Integer.parseInt(s)); 31 | } 32 | }) 33 | .map(i -> i) 34 | .subscribe(System.out::println);//1 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |