├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── io
│ │ └── github
│ │ └── patrickyin
│ │ └── coroutinesvsrx
│ │ ├── MainActivity.kt
│ │ └── data
│ │ ├── CoroutineRestfulAPI.kt
│ │ ├── HTTPClient.kt
│ │ ├── RxRestfulAPI.kt
│ │ └── model
│ │ ├── Launch.kt
│ │ ├── LaunchSite.kt
│ │ ├── Rocket.kt
│ │ └── RocketDetail.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/
38 |
39 | # Keystore files
40 | # Uncomment the following line if you do not want to check your keystore files in.
41 | #*.jks
42 |
43 | # External native build folder generated in Android Studio 2.2 and later
44 | .externalNativeBuild
45 |
46 | # Google Services (e.g. APIs or Firebase)
47 | google-services.json
48 |
49 | # Freeline
50 | freeline.py
51 | freeline/
52 | freeline_project_description.json
53 |
54 | # fastlane
55 | fastlane/report.xml
56 | fastlane/Preview.html
57 | fastlane/screenshots
58 | fastlane/test_output
59 | fastlane/readme.md
60 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - build-tools-28.0.2
6 | - android-28
7 | - extra-google-google_play_services
8 | - extra-google-m2repository
9 | - extra-android-m2repository
10 | - extra-android-support
11 | - addon-google_apis-google-28
12 |
13 | before_cache:
14 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
15 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
16 | cache:
17 | directories:
18 | - $HOME/.gradle/caches/
19 | - $HOME/.gradle/wrapper/
20 | - $HOME/.android/build-cache
21 |
22 | script:
23 | - ./gradlew build
24 |
25 | after_success:
26 | - bash <(curl -s https://codecov.io/bash)
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Patrick Yin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # kotlin-coroutines-vs-rx-java
2 |
3 | [](https://travis-ci.org/patrickyin/kotlin-coroutines-vs-rx)
4 |
5 | This is a simple `Kotlin Coroutines vs. RxJava` sample. It calls SpaceX's api to get the next launch's deatil.
6 |
7 | ## Dependencies
8 | * RxJava2
9 | * RxAndroid
10 | * Kotlinx-coroutines
11 | * GSON
12 | * OKHTTP
13 | * Retrofit2
14 | * Retrofit2-adapter-rxjava2
15 | * Retrofit2-adapter-kotlin-coroutines
16 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 |
6 | android {
7 | compileSdkVersion rootProject.ext.compile_sdk_version
8 | buildToolsVersion rootProject.ext.build_tools_version
9 |
10 | defaultConfig {
11 | applicationId rootProject.ext.application_id
12 | minSdkVersion rootProject.ext.mini_sdk_version
13 | targetSdkVersion rootProject.ext.target_sdk_version
14 | versionCode rootProject.ext.version_code
15 | versionName rootProject.ext.version_name
16 | testInstrumentationRunner rootProject.ext.test_runner
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | useProguard false
22 | }
23 | }
24 |
25 | flavorDimensions "mode"
26 |
27 | productFlavors {
28 | def DEVELOPMENT_ENDPOINT = "https://api.spacexdata.com/v2/"
29 | development {
30 | dimension "mode"
31 | buildConfigField "String", "ENDPOINT", "\"" + DEVELOPMENT_ENDPOINT + "\""
32 | }
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
39 | implementation "com.android.support:appcompat-v7:${rootProject.ext.support_library_version}"
40 | implementation "com.android.support:recyclerview-v7:${rootProject.ext.support_library_version}"
41 | implementation "com.android.support.constraint:constraint-layout:${rootProject.ext.constraint_layout_version}"
42 |
43 | implementation "com.squareup.retrofit2:retrofit:${rootProject.ext.retrofit2_version}"
44 | implementation "com.squareup.retrofit2:adapter-rxjava2:${rootProject.ext.retrofit2_version}"
45 |
46 | implementation "com.squareup.okhttp3:okhttp:${rootProject.ext.okhttp3_version}"
47 |
48 | implementation "com.google.code.gson:gson:${rootProject.ext.gson_version}"
49 | implementation "com.squareup.retrofit2:converter-gson:${rootProject.ext.retrofit2_version}"
50 |
51 | implementation "io.reactivex.rxjava2:rxjava:${rootProject.ext.rxjava2_version}"
52 | implementation "io.reactivex.rxjava2:rxandroid:${rootProject.ext.rxandroid_version}"
53 |
54 | implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:${rootProject.ext.retrofit2_coroutines_adapter_version}"
55 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${rootProject.ext.coroutines_android_version}"
56 |
57 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
58 | testImplementation "junit:junit:${rootProject.ext.junit_version}"
59 | testImplementation "org.mockito:mockito-core:${rootProject.ext.mockito_version}"
60 | testImplementation "org.powermock:powermock-module-junit4:${rootProject.ext.powermock_version}"
61 | testImplementation "org.powermock:powermock-api-mockito2:${rootProject.ext.powermock_version}"
62 | androidTestImplementation "com.android.support.test:runner:${rootProject.ext.support_library_test_runner_version}"
63 | androidTestImplementation "com.android.support.test.espresso:espresso-core:${rootProject.ext.espresso_version}"
64 | }
65 |
--------------------------------------------------------------------------------
/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/patrick/Documents/android_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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx
2 |
3 | import android.os.Bundle
4 | import android.support.annotation.UiThread
5 | import android.support.v7.app.AppCompatActivity
6 | import io.github.patrickyin.coroutinesvsrx.data.HTTPClient
7 | import io.github.patrickyin.coroutinesvsrx.data.model.RocketDetail
8 | import io.reactivex.android.schedulers.AndroidSchedulers
9 | import io.reactivex.disposables.CompositeDisposable
10 | import io.reactivex.schedulers.Schedulers
11 | import kotlinx.android.synthetic.main.activity_main.*
12 | import kotlinx.coroutines.experimental.CommonPool
13 | import kotlinx.coroutines.experimental.android.UI
14 | import kotlinx.coroutines.experimental.cancel
15 | import kotlinx.coroutines.experimental.launch
16 |
17 |
18 | class MainActivity : AppCompatActivity() {
19 |
20 | private val disposables = CompositeDisposable()
21 |
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | setContentView(R.layout.activity_main)
25 |
26 | clear.setOnClickListener { text_view.text = null }
27 |
28 | load_rx.setOnClickListener { fetchDataRx() }
29 |
30 | load_coroutines.setOnClickListener { fetchDataCoroutines() }
31 | }
32 |
33 | override fun onDestroy() {
34 | super.onDestroy()
35 |
36 | disposables.clear()
37 | CommonPool.cancel()
38 | }
39 |
40 | private fun fetchDataCoroutines() {
41 | val restfulAPI = HTTPClient.coroutineRestfulAPI
42 | launch(UI) {
43 | try {
44 | val nextLaunch = restfulAPI.getNextLaunch().await()
45 | val rocketDetail = restfulAPI.getRocket(nextLaunch.rocket?.rocketId ?: "").await()
46 | val result = formatString(rocketDetail)
47 | updateUI(result)
48 | } catch (e: Throwable) {
49 | showError(e)
50 | }
51 | }
52 | }
53 |
54 | private fun fetchDataRx() {
55 | val restfulAPI = HTTPClient.rxRestfulAPI
56 |
57 | val disposable = restfulAPI.getNextLaunch()
58 | .flatMap { restfulAPI.getRocket(it.rocket?.rocketId ?: "0") }
59 | .map { formatString(it) }
60 | .subscribeOn(Schedulers.io())
61 | .observeOn(AndroidSchedulers.mainThread())
62 | .subscribe({ text -> updateUI(text) }, { showError(it) })
63 | disposables.add(disposable)
64 | }
65 |
66 | private fun formatString(rocketDetail: RocketDetail) =
67 | "Rocket name: ${rocketDetail.name}\nStages: ${rocketDetail.stages} \nCost per launch: ${rocketDetail.costPerLaunch}"
68 |
69 | private fun showError(throwable: Throwable) {
70 | text_view.text = throwable.localizedMessage
71 | }
72 |
73 | @UiThread
74 | private fun updateUI(text: String) {
75 | text_view.text = text
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/data/CoroutineRestfulAPI.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx.data
2 |
3 | import io.github.patrickyin.coroutinesvsrx.data.model.Launch
4 | import io.github.patrickyin.coroutinesvsrx.data.model.RocketDetail
5 | import kotlinx.coroutines.experimental.Deferred
6 | import retrofit2.http.GET
7 | import retrofit2.http.Path
8 |
9 | interface CoroutineRestfulAPI {
10 | @GET("launches/next")
11 | fun getNextLaunch(): Deferred
12 |
13 | @GET("rockets/{rocketId}")
14 | fun getRocket(@Path("rocketId") rocketId: String): Deferred
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/data/HTTPClient.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx.data
2 |
3 | import com.jakewharton.retrofit2.adapter.kotlin.coroutines.experimental.CoroutineCallAdapterFactory
4 | import io.github.patrickyin.coroutinesvsrx.BuildConfig
5 | import retrofit2.CallAdapter
6 | import retrofit2.Retrofit
7 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
8 | import retrofit2.converter.gson.GsonConverterFactory
9 |
10 | object HTTPClient {
11 | val rxRestfulAPI: RxRestfulAPI by lazy {
12 | initializeRetrofit(RxJava2CallAdapterFactory.create())
13 | }
14 |
15 | val coroutineRestfulAPI: CoroutineRestfulAPI by lazy {
16 | initializeRetrofit(CoroutineCallAdapterFactory())
17 | }
18 |
19 | private inline fun initializeRetrofit(retrofitFactory: CallAdapter.Factory): T {
20 | val retrofit = Retrofit.Builder()
21 | .baseUrl(BuildConfig.ENDPOINT)
22 | .addConverterFactory(GsonConverterFactory.create())
23 | .addCallAdapterFactory(retrofitFactory)
24 | .build()
25 |
26 | return retrofit.create(T::class.java)
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/data/RxRestfulAPI.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx.data
2 |
3 | import io.github.patrickyin.coroutinesvsrx.data.model.Launch
4 | import io.github.patrickyin.coroutinesvsrx.data.model.RocketDetail
5 | import io.reactivex.Single
6 | import retrofit2.http.GET
7 | import retrofit2.http.Path
8 |
9 | interface RxRestfulAPI {
10 | @GET("launches/next")
11 | fun getNextLaunch(): Single
12 |
13 | @GET("rockets/{rocketId}")
14 | fun getRocket(@Path("rocketId") rocketId: String): Single
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/data/model/Launch.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx.data.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class Launch(
6 | @SerializedName("rocket")
7 | var rocket: Rocket? = null,
8 | @SerializedName("launch_site")
9 | var launchSite: LaunchSite? = null
10 | )
11 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/data/model/LaunchSite.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx.data.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class LaunchSite(
6 | @SerializedName("site_id")
7 | var siteId: String? = null,
8 | @SerializedName("site_name")
9 | var siteName: String? = null,
10 | @SerializedName("site_name_long")
11 | var siteNameLong: String? = null
12 | )
13 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/data/model/Rocket.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx.data.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class Rocket(
6 | @SerializedName("rocket_id")
7 | var rocketId: String? = null
8 | )
9 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/patrickyin/coroutinesvsrx/data/model/RocketDetail.kt:
--------------------------------------------------------------------------------
1 | package io.github.patrickyin.coroutinesvsrx.data.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class RocketDetail(
6 | @SerializedName("name")
7 | var name: String? = null,
8 | @SerializedName("stages")
9 | var stages: String? = null,
10 | @SerializedName("cost_per_launch")
11 | var costPerLaunch: String? = null
12 | )
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
22 |
23 |
35 |
36 |
49 |
50 |
62 |
63 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Kotlin coroutines vs Rx
3 | Load data - Coroutines
4 | Load data - Rx
5 | Clear
6 | dummy button
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.2.60'
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:3.1.4'
9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | google()
16 | jcenter()
17 | }
18 | ext {
19 | application_id = "io.github.patrickyin.coroutinesvsrx"
20 | test_runner = "android.support.test.runner.AndroidJUnitRunner"
21 | compile_sdk_version = 28
22 | mini_sdk_version = 21
23 | target_sdk_version = 28
24 | build_tools_version = '28.0.2'
25 | version_code = 1
26 | version_name = "1.0"
27 |
28 | support_library_version = "27.1.1"
29 | constraint_layout_version = "1.1.2"
30 | retrofit2_version = "2.3.0"
31 | retrofit2_coroutines_adapter_version = "1.0.0"
32 | okhttp3_version = "3.10.0"
33 | gson_version = "2.8.2"
34 | rxjava2_version = "2.1.10"
35 | rxandroid_version = "2.0.2"
36 | coroutines_android_version = "0.24.0"
37 | junit_version = "4.12"
38 | mockito_version = "2.8.9"
39 | powermock_version = "1.7.1"
40 | support_library_test_runner_version = "1.0.1"
41 | espresso_version = "3.0.1"
42 | }
43 | }
44 |
45 | task clean(type: Delete) {
46 | delete rootProject.buildDir
47 | }
48 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patrickyin/kotlin-coroutines-vs-rx/64b36f7b6f6c1f95e3f741f28d0e6901d950a9ac/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 16 14:05:23 AEST 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------