From d5658b423dbe760cca7cfb43d2e4b9ed66ee6480 Mon Sep 17 00:00:00 2001 From: marcelpinto Date: Sat, 9 Jan 2021 17:19:46 +0800 Subject: [PATCH] Clean up docs and gradle files --- README.md | 13 +++++++++---- app/build.gradle.kts | 3 ++- .../permissionktx/advance/AdvanceViewModelTest.kt | 10 ++++------ build.gradle.kts | 2 +- lib/build.gradle.kts | 1 + lib/consumer-rules.pro | 1 + 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1c5a30c..2eb847d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ permission acceptance rate. ## How to include in your project -Add custom maven url repository (publishing to JCentral is in progress) +The library is available via JCentral: ```groovy allprojects { @@ -49,6 +49,8 @@ allprojects { } ``` +Add it to your module dependencies: + ```groovy dependencies { implementation 'dev.marcelpinto.permissions:permissions-ktx:0.4' @@ -119,8 +121,9 @@ locationPermissionRequest.safeLaunch( ``` > Note: only ``onRequireRational`` lambda is required. -For an example of this check the [Simple sample](app/src/main/java/dev/marcelpinto/permissionktx/simple/SimpleFragment.kt) +Check the [Simple sample](app/src/main/java/dev/marcelpinto/permissionktx/simple/SimpleFragment.kt) or the [Compose Sample](app/src/main/java/dev/marcelpinto/permissionktx/compose) +for more. ### via launch() @@ -193,6 +196,7 @@ allowing the test to control the status of the permission without Android depend ```kotlin // Using a StateFlow to change the values provided by the Observer and Checker +// You could use other mechanisms or directly a simple variable private var permissionStatus = MutableStateFlow( Permission.Status.Revoked( name = Manifest.permission.ACCESS_FINE_LOCATION, @@ -231,11 +235,12 @@ fun test() { To allow control of the permission flow without having to grant/revoke Android permissions the library provides an overload of the Permission.Init method that allows to provide custom implementation for Checker, Observer and the ActivityResultRegistry to use -when launching the permission request. +when launching the permission request +(see [Testing ActivityResult](https://developer.android.com/training/basics/intents/result#test)). This allow full control and customization of the Permission status and permission request results, allowing to fully test the permission flow -without interacting with the Android System. +without interacting with the Android framework. ```kotlin private var permissionStatus: Permission.Status = Permission.Status.Revoked( diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a3566f9..6f0610a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -61,7 +61,8 @@ android { dependencies { implementation(kotlin("stdlib", KotlinCompilerVersion.VERSION)) - implementation(project(":lib")) + //implementation(project(":lib")) + implementation("dev.marcelpinto.permissions:permissions-ktx:0.4") implementation("androidx.core:core-ktx:1.3.2") implementation("androidx.appcompat:appcompat:1.2.0") diff --git a/app/src/test/java/dev/marcelpinto/permissionktx/advance/AdvanceViewModelTest.kt b/app/src/test/java/dev/marcelpinto/permissionktx/advance/AdvanceViewModelTest.kt index 09e2d7f..a971035 100644 --- a/app/src/test/java/dev/marcelpinto/permissionktx/advance/AdvanceViewModelTest.kt +++ b/app/src/test/java/dev/marcelpinto/permissionktx/advance/AdvanceViewModelTest.kt @@ -100,11 +100,9 @@ class AdvanceViewModelTest { @Test fun testGivenPermissionRevokedWithRationalWhenLocationClickThenShowRational() = testScope.runBlockingTest { - permissionStatus.emit( - Permission.Status.Revoked( - permissionStatus.value.name, - Permission.Rational.REQUIRED - ) + permissionStatus.value = Permission.Status.Revoked( + permissionStatus.value.name, + Permission.Rational.REQUIRED ) val target = AdvanceViewModel(locationFlow) @@ -123,7 +121,7 @@ class AdvanceViewModelTest { val target = AdvanceViewModel(locationFlow) target.onLocationClick() - permissionStatus.emit(Permission.Status.Granted(permissionStatus.value.name)) + permissionStatus.value = Permission.Status.Granted(permissionStatus.value.name) target.getViewData().value!!.run { assertThat(location).isEqualTo(actualFlow.value) diff --git a/build.gradle.kts b/build.gradle.kts index 7c505a7..0cee5a4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath("com.android.tools.build:gradle:7.0.0-alpha03") + classpath("com.android.tools.build:gradle:7.0.0-alpha04") classpath(kotlin("gradle-plugin", version = "1.4.21")) } } diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 23972c5..e8503cb 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -6,6 +6,7 @@ plugins { id("com.android.library") kotlin("android") id("org.jetbrains.dokka") version "1.4.20" + id("com.jfrog.bintray") version "1.8.5" `maven-publish` id("com.jfrog.bintray") version "1.8.5" } diff --git a/lib/consumer-rules.pro b/lib/consumer-rules.pro index e69de29..7bc6b6e 100644 --- a/lib/consumer-rules.pro +++ b/lib/consumer-rules.pro @@ -0,0 +1 @@ +-keep class dev.marcelpinto.permissionktx.Permission$PermissionInitializer \ No newline at end of file