Skip to content
This repository has been archived by the owner on Jun 16, 2019. It is now read-only.

Commit

Permalink
4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed May 27, 2018
1 parent dae2e93 commit cc83c4e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add this to your module's `build.gradle` file (make sure the version matches the
```gradle
dependencies {
compile 'com.afollestad:icon-request:4.0.0'
compile 'com.afollestad:icon-request:4.0.1'
}
```

Expand Down Expand Up @@ -165,7 +165,13 @@ You can pass an `apiHost` and `apiKey` to integrate with [Arctic Request Manager
With a configured `ArcticRequest` instance, you can load unthemed apps:

```kotlin
// Rely on only the onLoad and onLoadError callbacks passed into ArcticRequest(...).
// If onLoadError isn't set, an error will result in a thrown RuntimeException.
request.performLoad()

// You will still receive onLoad and onLoadError notifications, but the result is also passed
// into the parameterized lambda.
request.performLoad { list, throwable -> }
```

Your `onLoaded` callback will receive a List of unthemed apps. If an error occurs,
Expand Down Expand Up @@ -210,7 +216,13 @@ filtered list based off the list of all loaded apps.
Once you've selected apps, you can send a request:

```kotlin
// Rely on only the onSent and onSendError callbacks passed into ArcticRequest(...).
// If onSendError isn't set, an error will result in a thrown RuntimeException.
request.performSend()

// You will still receive onSent and onSendError notifications, but the result is also passed
// into the parameterized lambda.
request.performSend { count, throwable -> }
```

Your `onSent` callback will be invoked if all is well; your `onSendError` callback
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext.versions = [
minSdk : 14,
compileSdk : 27,
publishVersion: '4.0.0',
versionCode : 4,
publishVersion: '4.0.1',
versionCode : 5,
kotlin : '1.2.41',

versionsPlugin: '0.17.0',
Expand Down
24 changes: 17 additions & 7 deletions library/src/main/java/com/afollestad/iconrequest/ArcticRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typealias VoidCallback = (() -> (Unit))?
typealias LoadedCallback = ((List<AppModel>) -> (Unit))?
typealias SentCallback = ((Int) -> (Unit))?
typealias AppCallback = ((AppModel) -> (Unit))?
typealias LoadedAndErrorCallback = ((List<AppModel>, Throwable?) -> (Unit))?
typealias SentAndErrorCallback = ((Int, Throwable?) -> (Unit))?

/** @author Aidan Follestad (afollestad) */
class ArcticRequest constructor(
Expand Down Expand Up @@ -76,7 +78,7 @@ class ArcticRequest constructor(
out.putSerializable(KEY_APPS, storedLoadedApps.toTypedArray())
}

fun performLoad() {
fun performLoad(callback: LoadedAndErrorCallback = null) {
onLoading?.invoke()
disposables += Observable.just(true)
.flatMap {
Expand All @@ -93,10 +95,15 @@ class ArcticRequest constructor(
}
.observeToMainThread()
.subscribe(
{ onLoaded?.invoke(it) },
{
if (onLoadError != null) onLoadError.invoke(it)
else throw RuntimeException(it)
onLoaded?.invoke(it)
callback?.invoke(it, null)
},
{
if (onLoadError != null || callback != null) {
onLoadError?.invoke(it)
callback?.invoke(listOf(), it)
} else throw RuntimeException(it)
}
)
}
Expand Down Expand Up @@ -201,7 +208,7 @@ class ArcticRequest constructor(
onLoaded?.invoke(storedLoadedApps)
}

fun performSend() {
fun performSend(callback: SentAndErrorCallback = null) {
onSending?.invoke()
disposables += Observable.just(true)
.map { selectedApps }
Expand All @@ -214,10 +221,13 @@ class ArcticRequest constructor(
{
resetSelection()
onSent?.invoke(it)
callback?.invoke(it, null)
},
{
if (onSendError != null) onSendError.invoke(it)
else throw RuntimeException(it)
if (onSendError != null || callback != null) {
onSendError?.invoke(it)
callback?.invoke(0, it)
} else throw RuntimeException(it)
}
)
}
Expand Down

0 comments on commit cc83c4e

Please sign in to comment.