aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/contracts
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-10-13 20:32:00 -0400
committerGitHub <noreply@github.com>2017-10-13 20:32:00 -0400
commit4ad2d23ceccc23f8b11b0a5e712a1f08722611df (patch)
tree3cd9cb8217ac7125db56160ff20ba2c6cebe5e91 /app/src/main/kotlin/com/pitchedapps/frost/contracts
parent32ff6c3269abb81289160aa6f9f55c14369c99a3 (diff)
downloadfrost-4ad2d23ceccc23f8b11b0a5e712a1f08722611df.tar.gz
frost-4ad2d23ceccc23f8b11b0a5e712a1f08722611df.tar.bz2
frost-4ad2d23ceccc23f8b11b0a5e712a1f08722611df.zip
Revert/mediapicker (#407)
* Remove kau mediapicker * Allow cancellation and clean up * Fix up downloader
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/contracts')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt29
1 files changed, 13 insertions, 16 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 f3d90bcc..50ab3acb 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt
@@ -5,10 +5,8 @@ import android.content.Intent
import android.net.Uri
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
-import ca.allanwang.kau.mediapicker.kauLaunchMediaPicker
-import ca.allanwang.kau.mediapicker.kauOnMediaPickerResult
-import com.pitchedapps.frost.activities.ImagePickerActivity
-import com.pitchedapps.frost.activities.VideoPickerActivity
+import ca.allanwang.kau.utils.string
+import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.L
/**
@@ -17,33 +15,32 @@ import com.pitchedapps.frost.utils.L
const val MEDIA_CHOOSER_RESULT = 67
interface FileChooserActivityContract {
- fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams)
+ fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: WebChromeClient.FileChooserParams)
}
interface FileChooserContract {
- var filePathCallback: ValueCallback<Array<Uri>>?
- fun Activity.openMediaPicker(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams)
+ var filePathCallback: ValueCallback<Array<Uri>?>?
+ fun Activity.openMediaPicker(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 var filePathCallback: ValueCallback<Array<Uri>?>? = null
- override fun Activity.openMediaPicker(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams) {
+ override fun Activity.openMediaPicker(filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: WebChromeClient.FileChooserParams) {
this@FileChooserDelegate.filePathCallback = filePathCallback
- val isVideo = fileChooserParams.acceptTypes.firstOrNull() == "video/*"
- kauLaunchMediaPicker(if (isVideo) VideoPickerActivity::class.java else ImagePickerActivity::class.java, MEDIA_CHOOSER_RESULT)
+ 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 {
L.d("FileChooser On activity results web $requestCode")
if (requestCode != MEDIA_CHOOSER_RESULT) return false
- val results = kauOnMediaPickerResult(resultCode, intent).map { it.uri }.toTypedArray()
- L.i("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)
+ val data = intent?.data
+ filePathCallback?.onReceiveValue(if (data != null) arrayOf(data) else null)
filePathCallback = null
return true
}