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

Commit

Permalink
Release 3.0.0-RC3
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed Jan 21, 2020
1 parent 59fde1d commit f2dbfbe
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Add this to your module's `build.gradle` file:
```gradle
dependencies {
implementation 'com.afollestad.assent:core:3.0.0-RC2'
implementation 'com.afollestad.assent:core:3.0.0-RC3'
}
```

Expand Down Expand Up @@ -155,7 +155,7 @@ Add this to your module's `build.gradle` file:
```gradle
dependencies {
implementation 'com.afollestad.assent:rationales:3.0.0-RC2'
implementation 'com.afollestad.assent:rationales:3.0.0-RC3'
}
```

Expand Down Expand Up @@ -196,7 +196,7 @@ Add this to your module's `build.gradle` file:
```gradle
dependencies {
implementation 'com.afollestad.assent:coroutines:3.0.0-RC2'
implementation 'com.afollestad.assent:coroutines:3.0.0-RC3'
}
```

Expand Down
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
3.0.0-RC3

* Quick fix-up around permanently denied detection! No longer reliant on rationale handler either.
* Added more methods to `AssentResult` to get granted, denied, and permanently denied permissions.
* More internal cleanup.

---

3.0.0-RC2

* Detect permanently denied permissions! Changes to `AssentResult`'s structure, it also allows you
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/afollestad/assent/AssentResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AssentResult(
}

override fun toString(): String {
return resultsMap.entries.joinToString(separator = ", ") { "${it.key}=>${it.value}" }
return resultsMap.entries.joinToString(separator = ", ") { "${it.key} -> ${it.value}" }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ internal fun Fragment.onPermissionsResponse(
permissions: Array<out String>,
grantResults: IntArray
) {
val prefs = RealPrefs(context!!)
val shouldShowRationale = RealShouldShowRationale(activity!!, prefs)
val activity = activity ?: error("Fragment is not attached: $this")
val prefs = RealPrefs(activity)
val shouldShowRationale = RealShouldShowRationale(activity, prefs)
val result = AssentResult(
permissions = permissions.toPermissions(),
grantResults = grantResults,
Expand Down
29 changes: 23 additions & 6 deletions core/src/test/java/com/afollestad/assent/ActivitiesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.afollestad.assent

import android.content.pm.PackageManager
import android.content.SharedPreferences
import android.content.pm.PackageManager.PERMISSION_DENIED
import android.content.pm.PackageManager.PERMISSION_GRANTED
import androidx.fragment.app.FragmentActivity
Expand All @@ -39,6 +39,7 @@ import com.nhaarman.mockitokotlin2.atLeastOnce
import com.nhaarman.mockitokotlin2.doAnswer
import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.isA
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
Expand All @@ -57,28 +58,44 @@ class ActivitiesTest {
on { beginTransaction() } doReturn fragmentTransaction
}

private val permissionFragment = mock<PermissionFragment>()
private val responseQueue = MockResponseQueue(allowedPermissions, permissionFragment)

private val sharedPrefsEditor = mock<SharedPreferences.Editor>()
private val sharedPrefs = mock<SharedPreferences> {
on { edit() } doReturn sharedPrefsEditor
}
private val activity = mock<FragmentActivity> {
on { getSharedPreferences(any(), any()) } doReturn sharedPrefs
// FRAGMENT TRANSACTIONS
on { supportFragmentManager } doReturn fragmentManager
// CHECK PERMISSION
on { checkPermission(any(), eq(0), any()) } doAnswer { inv ->
val checkPermission = inv.getArgument<String>(0)
val parsedCheckPermission = Permission.parse(checkPermission)
return@doAnswer if (allowedPermissions.contains(parsedCheckPermission)) {
PackageManager.PERMISSION_GRANTED
PERMISSION_GRANTED
} else {
PackageManager.PERMISSION_DENIED
PERMISSION_DENIED
}
}
}

private val permissionFragment = mock<PermissionFragment> {
on { activity } doReturn activity
on { isAdded } doReturn true
}
private val responseQueue = MockResponseQueue(allowedPermissions, permissionFragment)

@Before fun setup() {
allowedPermissions.clear()
Assent.fragmentCreator = { permissionFragment }

doAnswer { invocation ->
val key: String = invocation.getArgument(0)
val value: Boolean = invocation.getArgument(1)
whenever(sharedPrefs.getBoolean(key, any()))
.doReturn(value)
}.whenever(sharedPrefsEditor)
.putBoolean(isA(), any())

whenever(permissionFragment.perform(any())).thenCallRealMethod()
whenever(
permissionFragment.onRequestPermissionsResult(any(), any(), any())
Expand Down
25 changes: 22 additions & 3 deletions core/src/test/java/com/afollestad/assent/FragmentsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.afollestad.assent

import android.content.SharedPreferences
import android.content.pm.PackageManager.PERMISSION_DENIED
import android.content.pm.PackageManager.PERMISSION_GRANTED
import androidx.fragment.app.Fragment
Expand All @@ -36,6 +37,7 @@ import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.doAnswer
import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.isA
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
Expand All @@ -54,10 +56,12 @@ class FragmentsTest {
on { beginTransaction() } doReturn fragmentTransaction
}

private val permissionFragment = mock<PermissionFragment>()
private val responseQueue = MockResponseQueue(allowedPermissions, permissionFragment)

private val sharedPrefsEditor = mock<SharedPreferences.Editor>()
private val sharedPrefs = mock<SharedPreferences> {
on { edit() } doReturn sharedPrefsEditor
}
private val activity = mock<FragmentActivity> {
on { getSharedPreferences(any(), any()) } doReturn sharedPrefs
// FRAGMENT TRANSACTIONS
on { supportFragmentManager } doReturn fragmentManager
// CHECK PERMISSION
Expand All @@ -75,12 +79,27 @@ class FragmentsTest {
on { fragmentManager } doReturn fragmentManager
on { childFragmentManager } doReturn fragmentManager
on { activity } doReturn activity
on { isAdded } doReturn true
}

private val permissionFragment = mock<PermissionFragment> {
on { activity } doReturn activity
on { isAdded } doReturn true
}
private val responseQueue = MockResponseQueue(allowedPermissions, permissionFragment)

@Before fun setup() {
allowedPermissions.clear()
Assent.fragmentCreator = { permissionFragment }

doAnswer { invocation ->
val key: String = invocation.getArgument(0)
val value: Boolean = invocation.getArgument(1)
whenever(sharedPrefs.getBoolean(key, any()))
.doReturn(value)
}.whenever(sharedPrefsEditor)
.putBoolean(isA(), any())

whenever(permissionFragment.perform(any())).thenCallRealMethod()
whenever(
permissionFragment.onRequestPermissionsResult(any(), any(), any())
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ ext.versions = [
min_sdk: 14,
compile_sdk: 29,
build_tools: "29.0.0",
publish_version: "3.0.0-RC2",
publish_version_code: 22
publish_version: "3.0.0-RC3",
publish_version_code: 23
]

ext.deps = [
Expand Down

0 comments on commit f2dbfbe

Please sign in to comment.