Skip to content

Commit f936750

Browse files
feat: added coroutine adapter example
1 parent 8fae7df commit f936750

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1057
-1
lines changed

CoroutineAdapters/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild
10+
/gradle.properties

CoroutineAdapters/.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CoroutineAdapters/.idea/misc.xml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CoroutineAdapters/.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CoroutineAdapters/.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CoroutineAdapters/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# CoroutineAdapter
2+
Coroutines are used to simplify asynchronous programming. They are very light and can be sometimes used in place of RxJava for performing async operations with less code. Coroutine Adapter is a call Adapter around Retrofit for Http calls developed by Jake Wharton.
3+
<br>
4+
<b>Docs: </b> https://github.com/JakeWharton/retrofit2-kotlin-coroutines-adapter
5+
<br><br>
6+
In this example we asynchronously hit 2 endpoints 1st is from where we get id and 2nd is to get the list of crew. We use coroutine Adapter of retrofit to asynchronously hit the 2 end points.
7+
<br><br>
8+
PS: Coroutines are in a experimental version. They will soon be stable.
9+
<br><br>
10+
To integrate the adapter integrate following dependency:
11+
<br>
12+
<pre>
13+
compile 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:1.0.0'
14+
</pre>
15+
<br><br>
16+
Screenshots:
17+
<br><br>
18+
<img src="realm.gif"/>

CoroutineAdapters/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

CoroutineAdapters/app/build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 26
9+
defaultConfig {
10+
applicationId "com.developers.coroutineadapters"
11+
minSdkVersion 19
12+
targetSdkVersion 26
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
24+
buildTypes.each {
25+
it.buildConfigField('String', "MOVIE_KEY", API_KEY)
26+
}
27+
}
28+
29+
dependencies {
30+
implementation fileTree(dir: 'libs', include: ['*.jar'])
31+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
32+
implementation 'com.android.support:appcompat-v7:26.1.0'
33+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
34+
testImplementation 'junit:junit:4.12'
35+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
36+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
37+
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:1.0.0'
38+
implementation "com.squareup.retrofit2:converter-gson:2.3.0"
39+
implementation 'com.android.support:cardview-v7:26.1.0'
40+
implementation 'com.android.support:recyclerview-v7:26.1.0'
41+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:0.21"
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.developers.coroutineadapters
2+
3+
import android.support.test.InstrumentationRegistry
4+
import android.support.test.runner.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getTargetContext()
22+
assertEquals("com.developers.coroutineadapters", appContext.packageName)
23+
}
24+
}

0 commit comments

Comments
 (0)