hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
423 stars 51 forks source link

Save captures to public picture directory #202

Closed fffx closed 2 years ago

fffx commented 2 years ago

I wanna save captures to DIRECTORY_PICTURES. I was thought to override onActivityResult in TurboWebFragment, but found out it's final. Also, I don't wanna override TurboWebChromeClient, which would add too much complexity just for this tiny tweak. Is there any other way I can do this? Thanks in advance.

jayohms commented 2 years ago

Can you explain the flow that you're trying to solve? Do you want to save a new capture to disk while also uploading to the WebView?

fffx commented 2 years ago

Yeah, I wanna make the new capture save to the local disk before uploading(more precisely in public Picture folder like Instagram).

Maybe I can create a PR for this? Add boolean option capture_to_public to settings? If it's true, we save new captures to Environment.DIRECTORY_PICTURES) / context.packageName.

fffx commented 2 years ago

😭 I overestimated my Android development skills. The permission problem with old and new Android versions really struggled me, so I used a workaround: copy the captures on form submission

this do not need any permission in Android Q +

 // WebFragment.kt

    @RequiresApi(Build.VERSION_CODES.Q)
    override fun onFormSubmissionStarted(location: String) {
        super.onFormSubmissionStarted(location)
        GlobalScope.launch(Dispatchers.Main) {
            withContext(Dispatchers.IO) {
                SaveCapture.sync(requireContext())
            }
        }
    }