Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to Rxjava 3.0 #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Android RxTasks

[![](https://img.shields.io/circleci/project/github/ashdavies/rx-tasks.svg)](https://circleci.com/gh/ashdavies/rx-tasks)
[![](https://img.shields.io/codacy/coverage/03ae86d9ce934421879bc407aa157732.svg)](https://app.codacy.com/project/ash.davies/rx-tasks/dashboard)
[![](https://img.shields.io/maven-central/v/io.ashdavies.rx.rxtasks/rx-tasks.svg)](https://search.maven.org/artifact/io.ashdavies.rx.rxtasks/rx-tasks)
Expand All @@ -8,8 +7,9 @@
[![](https://img.shields.io/codacy/grade/03ae86d9ce934421879bc407aa157732.svg)](https://app.codacy.com/project/ash.davies/rx-tasks/dashboard)
[![](https://img.shields.io/github/last-commit/ashdavies/rx-tasks.svg)](https://github.com/ashdavies/rx-tasks/commits/master)
[![](https://img.shields.io/github/issues-pr/ashdavies/rx-tasks.svg)](https://github.com/ashdavies/rx-tasks/pulls)
### This is a fork of https://github.com/ashdavies/rx-tasks that add support for rxjava3

**Simple and lightweight RxJava2 conversion for the [Google Tasks APIs](https://developers.google.com/android/guides/tasks)**
**Simple and lightweight RxJava3 conversion for the [Google Tasks APIs](https://developers.google.com/android/guides/tasks)**

## The Tasks API
> Starting with Google Play services version 9.0.0, you can use a `Task` API and a number of methods that return `Task` or its subclasses. `Task` is an API that represents asynchronous method calls, similar to `PendingResult` in previous versions of Google Play Services.
Expand Down
23 changes: 12 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-alpha07'
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
}

repositories {
Expand All @@ -16,11 +16,11 @@ apply plugin: 'com.android.library'
//apply plugin: 'jacoco-android'
apply plugin: 'kotlin-android'

apply from: file('gradle/git-release-notes.gradle')
apply from: file('gradle/gradle-mvn-push.gradle')
//apply from: file('gradle/git-release-notes.gradle')
//apply from: file('gradle/gradle-mvn-push.gradle')

android {
compileSdkVersion 28
compileSdkVersion 31

defaultConfig {
compileOptions {
Expand All @@ -29,7 +29,7 @@ android {
}

minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 31
}

sourceSets {
Expand All @@ -42,17 +42,18 @@ repositories {
google()
jcenter()
}
ext.kotlin_version = "1.5.31"

dependencies {
implementation 'com.google.android.gms:play-services-tasks:16.0.1'
implementation 'org.jetbrains.kotlin:kotlin-scripting-jvm:1.3.11'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.10'
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
implementation 'org.jetbrains.kotlin:kotlin-scripting-jvm:1.6.10'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

testImplementation 'junit:junit:4.12'
testImplementation 'com.google.truth:truth:0.34'

testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation 'org.mockito:mockito-core:4.0.0'
testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.6.0'
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=ashdavies
POM_DEVELOPER_NAME=Ash Davies

android.useAndroidX = true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.ashdavies.rx.rxtasks

import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import io.reactivex.CompletableEmitter
import io.reactivex.rxjava3.core.CompletableEmitter

internal class CompletableEmitterListener(private val emitter: CompletableEmitter) : OnCompleteListener<Void> {
override fun onComplete(task: Task<Void>) = try {
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/io/ashdavies/rx/rxtasks/CompletableTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package io.ashdavies.rx.rxtasks

import android.app.Activity
import com.google.android.gms.tasks.Task
import io.reactivex.Completable
import io.reactivex.CompletableEmitter
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.CompletableEmitter

import java.util.concurrent.Executor

fun Task<Void>.toCompletable(): Completable = asCompletable { addOnCompleteListener(CompletableEmitterListener(it)) }
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/io/ashdavies/rx/rxtasks/RxTasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
package io.ashdavies.rx.rxtasks

import com.google.android.gms.tasks.Task
import io.reactivex.Completable
import io.reactivex.Single

import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Single

@Deprecated(
message = "Use Task<Void>.toCompletable() instead",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.ashdavies.rx.rxtasks

import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import io.reactivex.SingleEmitter
import io.reactivex.rxjava3.core.SingleEmitter

internal class SingleEmitterListener<T : Any>(private val emitter: SingleEmitter<T>) : OnCompleteListener<T> {
override fun onComplete(task: Task<T>) = try {
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/io/ashdavies/rx/rxtasks/SingleTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package io.ashdavies.rx.rxtasks

import android.app.Activity
import com.google.android.gms.tasks.Task
import io.reactivex.Single
import io.reactivex.SingleEmitter

import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.core.SingleEmitter
import java.util.concurrent.Executor

fun <T : Any> Task<T>.toSingle(): Single<T> = asSingle { addOnCompleteListener(SingleEmitterListener(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.android.gms.tasks.Tasks
import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.then
import io.reactivex.CompletableEmitter
import io.reactivex.rxjava3.core.CompletableEmitter
import org.junit.Test
import java.util.concurrent.CancellationException

Expand All @@ -15,7 +15,7 @@ internal class CompletableEmitterListenerTest {

@Test
fun `should represent result as completion`() {
listener.onComplete(Tasks.forResult<Void>(null))
listener.onComplete(Tasks.forResult(null))

then(emitter)
.should()
Expand All @@ -24,7 +24,7 @@ internal class CompletableEmitterListenerTest {

@Test
fun `should represent cancelled as error`() {
listener.onComplete(Tasks.forCanceled<Void>())
listener.onComplete(Tasks.forCanceled())

then(emitter)
.should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.android.gms.tasks.Tasks
import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.then
import io.reactivex.SingleEmitter
import io.reactivex.rxjava3.core.SingleEmitter
import org.junit.Test
import java.util.concurrent.CancellationException

Expand Down