Skip to content

Commit

Permalink
Update 2.x branch to 0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaarman committed Dec 16, 2016
1 parent 526135f commit efe0a4c
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 278 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ language: android
android:
components:
- tools
- build-tools-24.0.3
- android-24
- build-tools-25.0.0
- android-25
- extra-android-m2repository

jdk: oraclejdk8
Expand Down
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}
dependencies {
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.8.0@aar'
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.9.1@aar'
}
```

Expand All @@ -26,17 +26,32 @@ Thanks to @vanniktech, RxPermissions now supports RxJava2, just change the packa

```gradle
dependencies {
compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.8.1@aar'
compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.1@aar'
}
```

## Migration to 0.9

Version 0.9 now uses a retained fragment to trigger the permission request from the framework. As a result, the `RxPermissions` class is no more a singleton.
To migrate from 0.8 or earlier, just replace the following :

```java
RxPermissions.getInstance(this) -> new RxPermissions(this) // where this is an Activity instance
```

## Usage

Example (with Retrolambda for brevity, but not required):
Create a `RxPermissions` instance :

```java
RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity instance
```

Example : request the CAMERA permission (with Retrolambda for brevity, but not required)

```java
// Must be done during an initialization phase like onCreate
RxPermissions.getInstance(this)
rxPermissions
.request(Manifest.permission.CAMERA)
.subscribe(granted -> {
if (granted) { // Always true pre-M
Expand All @@ -58,7 +73,7 @@ Example :
```java
// Must be done during an initialization phase like onCreate
RxView.clicks(findViewById(R.id.enableCamera))
.compose(RxPermissions.getInstance(this).ensure(Manifest.permission.CAMERA))
.compose(rxPermissions.ensure(Manifest.permission.CAMERA))
.subscribe(granted -> {
// R.id.enableCamera has been clicked
});
Expand All @@ -67,7 +82,7 @@ RxView.clicks(findViewById(R.id.enableCamera))
If multiple permissions at the same time, the result is combined :

```java
RxPermissions.getInstance(this)
rxPermissions
.request(Manifest.permission.CAMERA,
Manifest.permission.READ_PHONE_STATE)
.subscribe(granted -> {
Expand All @@ -82,7 +97,7 @@ RxPermissions.getInstance(this)
You can also observe a detailed result with `requestEach` or `ensureEach` :

```java
RxPermissions.getInstance(this)
rxPermissions
.requestEach(Manifest.permission.CAMERA,
Manifest.permission.READ_PHONE_STATE)
.subscribe(permission -> { // will emit 2 Permission objects
Expand All @@ -102,20 +117,14 @@ Look at the `sample` app for more.
## Important read

**As mentioned above, because your app may be restarted during the permission request, the request
must be done during an initialization phase**. This may be `Activity.onCreate/onResume`, or
`View.onFinishInflate` or others.
must be done during an initialization phase**. This may be `Activity.onCreate`, or
`View.onFinishInflate`, but not *pausing* methods like `onResume`, because you'll potentially create an infinite request loop, as your requesting activity is paused by the framework during the permission request.

If not, and if your app is restarted during the permission request (because of a configuration
change for instance), the user's answer will never be emitted to the subscriber.

You can find more details about that [here](https://github.com/tbruyelle/RxPermissions/issues/69).

## Migration to 0.6.x

Version 0.6.0 replaced the methods `request(trigger, permission...)` and `requestEach(trigger, permission...)`
by *composables* methods `ensure(permission...)` and `ensureEach(permission...)`. Read the second
example to see how to use them.

## Status

This library is still beta, so contributions are welcome.
Expand Down
20 changes: 14 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,31 @@ subprojects {
}

ext {
minSdkVersion = 9
compileSdkVersion = 24
minSdkVersion = 11
compileSdkVersion = 25
targetSdkVersion = compileSdkVersion
buildToolsVersion = '24.0.3'
buildToolsVersion = '25.0.0'

rxJava = 'io.reactivex.rxjava2:rxjava:2.0.0'
appCompat = 'com.android.support:appcompat-v7:24.1.1'
rxJava = 'io.reactivex.rxjava2:rxjava:2.0.2'
supportLibraryVersion = '25.0.0'
appCompat = "com.android.support:appcompat-v7:$supportLibraryVersion"
supportAnnotations = "com.android.support:support-annotations:$supportLibraryVersion"
junit = 'junit:junit:4.12'
mockito = 'org.mockito:mockito-core:1.10.19'

robolectricVersion = '3.1.4'
robolectric = "org.robolectric:robolectric:$robolectricVersion"
robolectricShadowsSupport = "org.robolectric:shadows-support-v4:$robolectricVersion"
// Workaround for https://github.com/robolectric/robolectric/issues/1932
khronosOpenGLApi = "org.khronos:opengl-api:gl1.1-android-2.1_r1"

bintrayRepo = 'tbruyelle'
bintrayName = 'RxPermissions2'

publishedGroupId = 'com.tbruyelle.rxpermissions2'
artifact = 'rxpermissions'
libraryName = 'RxPermissions'
libraryVersion = '0.8.1'
libraryVersion = '0.9.1'

libraryDescription = 'A wrapper for Android 6.0 permissions'

Expand Down
4 changes: 4 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ android {

dependencies {
compile rootProject.ext.rxJava
compile rootProject.ext.supportAnnotations

testCompile rootProject.ext.junit
testCompile rootProject.ext.mockito
testCompile rootProject.ext.robolectric
testCompile rootProject.ext.robolectricShadowsSupport
testCompile rootProject.ext.khronosOpenGLApi
}

apply from: 'install.gradle'
Expand Down
14 changes: 3 additions & 11 deletions lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.tbruyelle.rxpermissions2"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<manifest package="com.tbruyelle.rxpermissions">

<application />

<application>
<activity
android:name="com.tbruyelle.rxpermissions2.ShadowActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
/>
</application>
</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Permission {
}

@Override
@SuppressWarnings("SimplifiableIfStatement")
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Expand Down
Loading

0 comments on commit efe0a4c

Please sign in to comment.