Skip to content

Commit ce23e7e

Browse files
committed
kotlin extension method for futures
1 parent 164356f commit ce23e7e

File tree

10 files changed

+243
-0
lines changed

10 files changed

+243
-0
lines changed

AndroidAsyncKotlin/.gitignore

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

AndroidAsyncKotlin/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
android {
5+
compileSdkVersion 29
6+
buildToolsVersion "29.0.1"
7+
8+
9+
defaultConfig {
10+
minSdkVersion 14
11+
targetSdkVersion 29
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
consumerProguardFiles 'consumer-rules.pro'
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
26+
}
27+
28+
dependencies {
29+
implementation fileTree(dir: 'libs', include: ['*.jar'])
30+
testImplementation 'junit:junit:4.12'
31+
androidTestImplementation 'androidx.test:runner:1.1.1'
32+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
33+
34+
api project(':AndroidAsync:AndroidAsync')
35+
}
36+
37+
// upload to maven task
38+
if (System.getenv().I_AM_KOUSH == 'true') {
39+
apply from: 'upload.gradle'
40+
}

AndroidAsyncKotlin/consumer-rules.pro

Whitespace-only changes.

AndroidAsyncKotlin/proguard-rules.pro

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.koushikdutta.async.kotlin
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext
22+
assertEquals("com.koushikdutta.async.kotlin.test", appContext.packageName)
23+
}
24+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.koushikdutta.async.kotlin" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.koushikdutta.async.kotlin
2+
3+
import com.koushikdutta.async.future.Future
4+
import kotlin.coroutines.resume
5+
import kotlin.coroutines.resumeWithException
6+
import kotlin.coroutines.suspendCoroutine
7+
8+
suspend fun <T> Future<T>.await(): T {
9+
return suspendCoroutine {
10+
this.setCallback { e, result ->
11+
if (e != null)
12+
it.resumeWithException(e)
13+
else
14+
it.resume(result)
15+
}
16+
}
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">AndroidAsyncKotlin</string>
3+
</resources>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.koushikdutta.async.kotlin
2+
3+
import org.junit.Test
4+
5+
import org.junit.Assert.*
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* See [testing documentation](http://d.android.com/tools/testing).
11+
*/
12+
class ExampleUnitTest {
13+
@Test
14+
fun addition_isCorrect() {
15+
assertEquals(4, 2 + 2)
16+
}
17+
}

AndroidAsyncKotlin/upload.gradle

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Setup
2+
3+
// 0) Setup your sonatype credentials by editing/creating ~/.gradle/gradle.properties and enter:
4+
// signing.keyId=<HEXADECIMCAL KEY ID RETRIVABLE VIA gpg --list-keys>
5+
// signing.password=<KEY PASSWORD>
6+
// signing.secretKeyRingFile=<PATH TO KEY RING, USUALLY ~/.gnupg/secring.gpg>
7+
// sonatypeUsername=<SONATYPE USERNAME OR WHATEVER YOU USE>
8+
// sonatypePassword=<CORRESPONDING PASSWORD>
9+
10+
// 1) Setup your build.gradle for your android project and add this one line of code which imports this gist:
11+
// apply from: 'https://raw.github.com/koush/mvn-repo/master/maven.gradle'
12+
13+
// 2) gradle clean && gradle build && gradle uploadArchives
14+
15+
// 3) That's it!
16+
17+
18+
apply plugin: 'maven'
19+
apply plugin: 'signing'
20+
21+
22+
afterEvaluate { project ->
23+
String user = null
24+
String repo = null
25+
'git remote -v'.execute(null, project.projectDir).getText().find('.*[email protected]/(.*?)/(.*?) .*?') {
26+
match ->
27+
user = match[1]
28+
repo = match[2]
29+
}
30+
31+
String githubUrl = 'https://api.github.com/repos/' + user + '/' + repo;
32+
if (System.getenv().GITHUB_TOKEN)
33+
githubUrl += '?access_token=' + System.getenv().GITHUB_TOKEN
34+
def repoInfo = new groovy.json.JsonSlurper().parseText(new URL(githubUrl).getText())
35+
36+
def android_manifest
37+
try {
38+
android_manifest = new XmlParser(false, false).parseText(new File(project.projectDir, 'AndroidManifest.xml').getText())
39+
}
40+
catch (e) {
41+
android_manifest = new XmlParser(false, false).parseText(new File(project.projectDir, 'src/main/AndroidManifest.xml').getText())
42+
}
43+
def versionName = android_manifest.'@android:versionName'
44+
def package_name = android_manifest.'@package'
45+
def artifact_id = project.projectDir.getName().toLowerCase()
46+
project.version = versionName
47+
project.group = package_name
48+
49+
uploadArchives {
50+
repositories {
51+
mavenDeployer {
52+
53+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
54+
pom.groupId = package_name
55+
pom.artifactId = artifact_id
56+
pom.version = versionName
57+
58+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
59+
authentication(userName: sonatypeUsername, password: sonatypePassword)
60+
}
61+
62+
pom.project {
63+
name repo
64+
packaging 'jar'
65+
description repoInfo.description
66+
url repoInfo.html_url
67+
68+
scm {
69+
url repoInfo.git_url
70+
connection repoInfo.git_url
71+
developerConnection repoInfo.ssh_url
72+
}
73+
74+
licenses {
75+
license {
76+
name 'The Apache Software License, Version 2.0'
77+
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
78+
distribution 'repo'
79+
}
80+
}
81+
82+
developers {
83+
developer {
84+
id user
85+
name user
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
92+
93+
signing {
94+
sign configurations.archives
95+
}
96+
97+
task androidJavadocs(type: Javadoc) {
98+
source = android.sourceSets.main.java.srcDirs
99+
}
100+
101+
task androidJavadocsJar(type: Jar) {
102+
classifier = 'javadoc'
103+
baseName = artifact_id
104+
from androidJavadocs.destinationDir
105+
}
106+
107+
task androidSourcesJar(type: Jar) {
108+
classifier = 'sources'
109+
baseName = artifact_id
110+
from android.sourceSets.main.java.srcDirs
111+
}
112+
113+
artifacts {
114+
// archives packageReleaseJar
115+
archives androidSourcesJar
116+
archives androidJavadocsJar
117+
}
118+
}

0 commit comments

Comments
 (0)