diff options
author | Allan Wang <me@allanwang.ca> | 2017-10-24 17:47:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 17:47:52 -0400 |
commit | 3e0d4547a5618463508cb9f13a4c8158c161b11f (patch) | |
tree | edd37abe26e5548deed540e7635c824292e70b2c /app/src/main/kotlin/com/pitchedapps/frost/contracts | |
parent | e4b3f3534a099d61eb2537f39d09bc40b4636b30 (diff) | |
download | frost-3e0d4547a5618463508cb9f13a4c8158c161b11f.tar.gz frost-3e0d4547a5618463508cb9f13a4c8158c161b11f.tar.bz2 frost-3e0d4547a5618463508cb9f13a4c8158c161b11f.zip |
misc (#428)
* Add permission check
* Validate uri before downloading
* Update links, addresses # 411
* Update crashlytics
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/contracts')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt index 50ab3acb..26b10532 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt @@ -5,6 +5,8 @@ import android.content.Intent import android.net.Uri import android.webkit.ValueCallback import android.webkit.WebChromeClient +import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE +import ca.allanwang.kau.permissions.kauRequestPermissions import ca.allanwang.kau.utils.string import com.pitchedapps.frost.R import com.pitchedapps.frost.utils.L @@ -29,11 +31,17 @@ class FileChooserDelegate : FileChooserContract { override var filePathCallback: ValueCallback<Array<Uri>?>? = null override fun Activity.openMediaPicker(filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: WebChromeClient.FileChooserParams) { - this@FileChooserDelegate.filePathCallback = filePathCallback - val intent = Intent() - intent.type = fileChooserParams.acceptTypes.firstOrNull() - intent.action = Intent.ACTION_GET_CONTENT - startActivityForResult(Intent.createChooser(intent, string(R.string.pick_image)), MEDIA_CHOOSER_RESULT) + kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ -> + if (!granted) { + filePathCallback.onReceiveValue(null) + return@kauRequestPermissions + } + this@FileChooserDelegate.filePathCallback = filePathCallback + val intent = Intent() + intent.type = fileChooserParams.acceptTypes.firstOrNull() + intent.action = Intent.ACTION_GET_CONTENT + startActivityForResult(Intent.createChooser(intent, string(R.string.pick_image)), MEDIA_CHOOSER_RESULT) + } } override fun Activity.onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean { |