From 405050e3f58b091148dec672c5603ec1165fbc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ga=C5=82uszka?= Date: Sun, 12 Jul 2020 14:37:35 +0200 Subject: [PATCH] feat: Migrate to RxJava 3 and RxBinding 4 (#326) --- build.gradle | 12 +++---- gradle/wrapper/gradle-wrapper.properties | 4 +-- lib/build.gradle | 4 +-- lib/src/main/AndroidManifest.xml | 2 +- .../Permission.java | 10 +++--- .../RxPermissions.java | 12 +++---- .../RxPermissionsFragment.java | 5 +-- .../RxPermissionsTest.java | 36 +++---------------- sample/build.gradle | 7 +++- sample/src/main/AndroidManifest.xml | 4 +-- .../sample/MainActivity.java | 15 ++++---- .../sample/RxPermissionsSampleTest.java | 9 +++-- 12 files changed, 50 insertions(+), 70 deletions(-) rename lib/src/main/java/com/tbruyelle/{rxpermissions2 => rxpermissions3}/Permission.java (93%) rename lib/src/main/java/com/tbruyelle/{rxpermissions2 => rxpermissions3}/RxPermissions.java (97%) rename lib/src/main/java/com/tbruyelle/{rxpermissions2 => rxpermissions3}/RxPermissionsFragment.java (97%) rename lib/src/test/java/com/tbruyelle/{rxpermissions2 => rxpermissions3}/RxPermissionsTest.java (96%) rename sample/src/main/java/com/tbruyelle/{rxpermissions2 => rxpermissions3}/sample/MainActivity.java (91%) diff --git a/build.gradle b/build.gradle index 3cff575..96ebda4 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,8 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } @@ -22,8 +22,8 @@ ext { compileSdkVersion = 29 targetSdkVersion = compileSdkVersion - rxJava = 'io.reactivex.rxjava2:rxjava:2.2.19' - junit = 'junit:junit:4.12' + rxJava = 'io.reactivex.rxjava3:rxjava:3.0.4' + junit = 'junit:junit:4.13' mockito = 'org.mockito:mockito-core:3.3.3' androidXFragment = 'androidx.fragment:fragment:1.2.5' @@ -37,9 +37,9 @@ ext { khronosOpenGLApi = "org.khronos:opengl-api:gl1.1-android-2.1_r1" bintrayRepo = 'tbruyelle' - bintrayName = 'RxPermissions2' + bintrayName = 'RxPermissions3' - publishedGroupId = 'com.tbruyelle.rxpermissions2' + publishedGroupId = 'com.tbruyelle.rxpermissions3' artifact = 'rxpermissions' libraryName = 'RxPermissions' libraryVersion = '0.9.5' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4745c9b..d73469f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 26 11:49:33 CEST 2020 +#Thu Jul 09 16:45:02 CEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip diff --git a/lib/build.gradle b/lib/build.gradle index 128274e..52cad1f 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -5,8 +5,8 @@ android { compileSdkVersion rootProject.ext.compileSdkVersion compileOptions { - sourceCompatibility 1.8 - targetCompatibility 1.8 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { minSdkVersion rootProject.ext.minSdkVersion diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml index 8772efc..5c7d790 100644 --- a/lib/src/main/AndroidManifest.xml +++ b/lib/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/lib/src/main/java/com/tbruyelle/rxpermissions2/Permission.java b/lib/src/main/java/com/tbruyelle/rxpermissions3/Permission.java similarity index 93% rename from lib/src/main/java/com/tbruyelle/rxpermissions2/Permission.java rename to lib/src/main/java/com/tbruyelle/rxpermissions3/Permission.java index 3137468..a3ae490 100644 --- a/lib/src/main/java/com/tbruyelle/rxpermissions2/Permission.java +++ b/lib/src/main/java/com/tbruyelle/rxpermissions3/Permission.java @@ -1,11 +1,11 @@ -package com.tbruyelle.rxpermissions2; +package com.tbruyelle.rxpermissions3; import java.util.List; -import io.reactivex.Observable; -import io.reactivex.functions.BiConsumer; -import io.reactivex.functions.Function; -import io.reactivex.functions.Predicate; +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.functions.BiConsumer; +import io.reactivex.rxjava3.functions.Function; +import io.reactivex.rxjava3.functions.Predicate; public class Permission { public final String name; diff --git a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissions.java b/lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissions.java similarity index 97% rename from lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissions.java rename to lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissions.java index eacf53c..fff1a96 100644 --- a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissions.java +++ b/lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissions.java @@ -12,7 +12,7 @@ * limitations under the License. */ -package com.tbruyelle.rxpermissions2; +package com.tbruyelle.rxpermissions3; import android.annotation.TargetApi; import android.app.Activity; @@ -28,11 +28,11 @@ import java.util.ArrayList; import java.util.List; -import io.reactivex.Observable; -import io.reactivex.ObservableSource; -import io.reactivex.ObservableTransformer; -import io.reactivex.functions.Function; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.core.ObservableSource; +import io.reactivex.rxjava3.core.ObservableTransformer; +import io.reactivex.rxjava3.functions.Function; +import io.reactivex.rxjava3.subjects.PublishSubject; public class RxPermissions { diff --git a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissionsFragment.java b/lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissionsFragment.java similarity index 97% rename from lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissionsFragment.java rename to lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissionsFragment.java index 4449c54..a6f5439 100644 --- a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissionsFragment.java +++ b/lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissionsFragment.java @@ -1,4 +1,4 @@ -package com.tbruyelle.rxpermissions2; +package com.tbruyelle.rxpermissions3; import android.annotation.TargetApi; import android.content.pm.PackageManager; @@ -13,7 +13,8 @@ import java.util.HashMap; import java.util.Map; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.rxjava3.subjects.PublishSubject; + public class RxPermissionsFragment extends Fragment { diff --git a/lib/src/test/java/com/tbruyelle/rxpermissions2/RxPermissionsTest.java b/lib/src/test/java/com/tbruyelle/rxpermissions3/RxPermissionsTest.java similarity index 96% rename from lib/src/test/java/com/tbruyelle/rxpermissions2/RxPermissionsTest.java rename to lib/src/test/java/com/tbruyelle/rxpermissions3/RxPermissionsTest.java index 0128863..1ddad4f 100644 --- a/lib/src/test/java/com/tbruyelle/rxpermissions2/RxPermissionsTest.java +++ b/lib/src/test/java/com/tbruyelle/rxpermissions3/RxPermissionsTest.java @@ -12,7 +12,7 @@ * limitations under the License. */ -package com.tbruyelle.rxpermissions2; +package com.tbruyelle.rxpermissions3; import android.Manifest; import android.annotation.TargetApi; @@ -32,9 +32,10 @@ import org.robolectric.android.controller.ActivityController; import org.robolectric.annotation.Config; -import io.reactivex.Observable; -import io.reactivex.observers.TestObserver; -import io.reactivex.subjects.PublishSubject; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.observers.TestObserver; +import io.reactivex.rxjava3.subjects.PublishSubject; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -85,7 +86,6 @@ public void subscription_preM() { trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(true); } @@ -101,7 +101,6 @@ public void subscription_granted() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(true); } @@ -117,7 +116,6 @@ public void eachSubscription_granted() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, true)); } @@ -133,7 +131,6 @@ public void eachSubscriptionCombined_granted() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, true)); } @@ -147,7 +144,6 @@ public void eachSubscription_preM() { trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, true)); } @@ -161,7 +157,6 @@ public void eachSubscriptionCombined_preM() { trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, true)); } @@ -175,7 +170,6 @@ public void subscription_alreadyGranted() { trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(true); } @@ -191,7 +185,6 @@ public void subscription_denied() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(false); } @@ -207,7 +200,6 @@ public void eachSubscription_denied() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, false)); } @@ -223,7 +215,6 @@ public void eachSubscriptionCombined_denied() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, false)); } @@ -237,7 +228,6 @@ public void subscription_revoked() { trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(false); } @@ -251,7 +241,6 @@ public void eachSubscription_revoked() { trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, false)); } @@ -265,7 +254,6 @@ public void eachSubscriptionCombined_revoked() { trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(new Permission(permission, false)); } @@ -281,7 +269,6 @@ public void subscription_severalPermissions_granted() { mRxPermissions.onRequestPermissionsResult(permissions, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(true); } @@ -297,7 +284,6 @@ public void eachSubscription_severalPermissions_granted() { mRxPermissions.onRequestPermissionsResult(permissions, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], true)); } @@ -313,7 +299,6 @@ public void eachSubscriptionCombined_severalPermissions_granted() { mRxPermissions.onRequestPermissionsResult(permissions, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0] + ", " + permissions[1], true)); } @@ -329,7 +314,6 @@ public void subscription_severalPermissions_oneDenied() { mRxPermissions.onRequestPermissionsResult(permissions, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(false); } @@ -347,7 +331,6 @@ public void subscription_severalPermissions_oneRevoked() { new int[]{PackageManager.PERMISSION_GRANTED}); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValue(false); } @@ -365,7 +348,6 @@ public void eachSubscription_severalPermissions_oneAlreadyGranted() { new int[]{PackageManager.PERMISSION_GRANTED}); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], true)); ArgumentCaptor requestedPermissions = ArgumentCaptor.forClass(String[].class); verify(mRxPermissions).requestPermissionsFromFragment(requestedPermissions.capture()); @@ -387,7 +369,6 @@ public void eachSubscriptionCombined_severalPermissions_oneAlreadyGranted() { new int[]{PackageManager.PERMISSION_GRANTED}); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0] + ", " + permissions[1], true)); ArgumentCaptor requestedPermissions = ArgumentCaptor.forClass(String[].class); verify(mRxPermissions).requestPermissionsFromFragment(requestedPermissions.capture()); @@ -407,7 +388,6 @@ public void eachSubscription_severalPermissions_oneDenied() { mRxPermissions.onRequestPermissionsResult(permissions, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], false)); } @@ -423,7 +403,6 @@ public void eachSubscriptionCombined_severalPermissions_oneDenied() { mRxPermissions.onRequestPermissionsResult(permissions, result); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0] + ", " + permissions[1], false)); } @@ -441,7 +420,6 @@ public void eachSubscription_severalPermissions_oneRevoked() { new int[]{PackageManager.PERMISSION_GRANTED}); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], false)); } @@ -459,7 +437,6 @@ public void eachSubscriptionCombined_severalPermissions_oneRevoked() { new int[]{PackageManager.PERMISSION_GRANTED}); sub.assertNoErrors(); - sub.assertTerminated(); sub.assertValues(new Permission(permissions[0] + ", " + permissions[1], false)); } @@ -477,7 +454,6 @@ public void subscription_trigger_granted() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertNotTerminated(); sub.assertValue(true); } @@ -495,7 +471,6 @@ public void eachSubscription_trigger_granted() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertNotTerminated(); sub.assertValue(new Permission(permission, true)); } @@ -513,7 +488,6 @@ public void eachSubscriptionCombined_trigger_granted() { mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result); sub.assertNoErrors(); - sub.assertNotTerminated(); sub.assertValue(new Permission(permission, true)); } diff --git a/sample/build.gradle b/sample/build.gradle index 26049eb..6193c17 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -3,6 +3,11 @@ apply plugin: 'com.android.application' android { compileSdkVersion rootProject.ext.compileSdkVersion + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + defaultConfig { applicationId "com.tbruyelle.rxpermissions.sample" minSdkVersion 14 @@ -20,7 +25,7 @@ android { dependencies { implementation project(':rxpermissions') - implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0' + implementation 'com.jakewharton.rxbinding4:rxbinding:4.0.0' implementation rootProject.ext.androidXAppcompat testImplementation 'junit:junit:4.13' diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 738bd5a..0b39597 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ @@ -16,7 +16,7 @@ tools:ignore="GoogleAppIndexingWarning" > diff --git a/sample/src/main/java/com/tbruyelle/rxpermissions2/sample/MainActivity.java b/sample/src/main/java/com/tbruyelle/rxpermissions3/sample/MainActivity.java similarity index 91% rename from sample/src/main/java/com/tbruyelle/rxpermissions2/sample/MainActivity.java rename to sample/src/main/java/com/tbruyelle/rxpermissions3/sample/MainActivity.java index 47258f1..5f5a1de 100644 --- a/sample/src/main/java/com/tbruyelle/rxpermissions2/sample/MainActivity.java +++ b/sample/src/main/java/com/tbruyelle/rxpermissions3/sample/MainActivity.java @@ -1,4 +1,4 @@ -package com.tbruyelle.rxpermissions2.sample; +package com.tbruyelle.rxpermissions3.sample; import android.Manifest.permission; import android.hardware.Camera; @@ -9,15 +9,16 @@ import androidx.appcompat.app.AppCompatActivity; -import com.jakewharton.rxbinding2.view.RxView; -import com.tbruyelle.rxpermissions2.Permission; -import com.tbruyelle.rxpermissions2.RxPermissions; +import com.jakewharton.rxbinding4.view.RxView; +import com.tbruyelle.rxpermissions3.Permission; +import com.tbruyelle.rxpermissions3.RxPermissions; import java.io.IOException; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Action; -import io.reactivex.functions.Consumer; +import io.reactivex.rxjava3.disposables.Disposable; +import io.reactivex.rxjava3.functions.Action; +import io.reactivex.rxjava3.functions.Consumer; + public class MainActivity extends AppCompatActivity { diff --git a/sample/src/test/java/com/tbruyelle/rxpermissions/sample/RxPermissionsSampleTest.java b/sample/src/test/java/com/tbruyelle/rxpermissions/sample/RxPermissionsSampleTest.java index 885dcf2..12e41cc 100644 --- a/sample/src/test/java/com/tbruyelle/rxpermissions/sample/RxPermissionsSampleTest.java +++ b/sample/src/test/java/com/tbruyelle/rxpermissions/sample/RxPermissionsSampleTest.java @@ -5,15 +5,16 @@ import android.app.Activity; import android.os.Build; -import com.tbruyelle.rxpermissions2.Permission; -import com.tbruyelle.rxpermissions2.RxPermissions; +import com.tbruyelle.rxpermissions3.Permission; +import com.tbruyelle.rxpermissions3.RxPermissions; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import io.reactivex.Observable; + +import io.reactivex.rxjava3.core.Observable; import static org.mockito.Mockito.when; @@ -22,8 +23,6 @@ */ public class RxPermissionsSampleTest { - @Mock - private Activity activity; @Mock private RxPermissions rxPermissions;