Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.

Commit c5da287

Browse files
committed
3.0.0-RC1
1 parent da81965 commit c5da287

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+724
-141
lines changed

README.md

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Assent is designed to make Android's runtime permissions easier and take less co
44

55
<img src="https://raw.githubusercontent.com/afollestad/assent/master/showcase2.png" width="750" />
66

7-
[ ![jCenter](https://api.bintray.com/packages/drummer-aidan/maven/assent/images/download.svg) ](https://bintray.com/drummer-aidan/maven/assent/_latestVersion)
7+
[ ![jCenter](https://api.bintray.com/packages/drummer-aidan/maven/assent%3Acore/images/download.svg) ](https://bintray.com/drummer-aidan/maven/assent%3Acore/_latestVersion)
88
[![Build Status](https://travis-ci.org/afollestad/assent.svg)](https://travis-ci.org/afollestad/assent)
99
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f1a2334c4c0349699760391bb71f763e)](https://www.codacy.com/app/drummeraidan_50/assent?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=afollestad/assent&amp;utm_campaign=Badge_Grade)
1010
[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0.html)
@@ -14,25 +14,26 @@ Assent is designed to make Android's runtime permissions easier and take less co
1414
1. [Gradle Dependency](#gradle-dependency)
1515
2. [The Basics](#the-basics)
1616
3. [Using Results](#using-results)
17-
4. [Under the Hood Extras](#under-the-hood-extras)
17+
4. [Request Debouncing](#request-debouncing)
1818
5. [Rationales](#rationales)
19+
6. [Coroutines](#coroutines)
1920

2021
---
2122

22-
## Gradle Dependency
23+
## Core
2324

2425
Add this to your module's `build.gradle` file:
2526

2627
```gradle
2728
dependencies {
2829
29-
implementation 'com.afollestad:assent:2.3.1'
30+
implementation 'com.afollestad.assent:core:3.0.0-RC1'
3031
}
3132
```
3233

3334
---
3435

35-
## The Basics
36+
### The Basics
3637

3738
Runtime permissions on Android are completely reliant on the UI the user is in. Permission requests
3839
go in and out of Activities and Fragments. This library provides its functionality as Kotlin
@@ -71,7 +72,7 @@ both.**
7172

7273
---
7374

74-
## Using Results
75+
### Using Results
7576

7677
`AssentResult` is provided in request callbacks. It has a few useful fields and methods:
7778

@@ -93,7 +94,7 @@ val permissionDenied: Boolean = result.isAllDenied(WRITE_EXTERNAL_STORAGE)
9394

9495
---
9596

96-
## Under the Hood Extras
97+
### Request Debouncing
9798

9899
If you were to do this...
99100

@@ -119,6 +120,19 @@ askForPermissions(CALL_PHONE) { _ -> }
119120

120121
## Rationales
121122

123+
[ ![jCenter](https://api.bintray.com/packages/drummer-aidan/maven/assent%3Arationales/images/download.svg) ](https://bintray.com/drummer-aidan/maven/assent%3Arationales/_latestVersion)
124+
125+
Add this to your module's `build.gradle` file:
126+
127+
```gradle
128+
dependencies {
129+
130+
implementation 'com.afollestad.assent:rationales:3.0.0-RC1'
131+
}
132+
```
133+
134+
---
135+
122136
Google recommends showing rationales for permissions when it may not be obvious to the user why
123137
you need them.
124138

@@ -142,3 +156,49 @@ askForPermissions(
142156
// Use result
143157
}
144158
```
159+
160+
---
161+
162+
## Coroutines
163+
164+
[ ![jCenter](https://api.bintray.com/packages/drummer-aidan/maven/assent%3Acoroutines/images/download.svg) ](https://bintray.com/drummer-aidan/maven/assent%3Acoroutines/_latestVersion)
165+
166+
Add this to your module's `build.gradle` file:
167+
168+
```gradle
169+
dependencies {
170+
171+
implementation 'com.afollestad.assent:coroutines:3.0.0-RC1'
172+
}
173+
```
174+
175+
---
176+
177+
Kotlin coroutines enable Assent to work without callbacks. If you do not know the basics of
178+
coroutines, you should research them first.
179+
180+
First, `awaitPermissionsResult(...)` is the coroutines equivalent to `askForPermissions(...)`:
181+
182+
```kotlin
183+
// Launch a coroutine in some scope...
184+
launch {
185+
val result: AssentResult = awaitPermissionsResult(
186+
READ_CONTACTS, WRITE_EXTERNAL_STORAGE, READ_SMS,
187+
rationaleHandler = rationaleHandler
188+
)
189+
// Use the result...
190+
}
191+
```
192+
193+
And second, `awaitPermissionsGranted(...)` is the coroutines equivalent to `runWithPermissions(...)`:
194+
195+
```kotlin
196+
// Launch a coroutine in some scope...
197+
launch {
198+
waitPermissionsGranted(
199+
READ_CONTACTS, WRITE_EXTERNAL_STORAGE, READ_SMS,
200+
rationaleHandler = rationaleHandler
201+
)
202+
// All three permissions were granted...
203+
}
204+
```

build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply from: rootProject.file("gradle/versions_plugin_config.gradle")
2-
apply from: rootProject.file("gradle/nebula_lint_config.gradle")
32

43
buildscript {
54
apply from: rootProject.file("dependencies.gradle")
@@ -13,7 +12,6 @@ buildscript {
1312
classpath deps.gradle_plugins.android
1413
classpath deps.gradle_plugins.bintray_release
1514
classpath deps.gradle_plugins.kotlin
16-
classpath deps.gradle_plugins.nebula_lint
1715
classpath deps.gradle_plugins.spotless
1816
classpath deps.gradle_plugins.versions
1917
}
@@ -29,7 +27,7 @@ allprojects {
2927
subprojects {
3028
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
3129
kotlinOptions {
32-
freeCompilerArgs += ['-module-name', project.path.replace('/', '.').replace(':', '_')]
30+
freeCompilerArgs += ['-module-name', project.path.substring(1).replace(':', '')]
3331
}
3432
}
3533
}
File renamed without changes.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
ext.module_group = "com.afollestad"
2-
ext.module_name = "assent"
1+
ext.module_group = "com.afollestad.assent"
2+
ext.module_name = "core"
33

44
apply from: rootProject.file("gradle/android_library_config.gradle")
55

66
dependencies {
7-
implementation deps.androidx.annotations
8-
implementation deps.androidx.app_compat
7+
api deps.androidx.app_compat
98

9+
compileOnly deps.androidx.annotations
1010
implementation deps.kotlin.stdlib8
11-
implementation deps.debug.timber
1211

1312
testImplementation deps.kotlin.test.mockito
1413
testImplementation deps.test.junit
14+
testImplementation deps.test.mockito_inline
1515
testImplementation deps.test.robolectric
1616
testImplementation deps.test.truth
1717
}

library/src/main/java/com/afollestad/assent/Assent.kt renamed to core/src/main/java/com/afollestad/assent/Assent.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ import android.content.Context
1919
import android.content.pm.PackageManager.PERMISSION_GRANTED
2020
import androidx.annotation.CheckResult
2121
import androidx.core.content.ContextCompat
22-
import com.afollestad.assent.internal.Assent.Companion.LOCK
2322
import com.afollestad.assent.internal.Assent.Companion.get
2423
import com.afollestad.assent.internal.PendingRequest
2524
import com.afollestad.assent.internal.PermissionFragment
2625
import com.afollestad.assent.internal.equalsPermissions
26+
import com.afollestad.assent.internal.log
2727
import com.afollestad.assent.rationale.RationaleHandler
28-
import timber.log.Timber
2928

3029
/**
3130
* Returns true if ALL given [permissions] have been granted.
@@ -44,7 +43,7 @@ internal fun <T : Any> T.startPermissionRequest(
4443
requestCode: Int = 20,
4544
rationaleHandler: RationaleHandler? = null,
4645
callback: Callback
47-
) = synchronized(LOCK) {
46+
) {
4847
log("askForPermissions(${permissions.joinToString()})")
4948

5049
if (rationaleHandler != null) {
@@ -59,7 +58,7 @@ internal fun <T : Any> T.startPermissionRequest(
5958
// Request matches permissions, append a callback
6059
log("Callback appended to existing matching request")
6160
currentRequest.callbacks.add(callback)
62-
return@synchronized
61+
return
6362
}
6463

6564
// Create a new pending request since none exist for these permissions
@@ -83,10 +82,3 @@ internal fun <T : Any> T.startPermissionRequest(
8382
get().requestQueue += newPendingRequest
8483
}
8584
}
86-
87-
internal fun Any.log(message: String) {
88-
Timber.tag("Assent-${name()}")
89-
Timber.d(message)
90-
}
91-
92-
private fun Any.name() = this::class.java.simpleName

library/src/main/java/com/afollestad/assent/AssentInActivity.kt renamed to core/src/main/java/com/afollestad/assent/AssentInActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.afollestad.assent
1919

2020
import android.app.Activity
2121
import com.afollestad.assent.internal.Assent.Companion.ensureFragment
22+
import com.afollestad.assent.internal.log
2223
import com.afollestad.assent.rationale.RationaleHandler
2324

2425
typealias Callback = (result: AssentResult) -> Unit

library/src/main/java/com/afollestad/assent/AssentInFragment.kt renamed to core/src/main/java/com/afollestad/assent/AssentInFragment.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ package com.afollestad.assent
2020
import androidx.annotation.CheckResult
2121
import androidx.fragment.app.Fragment
2222
import com.afollestad.assent.internal.Assent.Companion.ensureFragment
23+
import com.afollestad.assent.internal.log
2324
import com.afollestad.assent.rationale.RationaleHandler
2425

2526
/**
2627
* Returns true if ALL given [permissions] have been granted.
2728
*/
2829
@CheckResult fun Fragment.isAllGranted(vararg permissions: Permission) =
29-
activity?.isAllGranted(*permissions) ?: throw IllegalStateException(
30-
"Fragment's Activity is null."
31-
)
30+
activity?.isAllGranted(*permissions) ?: error("Fragment's Activity is null.")
3231

3332
/**
3433
* Performs a permission request, asking for all given [permissions], and

library/src/main/java/com/afollestad/assent/AssentResult.kt renamed to core/src/main/java/com/afollestad/assent/AssentResult.kt

File renamed without changes.

library/src/main/java/com/afollestad/assent/Permissions.kt renamed to core/src/main/java/com/afollestad/assent/Permissions.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ enum class Permission(val value: String) {
4646
WRITE_CALL_LOG(Manifest.permission.WRITE_CALL_LOG),
4747
ADD_VOICEMAIL(Manifest.permission.ADD_VOICEMAIL),
4848
USE_SIP(Manifest.permission.USE_SIP),
49-
PROCESS_OUTGOING_CALLS(Manifest.permission.PROCESS_OUTGOING_CALLS),
5049

5150
BODY_SENSORS(Manifest.permission.BODY_SENSORS),
5251

@@ -59,7 +58,12 @@ enum class Permission(val value: String) {
5958
READ_EXTERNAL_STORAGE(Manifest.permission.READ_EXTERNAL_STORAGE),
6059
WRITE_EXTERNAL_STORAGE(Manifest.permission.WRITE_EXTERNAL_STORAGE),
6160

62-
SYSTEM_ALERT_WINDOW(Manifest.permission.SYSTEM_ALERT_WINDOW);
61+
SYSTEM_ALERT_WINDOW(Manifest.permission.SYSTEM_ALERT_WINDOW),
62+
63+
/** @deprecated */
64+
@Suppress("DEPRECATION")
65+
@Deprecated("Manifest.permission.PROCESS_OUTGOING_CALLS is deprecated.")
66+
PROCESS_OUTGOING_CALLS(Manifest.permission.PROCESS_OUTGOING_CALLS);
6367

6468
companion object {
6569
@JvmStatic fun parse(raw: String): Permission {

0 commit comments

Comments
 (0)