diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index f24403c5..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.github/workflows/deploy_snapshot.yml b/.github/workflows/deploy_snapshot.yml new file mode 100644 index 00000000..d01cca05 --- /dev/null +++ b/.github/workflows/deploy_snapshot.yml @@ -0,0 +1,26 @@ +name: Deploy snapshot + +on: + pull_request: + branches: + - master + types: [closed] + +jobs: + build: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + steps: + - uses: actions/checkout@v2 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Prepare local.properties for testing + run: echo "sdk.dir=$ANDROID_HOME" > local.properties + - name: Build with Gradle + run: ./gradlew clean build + - name: Deploy snapshot + run: ./gradlew uploadArchives --no-daemon --no-parallel -PSONATYPE_NEXUS_USERNAME=${{secrets.SONATYPE_NEXUS_USERNAME}} -PSONATYPE_NEXUS_PASSWORD=${{secrets.SONATYPE_NEXUS_PASSWORD}} -Psigning.keyId=${{secrets.SIGNING_KEY_ID}} -Psigning.password=${{secrets.SIGNING_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg) diff --git a/.github/workflows/ktx-release.yml b/.github/workflows/ktx-release.yml new file mode 100644 index 00000000..11291882 --- /dev/null +++ b/.github/workflows/ktx-release.yml @@ -0,0 +1,30 @@ +name: KTX Release + +on: + push: + tags: + - 'ktx-*.*.*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Prepare local.properties for testing + run: echo "sdk.dir=$ANDROID_HOME" > local.properties + - name: Build with Gradle + run: ./gradlew clean build + - name: Decode the secret key and place the file + run: | + echo "${{secrets.SIGNING_SECRET_KEY_RING_FILE}}" > ~/.gradle/secring.gpg.b64 + base64 -d ~/.gradle/secring.gpg.b64 > ~/.gradle/secring.gpg + - name: Publish project + run: ./gradlew ktx:uploadArchives --no-daemon --no-parallel -PSONATYPE_NEXUS_USERNAME=${{secrets.SONATYPE_NEXUS_USERNAME}} -PSONATYPE_NEXUS_PASSWORD=${{secrets.SONATYPE_NEXUS_PASSWORD}} -Psigning.keyId=${{secrets.SIGNING_KEY_ID}} -Psigning.password=${{secrets.SIGNING_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg) + - name: Close the repository + run: ./gradlew closeAndReleaseRepository diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml new file mode 100644 index 00000000..7c0a4b49 --- /dev/null +++ b/.github/workflows/pull_request_ci.yml @@ -0,0 +1,21 @@ +name: CI for pull request + +on: + pull_request: + types: [assigned, opened, synchronize, reopened] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Prepare local.properties for testing + run: echo "sdk.dir=$ANDROID_HOME" > local.properties + - name: Build with Gradle + run: ./gradlew clean check --stacktrace diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..082a7e8d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Prepare local.properties for testing + run: echo "sdk.dir=$ANDROID_HOME" > local.properties + - name: Build with Gradle + run: ./gradlew clean build + - name: Decode the secret key and place the file + run: | + echo "${{secrets.SIGNING_SECRET_KEY_RING_FILE}}" > ~/.gradle/secring.gpg.b64 + base64 -d ~/.gradle/secring.gpg.b64 > ~/.gradle/secring.gpg + - name: Publish project + run: ./gradlew uploadArchives --no-daemon --no-parallel -PSONATYPE_NEXUS_USERNAME=${{secrets.SONATYPE_NEXUS_USERNAME}} -PSONATYPE_NEXUS_PASSWORD=${{secrets.SONATYPE_NEXUS_PASSWORD}} -Psigning.keyId=${{secrets.SIGNING_KEY_ID}} -Psigning.password=${{secrets.SIGNING_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg) + - name: Close the repository + run: ./gradlew closeAndReleaseRepository diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 357768eb..00000000 --- a/.travis.yml +++ /dev/null @@ -1,46 +0,0 @@ -language: android - -env: - global: - - secure: "KY2ZIqFr6RCbZvFpCGo1CXtnmvbGq+uEw/haDOeva7V86A5K+2IzzoCdBTyIcGWo4MfAlfwvtr2z/5JTLQQ9XE2h0N1oVTqJCBPTmorXDFv7CNHxortje9Ra0jrQZY69pXCJePlI9XQ4QOS2pHMujucYt7RFTV/TmU3yI+xBd6PVVTt54mRCSrIAbl5YWGK9lHUWygBn+rLspmAxamSOccqjJlmotzqFp60gedgbrcGOPhLRcuESDn8w45fP0I1owXEhvnIOlMlTavoDc+qeMLckR9xyCYFqxt0jTPaQViR0+JPm7P9Qwho4r9dBcoK+ojqg56fyqQ89sckZ22jXqjmWrKViQdCEB5Oul/n2R2fgH+OfZ1eUffaNTKRAz8a7JgwmPC+X7BiQKxY+GGeZ7tlMxlSyGQGr5EDsAypr9R7r+6WuHtlM7wfSdWNWgMY+CnViJH0f1pl5nftqBzE2PJArU4w1r5tPdkVnGzUHgDrksTGU9WRQ4q/HP+8xZkQjsY1hRuXJlXm+SvMPNyJRn1yxyu2zeetdOmnEUHVN1TgGol3k/sHCUtqF6N4cskpCTFTdXNSZPd3uZs0JLhQR4ygJ6Es+yfPM6pae8jKmUNsUJpl9ctOpwvyZYIsc3rqtLjBWN47v6S/wtOmdJhh1uxz79K7vcPh1Z3pcfGgoVUs=" - - secure: "ucfbFyzFVzzmGivT3MrH7CbW1Wjs2B2gFIc/iqsJ/jF+1vh0ki2wwmE8pFFGo/4iKF59yCnj0NtxnInX3YVRtLOKD1bqS0yAPOskLlx3XhH5gg4owJ6vo9vuKoizcRabT/ss8SjlFkv7PDHmFWVyUtZmgjkwZbuQbTnMBQv1qzDo+AfS8cuDQAXvWzfMF1R9wEpc1/hmRCYMTpUS3c0qms2wxPatLLnXHGT3qVfHsAFm46mBiwA2K7G8UwRHLQCqC0RE9/4PDvmrTSt4xdq9PsY6CGqBHJmDW8ylWW6JONzFw4g3l/9GH0uBu4iryZmZORjTCRsIWbqzFcLCF+AN+mLxIsmRnRqabxOv4QRgIRq0S5ODfOkLbrAMTRH7P4JitwSnMUrG6Rfmb5XRTg6Di0L3Wd2n4wP9n7R/2037Z7C9/nwfv5UewCn75H5DynLGA00szLLe4ws4oY0OEJQQoCkjXkNoXvPuCv6XaVTg61JgSJGMJsjxNGGrAjXJvpXgGPdqMqert/quc5kdyabU0O7H9EfLBPQ0jFMrDXZkfjGRvyshp4bhIthIw1oerQy2DDtkPsQkhRajPg2AyHo5ttGnsr7fyZ1eAol8SgvP180zqsHJj8rPwET7WN+QgPA/xBuj9CFUpoRF3QFVoxMFouimgUhwKV1nZ8uCJ4vaSSA=" - - secure: "BEOoJWIoQSp9j6XOxAIN3o7oe/RH6OePD+gGeX4PmQcqVnqYzUxVSUMknQSKzTpHlrXHPGOh2sJRCcNynSEhRryC/qEu73Z/lwgye+xnaz7YTnqo+lfVnzWDPvMTi4IuLJuL6R31ZeM9XOqvOA4k6RoxcbRp6WI4mPtrReipsq6bJwBRJlC6bnxIvrkmiRLm/E/clx1bfVVOpAMk6SELc/lBtXq20BO96J/WkUHGKmva5Pp7K8lQ+vXhCasHrmKxXrzYAvjZTnQGEZmTE5z3+2H8jQ9OBZdI13JOE+Lm+COIa+/GcEUNUsc0hReqJSJmC+7EzTWxDhxpUpjS+Pjy67Btly7cAo3U7HFTR/b00en+acAFeznsNc1tJDBWk+PQwxGyETxOfkZNcWn9RNHqZat/zIhIqbdwuu0M+IcvrZ3yRQV0UmIcnAHxU+e3+IXo9KXe3oz2Mi1VaxzH8pLftEHzDc3VXObnvFaKNSLdhIS2UdlFVX0iPfU2e7U6yKOI5z5MDzRVhgCHdMqyfAcoTOrwRePVoDk5UFxy9C2TAIIJ9xlfW4YydIbIJRahjtRe5+Jp2lH9qiBgjt6/IgiXpI4C6H+8rsfz4N7pssmymM7+0hQuSevWaJnhCt9kPdiwHzHJ3lUm/ud1WGZvQQUFH/pTQJXOYqxmDRivQlzWSWQ=" - - secure: "znN56WtufsW5EYRWCbc5sJOkuVnZw8J2nhGTGCtLwXOrQhYZvVHlxhNmwkWctBF/kJHNtxGWnq3bcsD3wOm7a/BSdZDCS+JoL0MN75QY93a2xoEoBSO4Wr0oW2s2HFc/+Ik9O8EeeH4YImYUYoQ+LVuFJ6twr+8vQDjrt7S2cndiBdX9cXnMbz5hh98rSy5NFawafp0p+lby8eKV8HjdwDkyHyZGtg2BU1s01ef45iOAXmZtvuRffASIoRTvF8qTanqv90ZUzm50Pl3UcLEx7A5tR+/hExeK1pY5RiRGjrZEWawVIyBjOuQtvjFaLlfmVnIt44fwF7luuVWI6slxyDp/RsXAazOmaaB5vVt8KlhwTUxgQ2NGFXjVaC//C9AiMnnU4ZrBF/D33VkcyHBvtTATtlLbIQliG3x119UGWAjTzJwSAIc/YgEowKK/MR/qHfRSxz+HTR73KV8DA1/yaRAhLPUY9iJ4Kmn0uVKc4WxSJpq+bPyXf4FGmc1AOt4VkSYpwsBxB8kZiqq2er1z+u2lYf2LZFhZ1rtZxvccrQurDE30LSyg2oZAI75/x7o97CLciTu342CM4c1FayRUV4CxIHwOEPenb7DfYvEyiexPDG3/DACcMGVUsYa4oFw3dftufJK9fWkI308uG19L4wqcVvMqAXqpn1NbQU0Akxk=" - -android: - components: - - tools - - platform-tools - - build-tools-28.0.3 - - android-28 - - extra-google-google_play_services - - extra-android-m2repository - - extra-android-support - - extra-google-m2repository - -jdk: - - oraclejdk8 - -before_install: - - echo "sdk.dir=$ANDROID_HOME" > local.properties - -script: ./gradlew clean check --stacktrace - -after_success: - - ./scripts/deploy_snapshot.sh - - ./scripts/push-to-github-io.sh - -deploy: - skip_cleanup: true - provider: script - script: ./scripts/release.sh - on: - tags: true - repo: permissions-dispatcher/PermissionsDispatcher - -cache: - directories: - - $HOME/.m2 - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ - - $HOME/.android/build-cache \ No newline at end of file diff --git a/.travis/deploy_key.enc b/.travis/deploy_key.enc deleted file mode 100644 index 2c1a0a87..00000000 Binary files a/.travis/deploy_key.enc and /dev/null differ diff --git a/CHANGELOG.md b/CHANGELOG.md index a5a829ef..93315039 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,61 @@ # ChangeLog +- 4.9.2 | ktx: 1.1.4 2022/04/04 + - Fix: [fix: use ContextCompat instead of PermissionChecker](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/757) +- ktx: 1.1.3 2021/11/07 + - Fix: [sort permissions to secure identification](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/729) +- ktx: 1.1.2 2021/08/14 + - Fix: [permissionRequest proceed doesn't work due to KtxPermissionRequest.requestPermission being null](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/742) +- ktx: 1.1.1 2021/08/09 + - Fix: [Avoid memory leak with ViewModel](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/741) + - Fix: [Support device orientation again](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/738) + - Fix: [Write settings action bug fix](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/737) +- 4.9.1 2021/08/09 + - Fix: [Address compile error on Kotlin 1.5](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/733) +- ktx: 1.0.5 2021/04/14 + - Fix: [Use commitAllowingStateLoss() instead of commitNowAllowingStateLoss() in PermissionRequestFragment dismiss() to avoid exception when performing multiple transactions at same time](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/724) +- ktx: 1.0.4 2021/03/16 + - Fix: [Wrong behaviour of ktx library when two permissions are requested in one screen](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/717) +- ktx: 1.0.3 2021/03/03 + - Fix: stop depending on SNAPSHOT library module +- ktx: 1.0.2 2021/03/03 + - Fix: [System dialog doesn't show up, after manually disable permission from setting](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/705) +- ktx: 1.0.1 2020/09/17 + - Fix: [fix: wrap PermissionResult with Event](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/689) +- ktx: 1.0.0 2020/08/31 + - fix: [observe ViewModel only when a permission has not been granted](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/681) + - feat: [Location dedicated permission methods](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/679) +- 4.8.0 2020/08/31 + - Feat: [Bug fix for NeedOnRequestPermissionsResult lint derector](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/680) +- ktx: 1.0.0-beta1 + - Update: [rewrite internal implementation](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/678) +- 4.7.0 2020/03/25 + - Feat: [ktx module](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/665) + - Update: [Add missing dangerous permissions check in later versions](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/652) + - Update: [Use the constant from `PermissionChecker`](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/658) +- 4.6.0 2019/10/30 + - Fix: lint CallNeedsPermission on same named function [#602](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/602) + - Fix: Remove Conductor support [#644](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/644) + [#620](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/620) + - Fix: Java to Kotlin collections mapping [#643](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/643) +- 4.5.0 2019/07/01 + - Improve: Incremental annotation processing for Kotlin [#626](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/626) + - Fix: lint CallNeedsPermission on same named function [#602](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/602) + - Fix: java-kotlin conversion issue [#603](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/603) [#620](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/620) + - Fix: Remove redundant BuildConfig file [#607](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/607) +- 4.3.1 2019/04/08 + - Add: Add support for internal classes [#574](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/606) +- 4.3.0 2018/12/31 + - Add: Conductor support [#574](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/574) - 4.2.0 2018/12/21 - Add: OnShowRationale API change with keeping backward compatibility [#569](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/569) - Update: Change maven groupId from `com.github.hotchemi` to `org.permissionsdispatcher` [#560](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/560) - Doc: Publish document site! https://permissions-dispatcher.github.io - Fix: Any is translated to java.lang.Object [#545](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/545) - Add: Support Java incremental compilation [#473](https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/473) + - Update: Drop Xiaomi support [#548](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/548) - 4.1.0 2018/12/07 - Fix: compile time validation for detecting OnNeverAskAgain with special permissions [#549](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/549) - - Update: Drop Xiaomi support [#548](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/548) - Fix: Fix CallNeedsPermissionDetector to scan only annotated classes [#536](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/536) - 4.0.0 2018/10/20 - Update: [Update androidx ver to 1.0.0](https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/530) diff --git a/README.md b/README.md index 6ef35883..7278ae35 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,126 @@ -# PermissionsDispatcher [![Build Status](https://travis-ci.org/permissions-dispatcher/PermissionsDispatcher.svg?branch=master)](https://travis-ci.org/permissions-dispatcher/PermissionsDispatcher) +# PermissionsDispatcher ![CI for pull request](https://github.com/permissions-dispatcher/PermissionsDispatcher/workflows/CI%20for%20pull%20request/badge.svg) [![PermissionsDispatcher](https://www.appbrain.com/stats/libraries/shield/permissions_dispatcher.svg)](https://www.appbrain.com/stats/libraries/details/permissions_dispatcher/permissionsdispatcher) -- [**Kotlin support**](https://github.com/hotchemi/PermissionsDispatcher/blob/master/doc/kotlin_usage.md) -- [**Special Permissions support**](https://github.com/hotchemi/PermissionsDispatcher/blob/master/doc/special_permissions.md) +- **Fully Kotlin/Java support** +- [**Special permissions support**](https://github.com/hotchemi/PermissionsDispatcher/blob/master/doc/special_permissions.md) - **100% reflection-free** PermissionsDispatcher provides a simple annotation-based API to handle runtime permissions. This library lifts the burden that comes with writing a bunch of check statements whether a permission has been granted or not from you, in order to keep your code clean and safe. -For more information please see [the website](https://permissions-dispatcher.github.io/). +## Usage + +- Kotlin: You can pick either of [ktx](https://github.com/permissions-dispatcher/PermissionsDispatcher/tree/master/ktx) or [kapt](https://github.com/permissions-dispatcher/PermissionsDispatcher#0-prepare-androidmanifest). +- Java: [apt](https://github.com/hotchemi/PermissionsDispatcher/blob/master/doc/java_usage.md) + +Here's a minimum example, in which you register a `MainActivity` which requires `Manifest.permission.CAMERA`. + +### 0. Prepare AndroidManifest + +Add the following line to `AndroidManifest.xml`: + +`` + +### 1. Attach annotations + +PermissionsDispatcher introduces only a few annotations, keeping its general API concise: + +> NOTE: Annotated methods must not be `private`. + +|Annotation|Required|Description| +|---|---|---| +|`@RuntimePermissions`|**✓**|Register an `Activity` or `Fragment` to handle permissions| +|`@NeedsPermission`|**✓**|Annotate a method which performs the action that requires one or more permissions| +|`@OnShowRationale`||Annotate a method which explains why the permissions are needed. It passes in a `PermissionRequest` object which can be used to continue or abort the current permission request upon user input. If you don't specify any argument for the method compiler will generate `process${NeedsPermissionMethodName}ProcessRequest` and `cancel${NeedsPermissionMethodName}ProcessRequest`. You can use those methods in place of `PermissionRequest`(ex: with `DialogFragment`)| +|`@OnPermissionDenied`||Annotate a method which is invoked if the user doesn't grant the permissions| +|`@OnNeverAskAgain`||Annotate a method which is invoked if the user chose to have the device "never ask again" about a permission| + +```kotlin +@RuntimePermissions +class MainActivity : AppCompatActivity(), View.OnClickListener { + + @NeedsPermission(Manifest.permission.CAMERA) + fun showCamera() { + supportFragmentManager.beginTransaction() + .replace(R.id.sample_content_fragment, CameraPreviewFragment.newInstance()) + .addToBackStack("camera") + .commitAllowingStateLoss() + } + + @OnShowRationale(Manifest.permission.CAMERA) + fun showRationaleForCamera(request: PermissionRequest) { + showRationaleDialog(R.string.permission_camera_rationale, request) + } + + @OnPermissionDenied(Manifest.permission.CAMERA) + fun onCameraDenied() { + Toast.makeText(this, R.string.permission_camera_denied, Toast.LENGTH_SHORT).show() + } + + @OnNeverAskAgain(Manifest.permission.CAMERA) + fun onCameraNeverAskAgain() { + Toast.makeText(this, R.string.permission_camera_never_askagain, Toast.LENGTH_SHORT).show() + } +} +``` + +### 2. Delegate to generated functions + +Now generated functions become much more concise and intuitive than Java version! + +```kotlin + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + findViewById(R.id.button_camera).setOnClickListener { + // NOTE: delegate the permission handling to generated function + showCameraWithPermissionCheck() + } + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + // NOTE: delegate the permission handling to generated function + onRequestPermissionsResult(requestCode, grantResults) + } +``` + +Check out the [sample](https://github.com/hotchemi/PermissionsDispatcher/tree/master/sample) for more details. + +## Other features/plugins + +- [Getting Special Permissions](https://github.com/hotchemi/PermissionsDispatcher/blob/master/doc/special_permissions.md) +- [maxSdkVersion](https://github.com/hotchemi/PermissionsDispatcher/blob/master/doc/maxsdkversion.md) +- [IntelliJ plugin](https://github.com/shiraji/permissions-dispatcher-plugin) +- [AndroidAnnotations plugin](https://github.com/AleksanderMielczarek/AndroidAnnotationsPermissionsDispatcherPlugin) + +## Installation + +**NOTE:** + - If you're using jCenter we've moved on to MavenCentral, see [migration guide](https://github.com/hotchemi/PermissionsDispatcher/blob/master/doc/migration_guide.md). + - 4.x only supports [Jetpack](https://developer.android.com/jetpack/). If you still use appcompat 3.x is the way to go. + +To add PermissionsDispatcher to your project, include the following in your **app module** `build.gradle` file: + +`${latest.version}` is [![Download](https://maven-badges.herokuapp.com/maven-central/com.github.permissions-dispatcher/permissionsdispatcher/badge.svg)](https://search.maven.org/search?q=g:com.github.permissions-dispatcher) + +```groovy +dependencies { + implementation "com.github.permissions-dispatcher:permissionsdispatcher:${latest.version}" + annotationProcessor "com.github.permissions-dispatcher:permissionsdispatcher-processor:${latest.version}" +} +``` + +With Kotlin: + +```groovy +apply plugin: 'kotlin-kapt' + +dependencies { + implementation "com.github.permissions-dispatcher:permissionsdispatcher:${latest.version}" + kapt "com.github.permissions-dispatcher:permissionsdispatcher-processor:${latest.version}" +} +``` ## License diff --git a/SUMMARY.md b/SUMMARY.md deleted file mode 100644 index 54a79214..00000000 --- a/SUMMARY.md +++ /dev/null @@ -1,26 +0,0 @@ -# Summary - -- [Introduction](README.md) - -## Getting Started - -- [Installation](doc/installation.md) -- [Java](doc/java_usage.md) -- [Kotlin](doc/kotlin_usage.md) - -## Features - -- [Special Permissions](doc/special_permissions.md) -- [maxSdkVersion](doc/maxsdkversion.md) - -## Plugins - -- [IntelliJ plugin](https://github.com/shiraji/permissions-dispatcher-plugin) -- [AndroidAnnotations plugin](https://github.com/permissions-dispatcher/AndroidAnnotationsPermissionsDispatcherPlugin) - -## Misc - -- [Changelog](CHANGELOG.md) -- [Migration Guide](doc/migration_guide.md) -- [Source Code](https://github.com/permissions-dispatcher/PermissionsDispatcher) -- [Users](doc/users.md) diff --git a/annotation/build.gradle b/annotation/build.gradle index 9d40c188..2525a324 100644 --- a/annotation/build.gradle +++ b/annotation/build.gradle @@ -1,56 +1,2 @@ apply plugin: 'java-library' -apply plugin: 'maven-publish' -apply plugin: 'com.jfrog.bintray' - -group = GROUP_ID -version = VERSION - -targetCompatibility = JavaVersion.VERSION_1_6 -sourceCompatibility = JavaVersion.VERSION_1_6 - -task sourcesJar(type: Jar) { - from sourceSets.main.java.srcDirs - classifier = 'sources' -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -publishing { - publications { - MyPublication(MavenPublication) { - from components.java - artifact sourcesJar - artifact javadocJar - groupId GROUP_ID - artifactId ARTIFACT_ID_ANNOTATION - version VERSION - } - } -} - -bintray { - publications = ['MyPublication'] - user = bintrayUser - key = bintrayKey - dryRun = dryRun - publish = true - - pkg { - repo = REPO - userOrg = USER - name = ARTIFACT_ID_ANNOTATION - vcsUrl = VCS_URL - licenses = LICENSES - version { - name = VERSION - desc = DESCRIPTION - } - } -} - -// Non-Android project: Artifactory Plugin adds only 1 publication -project.ext.publicationName = "maven" -apply from: rootProject.file('gradle/gradle-artifactory-upload.gradle') +apply plugin: "com.vanniktech.maven.publish" diff --git a/annotation/gradle.properties b/annotation/gradle.properties new file mode 100644 index 00000000..1fb357f6 --- /dev/null +++ b/annotation/gradle.properties @@ -0,0 +1,3 @@ +POM_NAME = permissionsdispatcher-annotation +POM_ARTIFACT_ID = permissionsdispatcher-annotation +POM_PACKAGING = jar diff --git a/build.gradle b/build.gradle index d46e8f54..e67de68b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,4 @@ buildscript { - apply from: "${rootDir.absolutePath}/ext.gradle" - repositories { mavenCentral() google() @@ -9,23 +7,17 @@ buildscript { dependencies { classpath "com.android.tools.build:gradle:$GRADLE_PLUGIN_VERSION" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" - classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$BINTRAY_PLUGIN_VERSION" - classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$JFROG_PLUGIN_VERSION" + classpath "org.jetbrains.dokka:dokka-gradle-plugin:$DOKKA_VERSION" + classpath "com.vanniktech:gradle-maven-publish-plugin:$PUBLISH_PLUGIN_VERSION" } } -def generatePomFilesTask = tasks.create("generatePomFiles") - allprojects { repositories { mavenCentral() google() jcenter() - } - - tasks.whenTaskAdded { - if (it.name.matches("generatePomFileFor([A-Z][a-zA-Z]*)Publication")) { - generatePomFilesTask.dependsOn it - } + // TODO: remove after publishing kompile-testing to Maven Central + maven { url 'https://jitpack.io' } } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index cacfe55b..fc2868a6 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -5,7 +5,7 @@ repositories { } dependencies { - compile gradleApi() - compile localGroovy() - compile "commons-io:commons-io:2.6" + implementation gradleApi() + implementation localGroovy() + implementation "commons-io:commons-io:2.6" } diff --git a/doc/installation.md b/doc/installation.md deleted file mode 100644 index 835d3354..00000000 --- a/doc/installation.md +++ /dev/null @@ -1,35 +0,0 @@ -## Installation - -NOTE: 4.x only supports [Jetpack](https://developer.android.com/jetpack/). If you still use appcompat 3.x is the way to go. - -To add PermissionsDispatcher to your project, include the following in your **app module** `build.gradle` file: - -`${latest.version}` is [![Download](https://api.bintray.com/packages/hotchemi/maven/permissionsdispatcher/images/download.svg?version=4.1.0) ](https://bintray.com/hotchemi/maven/permissionsdispatcher/4.1.0/link) - -```groovy -dependencies { - implementation "org.permissionsdispatcher:permissionsdispatcher:${latest.version}" - annotationProcessor "org.permissionsdispatcher:permissionsdispatcher-processor:${latest.version}" -} -``` - -With Kotlin: - -```groovy -apply plugin: 'kotlin-kapt' - -dependencies { - implementation "org.permissionsdispatcher:permissionsdispatcher:${latest.version}" - kapt "org.permissionsdispatcher:permissionsdispatcher-processor:${latest.version}" -} -``` - -Snapshots of the development version are available in [JFrog's snapshots repository](https://oss.jfrog.org/oss-snapshot-local/). -Add the repo below to download `SNAPSHOT` releases. - -```groovy -repositories { - jcenter() - maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' } -} -``` diff --git a/doc/java_usage.md b/doc/java_usage.md index 08ca525f..265be403 100644 --- a/doc/java_usage.md +++ b/doc/java_usage.md @@ -16,7 +16,7 @@ PermissionsDispatcher introduces only a few annotations, keeping its general API |Annotation|Required|Description| |---|---|---| -|`@RuntimePermissions`|**✓**|Register an `Activity` or `Fragment`(we support both) to handle permissions| +|`@RuntimePermissions`|**✓**|Register an `Activity` or `Fragment` to handle permissions| |`@NeedsPermission`|**✓**|Annotate a method which performs the action that requires one or more permissions| |`@OnShowRationale`||Annotate a method which explains why the permissions are needed. It passes in a `PermissionRequest` object which can be used to continue or abort the current permission request upon user input. If you don't specify any argument for the method compiler will generate `process${NeedsPermissionMethodName}ProcessRequest` and `cancel${NeedsPermissionMethodName}ProcessRequest`. You can use those methods in place of `PermissionRequest`(ex: with `DialogFragment`)| |`@OnPermissionDenied`||Annotate a method which is invoked if the user doesn't grant the permissions| diff --git a/doc/kotlin_usage.md b/doc/kotlin_usage.md deleted file mode 100644 index fafe8b75..00000000 --- a/doc/kotlin_usage.md +++ /dev/null @@ -1,75 +0,0 @@ -## Usage with Kotlin - -Here's a minimum example, in which you register a `MainActivity` which requires `Manifest.permission.CAMERA`. - -### 0. Prepare AndroidManifest - -Add the following line to `AndroidManifest.xml`: - -`` - -### 1. Attach annotations - -PermissionsDispatcher introduces only a few annotations, keeping its general API concise: - -> NOTE: Annotated methods must not be `private`. - -|Annotation|Required|Description| -|---|---|---| -|`@RuntimePermissions`|**✓**|Register an `Activity` or `Fragment`(we support both) to handle permissions| -|`@NeedsPermission`|**✓**|Annotate a method which performs the action that requires one or more permissions| -|`@OnShowRationale`||Annotate a method which explains why the permissions are needed. It passes in a `PermissionRequest` object which can be used to continue or abort the current permission request upon user input. If you don't specify any argument for the method compiler will generate `process${NeedsPermissionMethodName}ProcessRequest` and `cancel${NeedsPermissionMethodName}ProcessRequest`. You can use those methods in place of `PermissionRequest`(ex: with `DialogFragment`)| -|`@OnPermissionDenied`||Annotate a method which is invoked if the user doesn't grant the permissions| -|`@OnNeverAskAgain`||Annotate a method which is invoked if the user chose to have the device "never ask again" about a permission| - -```kotlin -@RuntimePermissions -class MainActivity : AppCompatActivity(), View.OnClickListener { - - @NeedsPermission(Manifest.permission.CAMERA) - fun showCamera() { - supportFragmentManager.beginTransaction() - .replace(R.id.sample_content_fragment, CameraPreviewFragment.newInstance()) - .addToBackStack("camera") - .commitAllowingStateLoss() - } - - @OnShowRationale(Manifest.permission.CAMERA) - fun showRationaleForCamera(request: PermissionRequest) { - showRationaleDialog(R.string.permission_camera_rationale, request) - } - - @OnPermissionDenied(Manifest.permission.CAMERA) - fun onCameraDenied() { - Toast.makeText(this, R.string.permission_camera_denied, Toast.LENGTH_SHORT).show() - } - - @OnNeverAskAgain(Manifest.permission.CAMERA) - fun onCameraNeverAskAgain() { - Toast.makeText(this, R.string.permission_camera_never_askagain, Toast.LENGTH_SHORT).show() - } -} -``` - -### 2. Delegate to generated functions - -Now generated functions become much more concise and intuitive than Java version! - -```kotlin - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - findViewById(R.id.button_camera).setOnClickListener { - // NOTE: delegate the permission handling to generated function - showCameraWithPermissionCheck() - } - } - - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults) - // NOTE: delegate the permission handling to generated function - onRequestPermissionsResult(requestCode, grantResults) - } -``` - -Check out the [sample](https://github.com/hotchemi/PermissionsDispatcher/tree/master/sample-kotlin) for more details. \ No newline at end of file diff --git a/doc/migration_guide.md b/doc/migration_guide.md index c22fa5e4..e242107f 100644 --- a/doc/migration_guide.md +++ b/doc/migration_guide.md @@ -1,9 +1,34 @@ # Migration guide +- [Migrating to Maven Central](#migrating-to-maven-central) - [Migrating to 4.x](#migrating-to-4x) - [Migrating to 3.x](#migrating-to-3x) - [Migrating to 2.x](#migrating-to-2x) +## Migrating to Maven Central + +Since Maven Central only accepts valid URL, we had no other choices but to change groupId again. + +```diff +dependencies { +- implementation "org.permissionsdispatcher:permissionsdispatcher:${latest.version}" ++ implementation "com.github.permissions-dispatcher:permissionsdispatcher:${latest.version}" +- annotationProcessor "org.permissionsdispatcher:permissionsdispatcher-processor:${latest.version}" ++ annotationProcessor "com.github.permissions-dispatcher:permissionsdispatcher-processor:${latest.version}" +} +``` + +#### KTX + +NOTE: Due to accidental mistake, artifact id `permissionsdispatcher-ktx` also exists on maven central but `ktx` is the correct one. + +```diff +dependencies { +- implementation "org.permissionsdispatcher:permissionsdispatcher-ktx:${latest.version}" ++ implementation "com.github.permissions-dispatcher:ktx:${latest.version}" +} +``` + ## Migrating to 4.x ### Change Maven groupId diff --git a/doc/users.md b/doc/users.md deleted file mode 100644 index c14705bb..00000000 --- a/doc/users.md +++ /dev/null @@ -1,16 +0,0 @@ -## Users - -More detail, please check [appbrain](http://www.appbrain.com/stats/libraries/details/permissions_dispatcher/permissionsdispatcher). - -- [Airbnb](https://play.google.com/store/apps/details?id=com.airbnb.android) -- [askfm](https://play.google.com/store/apps/details?id=com.askfm) -- [Hotel tonight](https://play.google.com/store/apps/details?id=com.hoteltonight.android.prod) -- [Cookpad](https://play.google.com/store/apps/details?id=com.cookpad.android.activities) -- [Cookpad international](https://play.google.com/store/apps/details?id=com.mufumbo.android.recipe.search) -- [Mercari](https://play.google.com/store/apps/details?id=com.kouzoh.mercari) -- [Mercari Atte](https://play.google.com/store/apps/details?id=com.souzoh.android.atte) -- [mitene](https://play.google.com/store/apps/details?id=us.mitene) -- [Monsterstrike](https://play.google.com/store/apps/details?id=jp.co.mixi.monsterstrike) -- [Matchbook](https://play.google.com/store/apps/details?id=jp.co.recruit.mtl.matchbook.android&hl=en) -- [kidsly](https://play.google.com/store/apps/details?id=jp.recruit.kidsly) -- [PAY SHOOT](https://play.google.com/store/apps/details?id=com.pishguy.androidapplication.shootpaymentservice) diff --git a/ext.gradle b/ext.gradle deleted file mode 100644 index ebb6f744..00000000 --- a/ext.gradle +++ /dev/null @@ -1,5 +0,0 @@ -ext { - bintrayUser = System.getenv("bintrayUser") - bintrayKey = System.getenv("bintrayKey") - dryRun = System.getenv("dryRun") == "true" -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index dd4f9458..cff91c0b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,39 +1,46 @@ # Upload configuration USER = hotchemi -GROUP_ID = org.permissionsdispatcher -ARTIFACT_ID_LIBRARY = permissionsdispatcher -ARTIFACT_ID_PROCESSOR = permissionsdispatcher-processor -ARTIFACT_ID_ANNOTATION = permissionsdispatcher-annotation -VERSION = 4.2.0 -REPO = org.permissionsdispatcher -DESCRIPTION = Annotation-based library for generating runtime permissions dispatcher. -WEBSITE = https://github.com/permissions-dispatcher/PermissionsDispatcher -VCS_URL = https://github.com/permissions-dispatcher/PermissionsDispatcher.git -LICENSES = ['Apache-2.0'] +GROUP = com.github.permissions-dispatcher +VERSION_NAME = 4.10.0-SNAPSHOT +POM_NAME = PermissionsDispatcher +POM_DESCRIPTION = A declarative API to handle Android runtime permissions. +POM_INCEPTION_YEAR = 2015 +POM_URL = https://github.com/permissions-dispatcher/PermissionsDispatcher +POM_SCM_URL = https://github.com/permissions-dispatcher/PermissionsDispatcher +POM_SCM_CONNECTION = https://github.com/permissions-dispatcher/PermissionsDispatcher.git +POM_LICENCE_NAME = The Apache Software License, Version 2.0 +POM_LICENCE_URL = https://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_DIST = repo +POM_DEVELOPER_ID = hotchemi +POM_DEVELOPER_NAME = Shintaro Katafuchi +POM_DEVELOPER_URL = https://github.com/hotchemi # Plugin versions -GRADLE_PLUGIN_VERSION = 3.2.1 -KOTLIN_VERSION = 1.2.71 -CONFIG_PLUGIN_VERSION = 2.2.2 -JFROG_PLUGIN_VERSION = 4.1.1 -BINTRAY_PLUGIN_VERSION = 1.8.4 -SUPPORT_LIBRARY_VERSION = 27.0.2 +DOKKA_VERSION = 1.4.20 +PUBLISH_PLUGIN_VERSION = 0.18.0 +GRADLE_PLUGIN_VERSION = 4.2.0 +KOTLIN_VERSION = 1.5.20 +KOTLIN_METADATA_VERSION = 0.3.0 ANDROIDX_LIBRARY_VERSION= 1.0.0 +LIFECYCLE_VERSION = 2.2.0 +ARC_TESTING_VERSION = 1.1.1 JAVAPOET_VERSION = 1.9.0 -KOTLINPOET_VERSION = 1.0.0 +KOTLINPOET_VERSION = 1.3.0 JUNIT_VERSION = 4.12 -MOCKITO_VERSION = 1.10.19 -POWERMOCK_VERSION = 1.6.4 +MOCKITO_VERSION = 2.28.2 +MOCKITO_KOTLIN_VERSION = 2.2.0 +POWERMOCK_VERSION = 2.0.2 COMPILE_TESTING_VERSION = 0.12 -LINT_VERSION = 26.2.0-alpha06 +LINT_VERSION = 26.3.2 ROBOLECTRIC_VERSION = 3.3.2 COMMONS_IO_VERSION = 2.6 +KOMPILE_TESTING_VERSION = 0.1.4 # Android configuration -COMPILE_SDK_VERSION = android-28 -BUILD_TOOLS_VERSION = 28.0.3 -TARGET_SDK_VERSION = 28 +COMPILE_SDK_VERSION = android-29 +TARGET_SDK_VERSION = 29 MIN_SDK_VERSION = 14 +SAMPLE_MIN_SDK_VERSION = 16 # Gradle parameters org.gradle.daemon = true diff --git a/gradle/gradle-artifactory-upload.gradle b/gradle/gradle-artifactory-upload.gradle deleted file mode 100644 index bfdea97c..00000000 --- a/gradle/gradle-artifactory-upload.gradle +++ /dev/null @@ -1,22 +0,0 @@ -if (!project.hasProperty('publicationName')) { - throw new ProjectConfigurationException("Project '$project.name' needs to specify 'proejct.ext.publicationName' if Artifactory support should be added!", null) -} - -apply plugin: 'com.jfrog.artifactory' - -artifactory { - contextUrl = 'https://oss.jfrog.org/artifactory' - publish { - repository { - // The Artifactory repository key to publish to - repoKey = VERSION.endsWith('SNAPSHOT') ? 'oss-snapshot-local' : 'oss-release-local' - username = System.getenv('bintrayUser') // The publisher user name - password = System.getenv('bintrayKey') // The publisher password - maven = true - } - defaults { - publishArtifacts = true - publications([project.ext.publicationName]) - } - } -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index b5166dad..94336fca 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bc8ff91e..1f3fdbc5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Apr 07 20:40:24 JST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/gradlew b/gradlew index 91a7e269..cccdd3d5 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,20 +6,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -114,6 +113,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec99730..e95643d6 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/sample-kotlin/.gitignore b/ktx-sample/.gitignore similarity index 100% rename from sample-kotlin/.gitignore rename to ktx-sample/.gitignore diff --git a/sample-kotlin/build.gradle b/ktx-sample/build.gradle similarity index 51% rename from sample-kotlin/build.gradle rename to ktx-sample/build.gradle index f1fbd602..db42650a 100644 --- a/sample-kotlin/build.gradle +++ b/ktx-sample/build.gradle @@ -1,29 +1,23 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' android { compileSdkVersion COMPILE_SDK_VERSION - buildToolsVersion BUILD_TOOLS_VERSION defaultConfig { - applicationId "permissions.dispatcher.samplekotlin" + applicationId "permissions.dispatcher.sample" targetSdkVersion TARGET_SDK_VERSION - minSdkVersion MIN_SDK_VERSION + minSdkVersion SAMPLE_MIN_SDK_VERSION versionCode 1 versionName "1.0" } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 - } - sourceSets { - main.java.srcDirs += "src/main/kotlin" + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" implementation "androidx.appcompat:appcompat:$ANDROIDX_LIBRARY_VERSION" - implementation project(':library') - kapt project(':processor') + implementation project(':ktx') } diff --git a/sample-kotlin/src/main/AndroidManifest.xml b/ktx-sample/src/main/AndroidManifest.xml similarity index 80% rename from sample-kotlin/src/main/AndroidManifest.xml rename to ktx-sample/src/main/AndroidManifest.xml index 63f110b0..01002661 100644 --- a/sample-kotlin/src/main/AndroidManifest.xml +++ b/ktx-sample/src/main/AndroidManifest.xml @@ -1,11 +1,10 @@ + package="permissions.dispatcher.ktx.sample"> - - + (R.id.button_camera).setOnClickListener { + permissionsRequester.launch() + } + view.findViewById