diff options
author | Allan Wang <me@allanwang.ca> | 2017-10-13 20:32:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-13 20:32:00 -0400 |
commit | 4ad2d23ceccc23f8b11b0a5e712a1f08722611df (patch) | |
tree | 3cd9cb8217ac7125db56160ff20ba2c6cebe5e91 /app/src/main/kotlin/com | |
parent | 32ff6c3269abb81289160aa6f9f55c14369c99a3 (diff) | |
download | frost-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')
6 files changed, 19 insertions, 52 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt index 4e1c31d9..27f959cf 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt @@ -372,7 +372,7 @@ class MainActivity : BaseActivity(), return true } - override fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams) { + override fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: WebChromeClient.FileChooserParams) { openMediaPicker(filePathCallback, fileChooserParams) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MediaPickerActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MediaPickerActivity.kt deleted file mode 100644 index 162baf20..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MediaPickerActivity.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.pitchedapps.frost.activities - -import android.content.Context -import android.net.Uri -import android.support.v4.content.FileProvider -import ca.allanwang.kau.mediapicker.* -import ca.allanwang.kau.utils.colorToBackground -import com.pitchedapps.frost.BuildConfig -import com.pitchedapps.frost.utils.Prefs -import java.io.File - -/** - * Created by Allan Wang on 2017-07-23. - */ -private fun actions(): List<MediaAction> { - val color = Prefs.accentColorForWhite - return listOf(object : MediaActionCamera(color) { - - override fun createFile(context: Context): File - = createMediaFile("Frost", ".jpg") - - override fun createUri(context: Context, file: File): Uri - = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file) - - }, MediaActionGallery(color = color.colorToBackground(0.1f))) -} - -class ImagePickerActivity : MediaPickerActivityOverlayBase(MediaType.IMAGE, actions()) - -class VideoPickerActivity : MediaPickerActivityOverlayBase(MediaType.VIDEO, actions())
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index a237e3f5..bca10606 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -192,7 +192,7 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : KauBas } } - override fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: WebChromeClient.FileChooserParams) { + override fun openFileChooser(filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: WebChromeClient.FileChooserParams) { openMediaPicker(filePathCallback, fileChooserParams) } 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 } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt index 64fb130f..ac9745f9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt @@ -8,6 +8,8 @@ import android.os.Environment import android.webkit.URLUtil 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.dbflow.loadFbCookie @@ -20,14 +22,12 @@ fun Context.frostDownload(url: String, userAgent: String, contentDisposition: St L.d("Received download request", "Download $url") kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ -> if (!granted) return@kauRequestPermissions - val request = DownloadManager.Request(Uri.parse(url)) - request.setMimeType(mimeType) val cookie = loadFbCookie(Prefs.userId) ?: return@kauRequestPermissions request.addRequestHeader("cookie", cookie.cookie) request.addRequestHeader("User-Agent", userAgent) - request.setDescription("Downloading file...") + request.setDescription(string(R.string.downloading)) request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)) request.allowScanningByMediaScanner() request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt index b469659b..2fa80830 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt @@ -69,7 +69,7 @@ class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() { progressObservable.onNext(newProgress) } - override fun onShowFileChooser(webView: WebView, filePathCallback: ValueCallback<Array<Uri>>, fileChooserParams: FileChooserParams): Boolean { + override fun onShowFileChooser(webView: WebView, filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: FileChooserParams): Boolean { activityContract?.openFileChooser(filePathCallback, fileChooserParams) ?: webView.frostSnackbar(R.string.file_chooser_not_found) return activityContract != null } |