diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-02 16:21:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-02 16:21:49 -0700 |
commit | 53382b44bb7ab7ccb559e96fd1f93c47020878ee (patch) | |
tree | 79c1862992f458ac52c1910b3a2e0c01cb7d5a5a /core/src/main/kotlin/ca/allanwang/kau/permissions | |
parent | 7d894be6de118357ec908d2d171b6152ce67307d (diff) | |
download | kau-53382b44bb7ab7ccb559e96fd1f93c47020878ee.tar.gz kau-53382b44bb7ab7ccb559e96fd1f93c47020878ee.tar.bz2 kau-53382b44bb7ab7ccb559e96fd1f93c47020878ee.zip |
Improve video prefetching (#17)
* Create base activity and add thumbnails to media picker
* Add checker to see if requested permission is inside the manifest
* Add faq parser with tests
* Add kpref testers and expose sp
* Test jitpack sample exclusion
* Test caching
* Improve glide caching
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/permissions')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt index d6e17db..0c42574 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt @@ -2,13 +2,17 @@ package ca.allanwang.kau.permissions import android.app.Activity import android.content.Context +import android.content.pm.PackageManager import android.support.v4.app.ActivityCompat +import ca.allanwang.kau.kotlin.lazyContext import ca.allanwang.kau.logging.KL import ca.allanwang.kau.utils.KauException import ca.allanwang.kau.utils.buildIsMarshmallowAndUp import ca.allanwang.kau.utils.hasPermission +import ca.allanwang.kau.utils.toast import java.lang.ref.WeakReference + /** * Created by Allan Wang on 2017-07-03. */ @@ -17,6 +21,17 @@ internal object PermissionManager { var requestInProgress = false val pendingResults: MutableList<WeakReference<PermissionResult>> by lazy { mutableListOf<WeakReference<PermissionResult>>() } + /** + * Retrieve permissions requested in our manifest + */ + val manifestPermission = lazyContext<Array<String>> { + try { + it.packageManager.getPackageInfo(it.packageName, PackageManager.GET_PERMISSIONS)?.requestedPermissions ?: emptyArray() + } catch (e: Exception) { + emptyArray() + } + } + operator fun invoke(context: Context, permissions: Array<out String>, callback: (granted: Boolean, deniedPerm: String?) -> Unit) { KL.d("Permission manager for: ${permissions.contentToString()}") if (!buildIsMarshmallowAndUp) return callback(true, null) @@ -30,6 +45,13 @@ internal object PermissionManager { } @Synchronized internal fun requestPermissions(context: Context, permissions: Array<out String>) { + permissions.forEach { + if (!manifestPermission(context).contains(it)) { + KL.e("Requested permission $it is not stated in the manifest") + context.toast("$it is not in the manifest") + //we'll let the request pass through so it can be denied and so the callback can be triggered + } + } val activity = (context as? Activity) ?: throw KauException("Context is not an instance of an activity; cannot request permissions") KL.d("Requesting permissions ${permissions.contentToString()}") ActivityCompat.requestPermissions(activity, permissions, 1) |