fix: catch exceptions while launching OPEN_DOCUMENT_TREE intent

This commit is contained in:
Akash Yadav
2023-03-03 19:08:30 +05:30
parent 28bd0ffc9a
commit 66b7f570db
2 changed files with 7 additions and 1 deletions
@@ -39,6 +39,7 @@ import androidx.core.provider.DocumentsContractCompat.buildDocumentUriUsingTree
import androidx.core.provider.DocumentsContractCompat.getTreeDocumentId
import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.Fragment
import com.itsaky.androidide.common.R
import com.itsaky.androidide.resources.R.string
import com.itsaky.androidide.utils.flashError
import java.io.File
@@ -106,7 +107,11 @@ open class BaseFragment @JvmOverloads constructor(contentLayoutId: Int = 0) :
protected fun pickDirectory(dirCallback: OnDirectoryPickedCallback?) {
this.callback = dirCallback
this.startForResult.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE))
try {
this.startForResult.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE))
} catch (e: Exception) {
requireActivity().flashError(getString(R.string.msg_dir_picker_failed, e.message))
}
}
fun interface OnDirectoryPickedCallback {
@@ -541,4 +541,5 @@
<string name="idepref_java_diagnosticEnabled_title">Diagnostics enabled</string>
<string name="idepref_java_diagnosticsEnabled_summary">(EXPERIMENTAL) Whether the Java source files should be analyzed for errors or not.</string>
<string name="title_reload_color_schemes">Reload color schemes</string>
<string name="msg_dir_picker_failed">Failed to start directory picker : %1$s</string>
</resources>