From 8be8b88247973592b2afe134f99c8102929e0b2d Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 25 Sep 2021 15:57:15 -0700 Subject: Delete old file chooser code --- .../com/pitchedapps/frost/contracts/FileChooser.kt | 67 +++------------------- 1 file changed, 8 insertions(+), 59 deletions(-) (limited to 'app/src') 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 21cb4948..521d0f97 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt @@ -25,7 +25,9 @@ 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.injectors.ThemeProvider import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.frostSnackbar import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -36,7 +38,7 @@ import javax.inject.Inject /** * Created by Allan Wang on 2017-07-04. */ -const val MEDIA_CHOOSER_RESULT = 67 +private const val MEDIA_CHOOSER_RESULT = 67 interface WebFileChooser { fun openMediaPicker( @@ -51,8 +53,10 @@ interface WebFileChooser { ): Boolean } -class WebFileChooserImpl @Inject internal constructor(private val activity: Activity) : - WebFileChooser { +class WebFileChooserImpl @Inject internal constructor( + private val activity: Activity, + private val themeProvider: ThemeProvider +) : WebFileChooser { private var filePathCallback: ValueCallback?>? = null override fun openMediaPicker( @@ -62,6 +66,7 @@ class WebFileChooserImpl @Inject internal constructor(private val activity: Acti activity.kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ -> if (!granted) { L.d { "Failed to get write permissions" } + activity.frostSnackbar(R.string.file_chooser_not_found, themeProvider) filePathCallback.onReceiveValue(null) return@kauRequestPermissions } @@ -97,59 +102,3 @@ interface WebFileChooserModule { @ActivityScoped fun webFileChooser(to: WebFileChooserImpl): WebFileChooser } - -interface FileChooserActivityContract { - fun openFileChooser( - filePathCallback: ValueCallback?>, - fileChooserParams: WebChromeClient.FileChooserParams - ) -} - -interface FileChooserContract { - var filePathCallback: ValueCallback?>? - fun Activity.openMediaPicker( - 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 Activity.openMediaPicker( - filePathCallback: ValueCallback?>, - fileChooserParams: WebChromeClient.FileChooserParams - ) { - kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ -> - if (!granted) { - L.d { "Failed to get write permissions" } - 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 { - L.d { "FileChooser On activity results web $requestCode" } - if (requestCode != MEDIA_CHOOSER_RESULT) return false - val data = intent?.data - filePathCallback?.onReceiveValue(if (data != null) arrayOf(data) else null) - filePathCallback = null - return true - } -} -- cgit v1.2.3