Skip to content

Commit 7e61a01

Browse files
committed
Merge branch 'master' of https://github.com/pdvrieze/darwinlib
2 parents 79c7791 + 475c942 commit 7e61a01

11 files changed

+86
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/.idea/workspace.xml
88
/.idea/compiler.xml
99
/.idea/artifacts
10+
local.properties

build.gradle

+12-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ext {
3737
buildscript {
3838
ext {
3939
if (!has('androidPluginVersion')) {
40-
androidPluginVersion = '3.4.0'
40+
androidPluginVersion = '3.4.1'
4141
}
4242
if (!has('kotlin_version')) {
4343
kotlin_version = '1.3.40'
@@ -58,10 +58,6 @@ buildscript {
5858
}
5959

6060

61-
task wrapper(type: Wrapper) {
62-
gradleVersion = '4.8'
63-
}
64-
6561
android {
6662
compileSdkVersion androidTarget.toInteger()
6763

@@ -83,12 +79,21 @@ dependencies {
8379
implementation "com.android.support:support-compat:${androidCompatVersion}"
8480
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
8581

86-
api "net.devrieze:android-coroutines:0.7.990"
87-
api "net.devrieze:android-coroutines-appcompat:0.7.990"
82+
api "net.devrieze:android-coroutines-appcompat:0.7.990-SNAPSHOT"
83+
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.0"
8884
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.0"
8985
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
9086
}
9187

88+
repositories {
89+
mavenLocal()
90+
jcenter()
91+
google()
92+
maven {
93+
url "https://plugins.gradle.org/m2/"
94+
}
95+
}
96+
9297

9398
repositories {
9499
jcenter()

gradle/wrapper/gradle-wrapper.jar

-561 Bytes
Binary file not shown.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env sh
22

3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
##############################################################################
420
##
521
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
2844
APP_BASE_NAME=`basename "$0"`
2945

3046
# 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=""
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
3248

3349
# Use the maximum available, or set MAX_FD != -1 to use that value.
3450
MAX_FD="maximum"

gradlew.bat

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem http://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
117
@if "%DEBUG%" == "" @echo off
218
@rem ##########################################################################
319
@rem
@@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
1430
set APP_HOME=%DIRNAME%
1531

1632
@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=
33+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
1834

1935
@rem Find java.exe
2036
if defined JAVA_HOME goto findJavaFromJavaHome

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name="darwinlib"

src/main/java/nl/adaptivity/android/darwin/AuthenticatedWebClient.kt

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.accounts.Account
2020
import android.app.Activity
2121
import android.content.Context
2222
import android.support.annotation.CallSuper
23+
import kotlinx.coroutines.CoroutineScope
2324
import kotlinx.coroutines.Job
2425
import nl.adaptivity.android.coroutines.CoroutineActivity
2526
import nl.adaptivity.kotlin.getValue
@@ -232,11 +233,18 @@ interface AuthenticatedWebClient {
232233
@Throws(IOException::class)
233234
fun execute(context: Context, request: WebRequest): HttpURLConnection?
234235

235-
fun CoroutineActivity.execute(request: WebRequest, onSuccess: RequestSuccess) =
236-
execute(request, false, NULL_ERROR_HANDLER, onSuccess)
236+
fun <A> A.execute(
237+
request: WebRequest,
238+
onSuccess: RequestSuccess
239+
) where A : Activity, A : CoroutineScope =
240+
execute(request, false, NULL_ERROR_HANDLER, onSuccess)
237241

238-
fun CoroutineActivity.execute(request: WebRequest, onError: RequestFailure, onSuccess: RequestSuccess) =
239-
execute(request, false, onError, onSuccess)
242+
fun <A> A.execute(
243+
request: WebRequest,
244+
onError: RequestFailure,
245+
onSuccess: RequestSuccess
246+
) where A : Activity, A : CoroutineScope =
247+
execute(request, false, onError, onSuccess)
240248

241249
/**
242250
* Execute the web request. This will launch it's own worker thread so no need to worry. The
@@ -249,7 +257,7 @@ interface AuthenticatedWebClient {
249257
* @param onError Called when the request fails for some reason
250258
* @param onSuccess Called when the request was successful.
251259
*/
252-
fun CoroutineActivity.execute(request: WebRequest, currentlyInRetry: Boolean, onError: RequestFailure, onSuccess: RequestSuccess): Job
260+
fun <A> A.execute(request: WebRequest, currentlyInRetry: Boolean, onError: RequestFailure, onSuccess: RequestSuccess): Job where A : Activity, A:CoroutineScope
253261

254262
companion object {
255263
private val NULL_ERROR_HANDLER: RequestFailure = RequestFailure { }

src/main/java/nl/adaptivity/android/darwin/AuthenticatedWebClientFactory.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,19 @@ object AuthenticatedWebClientFactory {
303303
}
304304

305305
@JvmStatic
306-
fun CoroutineActivity.tryEnsureAccount(context: Activity,
306+
fun <A: CoroutineActivity> tryEnsureAccount(context: A,
307307
authBase: URI?,
308-
callback: SerializableHandler<Activity, Maybe<Account?>>): Job {
309-
return aLaunch {
308+
callback: SerializableHandler<A, Maybe<Account?>>): Job {
309+
return context.aLaunch {
310+
callback(context, ensureAccountToplevel(authBase))
311+
}
312+
}
313+
314+
@JvmStatic
315+
fun <A: CompatCoroutineActivity> tryEnsureAccount(context: A,
316+
authBase: URI?,
317+
callback: SerializableHandler<A, Maybe<Account?>>): Job {
318+
return context.aLaunch {
310319
callback(context, ensureAccountToplevel(authBase))
311320
}
312321
}

src/main/java/nl/adaptivity/android/darwin/AuthenticatedWebClientV14.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import android.content.Context
2424
import android.os.Build
2525
import android.support.annotation.WorkerThread
2626
import android.util.Log
27+
import kotlinx.coroutines.CoroutineScope
2728
import kotlinx.coroutines.Job
2829
import kotlinx.coroutines.launch
2930
import nl.adaptivity.android.coroutines.CoroutineActivity
@@ -92,7 +93,12 @@ internal class AuthenticatedWebClientV14(override val account: Account, override
9293
return null
9394
}
9495

95-
override fun CoroutineActivity.execute(request: AuthenticatedWebClient.WebRequest, currentlyInRetry: Boolean, onError: RequestFailure, onSuccess: RequestSuccess): Job {
96+
override fun <A> A.execute(
97+
request: AuthenticatedWebClient.WebRequest,
98+
currentlyInRetry: Boolean,
99+
onError: RequestFailure,
100+
onSuccess: RequestSuccess
101+
): Job where A : Activity, A : CoroutineScope {
96102
return launch {
97103
val connection = execute(this@execute, request)
98104
when {
@@ -176,4 +182,4 @@ internal class AuthenticatedWebClientV14(override val account: Account, override
176182

177183
}
178184

179-
}
185+
}

src/main/java/nl/adaptivity/android/darwin/DownloadFragment.kt

+4-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ import android.database.Cursor
2929
import android.net.Uri
3030
import android.os.Bundle
3131
import android.widget.Toast
32-
import kotlinx.coroutines.CancellationException
33-
import kotlinx.coroutines.CoroutineScope
34-
import kotlinx.coroutines.launch
35-
import kotlinx.coroutines.suspendCancellableCoroutine
32+
import kotlinx.coroutines.*
3633
import nl.adaptivity.android.coroutines.Maybe
3734
import nl.adaptivity.android.coroutines.ParcelableContinuation
3835
import nl.adaptivity.android.darwinlib.R
@@ -151,8 +148,9 @@ class DownloadFragment(): Fragment() {
151148
/**
152149
* Async version of [download] that has a callback instead of being a suspend function.
153150
*/
154-
fun CoroutineScope.download(activity: Activity, downloadUri: Uri, callback: (Maybe<Uri>) -> Unit) {
155-
launch {
151+
@Deprecated("This uses the global scope")
152+
fun download(activity: Activity, downloadUri: Uri, callback: (Maybe<Uri>) -> Unit) {
153+
GlobalScope.launch {
156154
try {
157155
download(activity, downloadUri).also { callback(Maybe.Ok(it)) }
158156
} catch (e: CancellationException) {

0 commit comments

Comments
 (0)