From d94bc858c8a0c273d87d705eb06d35cfd9cf9e08 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 25 Jul 2017 15:18:12 -0700 Subject: Update image downloads , IAB, and many issue reports (#95) * 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 --- .../com/pitchedapps/frost/contracts/FileChooser.kt | 42 ++++++++++------------ 1 file changed, 18 insertions(+), 24 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/contracts') 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>, fileChooserParams: WebChromeClient.FileChooserParams) @@ -20,35 +22,27 @@ interface FileChooserActivityContract { interface FileChooserContract { var filePathCallback: ValueCallback>? - fun openFileChooser(activity: Activity, filePathCallback: ValueCallback>, fileChooserParams: WebChromeClient.FileChooserParams) - fun onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean + fun Activity.openImagePicker(filePathCallback: ValueCallback>, fileChooserParams: WebChromeClient.FileChooserParams) + fun Activity.onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean } class FileChooserDelegate : FileChooserContract { override var filePathCallback: ValueCallback>? = null - override fun openFileChooser(activity: Activity, filePathCallback: ValueCallback>, 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>, 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 } -- cgit v1.2.3