Merge pull request #1343 from KryptKode/fix/sdk30-saf-source-folder

sdk 30 changes
This commit is contained in:
Tibor Kaputa 2022-03-19 23:50:37 +01:00 committed by GitHub
commit f87746d9e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 21 deletions

View file

@ -491,7 +491,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
} }
funAfterSAFPermission = callback funAfterSAFPermission = callback
WritePermissionDialog(this, Mode.OTG) { WritePermissionDialog(this, Mode.Otg) {
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply { Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
try { try {
startActivityForResult(this, OPEN_DOCUMENT_TREE_OTG) startActivityForResult(this, OPEN_DOCUMENT_TREE_OTG)
@ -593,11 +593,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
) { ) {
handleSAFDialog(source) { handleSAFDialog(source) {
if (it) { if (it) {
handleSAFDialogSdk30(source) { startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden)
if (it) {
startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden)
}
}
} }
} }
} else { } else {

View file

@ -11,39 +11,39 @@ import kotlinx.android.synthetic.main.dialog_write_permission.view.*
import kotlinx.android.synthetic.main.dialog_write_permission_otg.view.* import kotlinx.android.synthetic.main.dialog_write_permission_otg.view.*
class WritePermissionDialog(activity: Activity, val mode: Mode, val callback: () -> Unit) { class WritePermissionDialog(activity: Activity, val mode: Mode, val callback: () -> Unit) {
enum class Mode { sealed class Mode {
OTG, object Otg : Mode()
SD_CARD, object SdCard : Mode()
OPEN_DOCUMENT_TREE_SDK_30, data class OpenDocumentTreeSDK30(val path: String) : Mode()
CREATE_DOCUMENT_SDK_30, object CreateDocumentSDK30 : Mode()
} }
var dialog: AlertDialog var dialog: AlertDialog
init { init {
val layout = if (mode == Mode.SD_CARD) R.layout.dialog_write_permission else R.layout.dialog_write_permission_otg val layout = if (mode == Mode.SdCard) R.layout.dialog_write_permission else R.layout.dialog_write_permission_otg
val view = activity.layoutInflater.inflate(layout, null) val view = activity.layoutInflater.inflate(layout, null)
val glide = Glide.with(activity) val glide = Glide.with(activity)
val crossFade = DrawableTransitionOptions.withCrossFade() val crossFade = DrawableTransitionOptions.withCrossFade()
when (mode) { when (mode) {
Mode.OTG -> { Mode.Otg -> {
view.write_permissions_dialog_otg_text.setText(R.string.confirm_usb_storage_access_text) view.write_permissions_dialog_otg_text.setText(R.string.confirm_usb_storage_access_text)
glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(view.write_permissions_dialog_otg_image) glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(view.write_permissions_dialog_otg_image)
} }
Mode.SD_CARD -> { Mode.SdCard -> {
glide.load(R.drawable.img_write_storage).transition(crossFade).into(view.write_permissions_dialog_image) glide.load(R.drawable.img_write_storage).transition(crossFade).into(view.write_permissions_dialog_image)
glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(view.write_permissions_dialog_image_sd) glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(view.write_permissions_dialog_image_sd)
} }
Mode.OPEN_DOCUMENT_TREE_SDK_30 -> { is Mode.OpenDocumentTreeSDK30 -> {
view.write_permissions_dialog_otg_text.setText(R.string.confirm_storage_access_android_text) view.write_permissions_dialog_otg_text.text = activity.getString(R.string.confirm_storage_access_android_text_specific, mode.path)
glide.load(R.drawable.img_write_storage_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image) glide.load(R.drawable.img_write_storage_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image)
view.write_permissions_dialog_otg_image.setOnClickListener { view.write_permissions_dialog_otg_image.setOnClickListener {
dialogConfirmed() dialogConfirmed()
} }
} }
Mode.CREATE_DOCUMENT_SDK_30 -> { Mode.CreateDocumentSDK30 -> {
view.write_permissions_dialog_otg_text.setText(R.string.confirm_create_doc_for_new_folder_text) view.write_permissions_dialog_otg_text.setText(R.string.confirm_create_doc_for_new_folder_text)
glide.load(R.drawable.img_write_storage_create_doc_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image) glide.load(R.drawable.img_write_storage_create_doc_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image)

View file

@ -125,7 +125,7 @@ fun BaseSimpleActivity.isShowingSAFDialog(path: String): Boolean {
return if ((!isRPlus() && isPathOnSD(path) && !isSDCardSetAsDefaultStorage() && (baseConfig.sdTreeUri.isEmpty() || !hasProperStoredTreeUri(false)))) { return if ((!isRPlus() && isPathOnSD(path) && !isSDCardSetAsDefaultStorage() && (baseConfig.sdTreeUri.isEmpty() || !hasProperStoredTreeUri(false)))) {
runOnUiThread { runOnUiThread {
if (!isDestroyed && !isFinishing) { if (!isDestroyed && !isFinishing) {
WritePermissionDialog(this, Mode.SD_CARD) { WritePermissionDialog(this, Mode.SdCard) {
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply { Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
putExtra(EXTRA_SHOW_ADVANCED, true) putExtra(EXTRA_SHOW_ADVANCED, true)
try { try {
@ -157,7 +157,7 @@ fun BaseSimpleActivity.isShowingSAFDialogSdk30(path: String): Boolean {
return if (isAccessibleWithSAFSdk30(path) && !hasProperStoredFirstParentUri(path)) { return if (isAccessibleWithSAFSdk30(path) && !hasProperStoredFirstParentUri(path)) {
runOnUiThread { runOnUiThread {
if (!isDestroyed && !isFinishing) { if (!isDestroyed && !isFinishing) {
WritePermissionDialog(this, Mode.OPEN_DOCUMENT_TREE_SDK_30) { WritePermissionDialog(this, Mode.OpenDocumentTreeSDK30(path.getFirstParentPath(this))) {
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply { Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
putExtra(EXTRA_SHOW_ADVANCED, true) putExtra(EXTRA_SHOW_ADVANCED, true)
putExtra(DocumentsContract.EXTRA_INITIAL_URI, createFirstParentTreeUriUsingRootTree(path)) putExtra(DocumentsContract.EXTRA_INITIAL_URI, createFirstParentTreeUriUsingRootTree(path))
@ -190,7 +190,7 @@ fun BaseSimpleActivity.isShowingSAFCreateDocumentDialogSdk30(path: String): Bool
return if (!hasProperStoredDocumentUriSdk30(path)) { return if (!hasProperStoredDocumentUriSdk30(path)) {
runOnUiThread { runOnUiThread {
if (!isDestroyed && !isFinishing) { if (!isDestroyed && !isFinishing) {
WritePermissionDialog(this, Mode.CREATE_DOCUMENT_SDK_30) { WritePermissionDialog(this, Mode.CreateDocumentSDK30) {
Intent(Intent.ACTION_CREATE_DOCUMENT).apply { Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
type = DocumentsContract.Document.MIME_TYPE_DIR type = DocumentsContract.Document.MIME_TYPE_DIR
putExtra(EXTRA_SHOW_ADVANCED, true) putExtra(EXTRA_SHOW_ADVANCED, true)
@ -267,7 +267,7 @@ fun BaseSimpleActivity.isShowingOTGDialog(path: String): Boolean {
fun BaseSimpleActivity.showOTGPermissionDialog(path: String) { fun BaseSimpleActivity.showOTGPermissionDialog(path: String) {
runOnUiThread { runOnUiThread {
if (!isDestroyed && !isFinishing) { if (!isDestroyed && !isFinishing) {
WritePermissionDialog(this, Mode.OTG) { WritePermissionDialog(this, Mode.Otg) {
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply { Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
try { try {
startActivityForResult(this, OPEN_DOCUMENT_TREE_OTG) startActivityForResult(this, OPEN_DOCUMENT_TREE_OTG)