aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/contracts
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-25 15:18:12 -0700
committerGitHub <noreply@github.com>2017-07-25 15:18:12 -0700
commitd94bc858c8a0c273d87d705eb06d35cfd9cf9e08 (patch)
tree05220a36a87a73388b89901f4fe5cd09d3fd48d5 /app/src/main/kotlin/com/pitchedapps/frost/contracts
parent913eaf7ea029030d7354a3969dc6aa87b0a51b1a (diff)
downloadfrost-d94bc858c8a0c273d87d705eb06d35cfd9cf9e08.tar.gz
frost-d94bc858c8a0c273d87d705eb06d35cfd9cf9e08.tar.bz2
frost-d94bc858c8a0c273d87d705eb06d35cfd9cf9e08.zip
Update image downloads , IAB, and many issue reports (#95)v1.4
* Remove iab proguard line * Remove dup vending aidl * Fix double calling issue * Change pro logging * Remove async call * Allow for multiple result flags from settings * Rename restore to get * Remove remaining async * Add null checks across web clients * Do not delete temp file on save * Implement image logic * Update file chooser * Update travis * Add intent checker * Update dependencies * Update dependencies * Add debugging option * Switch context for login glide * Scan newly added files * Update theme * Allow image downloading in messages * Finalize beta release * Build to beta * Update strings
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/contracts')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt42
1 files changed, 18 insertions, 24 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 5b2cfa49..bd31d6ce 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt
@@ -5,14 +5,16 @@ import android.content.Intent
import android.net.Uri
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
-import ca.allanwang.kau.permissions.PERMISSION_READ_EXTERNAL_STORAGE
-import ca.allanwang.kau.permissions.kauRequestPermissions
+import ca.allanwang.kau.imagepicker.kauLaunchImagePicker
+import ca.allanwang.kau.imagepicker.kauOnImagePickerResult
+import com.pitchedapps.frost.activities.ImagePickerActivity
import com.pitchedapps.frost.utils.L
+import java.io.File
/**
* Created by Allan Wang on 2017-07-04.
*/
-const val FILE_CHOOSER_REQUEST = 67
+const val IMAGE_CHOOSER_REQUEST = 67
interface FileChooserActivityContract {
fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams)
@@ -20,35 +22,27 @@ interface FileChooserActivityContract {
interface FileChooserContract {
var filePathCallback: ValueCallback<Array<Uri>>?
- fun openFileChooser(activity: Activity, filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams)
- fun onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean
+ fun Activity.openImagePicker(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams)
+ fun Activity.onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean
}
class FileChooserDelegate : FileChooserContract {
override var filePathCallback: ValueCallback<Array<Uri>>? = null
- override fun openFileChooser(activity: Activity, filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams) {
- activity.kauRequestPermissions(PERMISSION_READ_EXTERNAL_STORAGE) {
- granted, _ ->
- if (!granted) return@kauRequestPermissions
- val contentSelectionIntent = Intent(Intent.ACTION_GET_CONTENT)
- contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE)
- contentSelectionIntent.type = fileChooserParams.acceptTypes?.joinToString(separator = "|") ?: "*/*"
- activity.startActivityForResult(contentSelectionIntent, FILE_CHOOSER_REQUEST)
- this.filePathCallback?.onReceiveValue(null)
- this.filePathCallback = filePathCallback
- }
+ override fun Activity.openImagePicker(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams) {
+ this@FileChooserDelegate.filePathCallback = filePathCallback
+ kauLaunchImagePicker(ImagePickerActivity::class.java, IMAGE_CHOOSER_REQUEST)
}
- override fun onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean {
- L.d("On activity results web $requestCode")
- if (requestCode != FILE_CHOOSER_REQUEST) return false
- var results: Uri? = null
-
- if (resultCode == Activity.RESULT_OK && intent != null) results = Uri.parse(intent.dataString)
- L.d("Callback received; ${filePathCallback != null}")
- filePathCallback?.onReceiveValue(if (results == null) null else arrayOf(results))
+ override fun Activity.onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean {
+ L.d("FileChooser On activity results web $requestCode")
+ if (requestCode != IMAGE_CHOOSER_REQUEST) return false
+ val results = kauOnImagePickerResult(resultCode, intent).map { it.uri }.toTypedArray()
+ L.d("FileChooser result ${results.contentToString()}")
+ //proper path content://com.android.providers.media.documents/document/image%3A36341
+ L.d("FileChooser Callback received; ${filePathCallback != null}")
+ filePathCallback?.onReceiveValue(results)
filePathCallback = null
return true
}