From 3d4648e38915d7d0ea59d9f770e45582ca7da947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ga=C5=82uszka?= Date: Thu, 9 Jul 2020 09:04:15 +0200 Subject: [PATCH] feat: Migrate to Jetpack (AndroidX) (#325) --- .travis.yml | 9 ++++-- README.md | 2 +- build.gradle | 20 ++++++------- gradle.properties | 3 ++ gradle/wrapper/gradle-wrapper.properties | 4 +-- lib/build.gradle | 14 +++++---- .../rxpermissions2/RxPermissions.java | 13 +++++---- .../rxpermissions2/RxPermissionsFragment.java | 11 +++---- .../rxpermissions2/RxPermissionsTest.java | 29 ++++++++++--------- sample/build.gradle | 6 ++-- .../rxpermissions2/sample/MainActivity.java | 3 +- 11 files changed, 65 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index e03c655..e263c4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: android +dist: trusty android: components: - tools - - build-tools-27.0.3 - - android-27 + - build-tools-29.0.3 + - android-29 - extra-android-m2repository jdk: oraclejdk8 @@ -14,6 +15,10 @@ notifications: sudo: false +before_script: +- mkdir "$ANDROID_HOME/licenses" || true +- echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" + cache: directories: - $HOME/.gradle diff --git a/README.md b/README.md index fe64bf5..a679d03 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This library allows the usage of RxJava with the new Android M permission model. ## Setup -To use this library your `minSdkVersion` must be >= 11. +To use this library your `minSdkVersion` must be >= 14. ```gradle allprojects { diff --git a/build.gradle b/build.gradle index 2fe4a44..3cff575 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + 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' } @@ -18,19 +18,19 @@ allprojects { } ext { - minSdkVersion = 11 - compileSdkVersion = 27 + minSdkVersion = 14 + compileSdkVersion = 29 targetSdkVersion = compileSdkVersion - rxJava = 'io.reactivex.rxjava2:rxjava:2.1.16' - supportLibraryVersion = '27.1.1' - appCompat = "com.android.support:appcompat-v7:$supportLibraryVersion" - supportAnnotations = "com.android.support:support-annotations:$supportLibraryVersion" - supportFragment = "com.android.support:support-fragment:$supportLibraryVersion" + rxJava = 'io.reactivex.rxjava2:rxjava:2.2.19' junit = 'junit:junit:4.12' - mockito = 'org.mockito:mockito-core:1.10.19' + mockito = 'org.mockito:mockito-core:3.3.3' - robolectricVersion = '3.3.2' + androidXFragment = 'androidx.fragment:fragment:1.2.5' + androidXAnnotation = 'androidx.annotation:annotation:1.1.0' + androidXAppcompat = 'androidx.appcompat:appcompat:1.1.0' + + robolectricVersion = '4.3.1' robolectric = "org.robolectric:robolectric:$robolectricVersion" robolectricShadowsSupport = "org.robolectric:shadows-support-v4:$robolectricVersion" // Workaround for https://github.com/robolectric/robolectric/issues/1932 diff --git a/gradle.properties b/gradle.properties index aac7c9b..cc04374 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,3 +15,6 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +android.useAndroidX = true +android.enableJetifier=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6758c39..4745c9b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jun 28 09:30:08 CDT 2018 +#Fri Jun 26 11:49:33 CEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/lib/build.gradle b/lib/build.gradle index 20d896c..128274e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -4,6 +4,10 @@ apply from: 'jitpack.gradle' android { compileSdkVersion rootProject.ext.compileSdkVersion + compileOptions { + sourceCompatibility 1.8 + targetCompatibility 1.8 + } defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion @@ -14,7 +18,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - + testOptions.unitTests.includeAndroidResources = true testOptions.unitTests.all { // unitTests.returnDefaultValues = true // Always show the result of every unit test, even if it passes. @@ -26,13 +30,13 @@ android { dependencies { implementation rootProject.ext.rxJava - implementation rootProject.ext.supportAnnotations - implementation rootProject.ext.supportFragment + implementation rootProject.ext.androidXFragment + implementation rootProject.ext.androidXAnnotation + implementation rootProject.ext.androidXAppcompat - testImplementation rootProject.ext.junit + testImplementation 'junit:junit:4.13' testImplementation rootProject.ext.mockito testImplementation rootProject.ext.robolectric - testImplementation rootProject.ext.robolectricShadowsSupport testImplementation rootProject.ext.khronosOpenGLApi } diff --git a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissions.java b/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissions.java index c1a50ee..eacf53c 100644 --- a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissions.java +++ b/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissions.java @@ -17,13 +17,14 @@ import android.annotation.TargetApi; import android.app.Activity; import android.os.Build; -import android.support.annotation.NonNull; -import android.support.annotation.VisibleForTesting; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentManager; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + import java.util.ArrayList; import java.util.List; @@ -322,7 +323,7 @@ boolean isMarshmallow() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; } - void onRequestPermissionsResult(String permissions[], int[] grantResults) { + void onRequestPermissionsResult(String[] permissions, int[] grantResults) { mRxPermissionsFragment.get().onRequestPermissionsResult(permissions, grantResults, new boolean[permissions.length]); } diff --git a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissionsFragment.java b/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissionsFragment.java index 4c927c4..4449c54 100644 --- a/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissionsFragment.java +++ b/lib/src/main/java/com/tbruyelle/rxpermissions2/RxPermissionsFragment.java @@ -4,11 +4,12 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; import android.util.Log; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; + import java.util.HashMap; import java.util.Map; @@ -38,7 +39,7 @@ void requestPermissions(@NonNull String[] permissions) { } @TargetApi(Build.VERSION_CODES.M) - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode != PERMISSIONS_REQUEST_CODE) return; @@ -52,7 +53,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String permissi onRequestPermissionsResult(permissions, grantResults, shouldShowRequestPermissionRationale); } - void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) { + void onRequestPermissionsResult(String[] permissions, int[] grantResults, boolean[] shouldShowRequestPermissionRationale) { for (int i = 0, size = permissions.length; i < size; i++) { log("onRequestPermissionsResult " + permissions[i]); // Find the corresponding subject diff --git a/lib/src/test/java/com/tbruyelle/rxpermissions2/RxPermissionsTest.java b/lib/src/test/java/com/tbruyelle/rxpermissions2/RxPermissionsTest.java index 89d2262..0128863 100644 --- a/lib/src/test/java/com/tbruyelle/rxpermissions2/RxPermissionsTest.java +++ b/lib/src/test/java/com/tbruyelle/rxpermissions2/RxPermissionsTest.java @@ -19,13 +19,14 @@ import android.app.Activity; import android.content.pm.PackageManager; import android.os.Build; -import android.support.v4.app.FragmentActivity; + +import androidx.fragment.app.FragmentActivity; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.android.controller.ActivityController; @@ -48,7 +49,7 @@ import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) -@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.M) +@Config(sdk = Build.VERSION_CODES.M) public class RxPermissionsTest { private FragmentActivity mActivity; @@ -273,7 +274,7 @@ public void eachSubscriptionCombined_revoked() { public void subscription_severalPermissions_granted() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_GRANTED}; trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub); @@ -289,7 +290,7 @@ public void subscription_severalPermissions_granted() { public void eachSubscription_severalPermissions_granted() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_GRANTED}; trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub); @@ -305,7 +306,7 @@ public void eachSubscription_severalPermissions_granted() { public void eachSubscriptionCombined_severalPermissions_granted() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_GRANTED}; trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub); @@ -321,7 +322,7 @@ public void eachSubscriptionCombined_severalPermissions_granted() { public void subscription_severalPermissions_oneDenied() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED}; trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub); @@ -337,7 +338,7 @@ public void subscription_severalPermissions_oneDenied() { public void subscription_severalPermissions_oneRevoked() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true); trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub); @@ -355,7 +356,7 @@ public void subscription_severalPermissions_oneRevoked() { public void eachSubscription_severalPermissions_oneAlreadyGranted() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); when(mRxPermissions.isGranted(Manifest.permission.CAMERA)).thenReturn(true); trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub); @@ -377,7 +378,7 @@ public void eachSubscription_severalPermissions_oneAlreadyGranted() { public void eachSubscriptionCombined_severalPermissions_oneAlreadyGranted() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); when(mRxPermissions.isGranted(Manifest.permission.CAMERA)).thenReturn(true); trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub); @@ -399,7 +400,7 @@ public void eachSubscriptionCombined_severalPermissions_oneAlreadyGranted() { public void eachSubscription_severalPermissions_oneDenied() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED}; trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub); @@ -415,7 +416,7 @@ public void eachSubscription_severalPermissions_oneDenied() { public void eachSubscriptionCombined_severalPermissions_oneDenied() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED}; trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub); @@ -431,7 +432,7 @@ public void eachSubscriptionCombined_severalPermissions_oneDenied() { public void eachSubscription_severalPermissions_oneRevoked() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true); trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub); @@ -449,7 +450,7 @@ public void eachSubscription_severalPermissions_oneRevoked() { public void eachSubscriptionCombined_severalPermissions_oneRevoked() { TestObserver sub = new TestObserver<>(); String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - when(mRxPermissions.isGranted(Matchers.anyVararg())).thenReturn(false); + when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false); when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true); trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub); diff --git a/sample/build.gradle b/sample/build.gradle index 7eb3366..26049eb 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -20,9 +20,9 @@ android { dependencies { implementation project(':rxpermissions') - implementation rootProject.ext.appCompat - implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1' + implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0' + implementation rootProject.ext.androidXAppcompat - testImplementation rootProject.ext.junit + testImplementation 'junit:junit:4.13' testImplementation rootProject.ext.mockito } diff --git a/sample/src/main/java/com/tbruyelle/rxpermissions2/sample/MainActivity.java b/sample/src/main/java/com/tbruyelle/rxpermissions2/sample/MainActivity.java index 7aaaeca..47258f1 100644 --- a/sample/src/main/java/com/tbruyelle/rxpermissions2/sample/MainActivity.java +++ b/sample/src/main/java/com/tbruyelle/rxpermissions2/sample/MainActivity.java @@ -3,11 +3,12 @@ import android.Manifest.permission; import android.hardware.Camera; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.SurfaceView; import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; + import com.jakewharton.rxbinding2.view.RxView; import com.tbruyelle.rxpermissions2.Permission; import com.tbruyelle.rxpermissions2.RxPermissions;