call handleSAFDialog result at fail too
This commit is contained in:
parent
43835b57fa
commit
089d53679f
7 changed files with 54 additions and 11 deletions
|
@ -274,6 +274,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
// synchronous return value determines only if we are showing the SAF dialog, callback result tells if the SD or OTG permission has been granted
|
||||
fun handleSAFDialog(path: String, callback: (success: Boolean) -> Unit): Boolean {
|
||||
return if (!packageName.startsWith("com.simplemobiletools")) {
|
||||
callback(true)
|
||||
|
@ -322,6 +323,11 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
handleSAFDialog(destination) {
|
||||
if (!it) {
|
||||
copyMoveListener.copyFailed()
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
showCopyMoveToasts = showToasts
|
||||
copyMoveCallback = callback
|
||||
var fileCountToCopy = fileDirItems.size
|
||||
|
@ -330,7 +336,9 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
} else {
|
||||
if (isPathOnOTG(source) || isPathOnOTG(destination) || isPathOnSD(source) || isPathOnSD(destination) || fileDirItems.first().isDirectory) {
|
||||
handleSAFDialog(source) {
|
||||
startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden, showToasts)
|
||||
if (it) {
|
||||
startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden, showToasts)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
|
|
@ -43,15 +43,17 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String,
|
|||
try {
|
||||
when {
|
||||
activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(path) {
|
||||
try {
|
||||
val documentFile = activity.getDocumentFile(path.getParentPath())
|
||||
if (documentFile?.createDirectory(path.getFilenameFromPath()) != null) {
|
||||
sendSuccess(alertDialog, path)
|
||||
} else {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
if (it) {
|
||||
try {
|
||||
val documentFile = activity.getDocumentFile(path.getParentPath())
|
||||
if (documentFile?.createDirectory(path.getFilenameFromPath()) != null) {
|
||||
sendSuccess(alertDialog, path)
|
||||
} else {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
} catch (e: SecurityException) {
|
||||
activity.showErrorToast(e)
|
||||
}
|
||||
} catch (e: SecurityException) {
|
||||
activity.showErrorToast(e)
|
||||
}
|
||||
}
|
||||
File(path).mkdirs() -> sendSuccess(alertDialog, path)
|
||||
|
|
|
@ -47,6 +47,10 @@ class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList<S
|
|||
}
|
||||
|
||||
activity.handleSAFDialog(sdFilePath) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
ignoreClicks = true
|
||||
var pathsCnt = validPaths.size
|
||||
for (path in validPaths) {
|
||||
|
|
|
@ -28,7 +28,10 @@ class WritePermissionDialog(activity: Activity, val isOTG: Boolean, val callback
|
|||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||
.setOnCancelListener { BaseSimpleActivity.funAfterSAFPermission = null }
|
||||
.setOnCancelListener {
|
||||
BaseSimpleActivity.funAfterSAFPermission?.invoke(false)
|
||||
BaseSimpleActivity.funAfterSAFPermission = null
|
||||
}
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.confirm_storage_access_title)
|
||||
}
|
||||
|
|
|
@ -392,6 +392,10 @@ fun BaseSimpleActivity.deleteFoldersBg(folders: ArrayList<FileDirItem>, deleteMe
|
|||
}
|
||||
|
||||
handleSAFDialog(needPermissionForPath) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
folders.forEachIndexed { index, folder ->
|
||||
deleteFolderBg(folder, deleteMediaOnly) {
|
||||
if (it)
|
||||
|
@ -454,6 +458,10 @@ fun BaseSimpleActivity.deleteFilesBg(files: ArrayList<FileDirItem>, allowDeleteF
|
|||
|
||||
var wasSuccess = false
|
||||
handleSAFDialog(files[0].path) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
files.forEachIndexed { index, file ->
|
||||
deleteFileBg(file, allowDeleteFolder) {
|
||||
if (it) {
|
||||
|
@ -498,7 +506,9 @@ fun BaseSimpleActivity.deleteFileBg(fileDirItem: FileDirItem, allowDeleteFolder:
|
|||
if (!fileDeleted) {
|
||||
if (needsStupidWritePermissions(path)) {
|
||||
handleSAFDialog(path) {
|
||||
trySAFFileDelete(fileDirItem, allowDeleteFolder, callback)
|
||||
if (it) {
|
||||
trySAFFileDelete(fileDirItem, allowDeleteFolder, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -539,6 +549,10 @@ fun Activity.rescanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = nul
|
|||
fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: ((success: Boolean) -> Unit)? = null) {
|
||||
if (needsStupidWritePermissions(newPath)) {
|
||||
handleSAFDialog(newPath) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
val document = getSomeDocumentFile(oldPath)
|
||||
if (document == null || (File(oldPath).isDirectory != document.isDirectory)) {
|
||||
runOnUiThread {
|
||||
|
@ -618,6 +632,10 @@ fun Activity.hideKeyboard(view: View) {
|
|||
fun BaseSimpleActivity.getFileOutputStream(fileDirItem: FileDirItem, allowCreatingNewFile: Boolean = false, callback: (outputStream: OutputStream?) -> Unit) {
|
||||
if (needsStupidWritePermissions(fileDirItem.path)) {
|
||||
handleSAFDialog(fileDirItem.path) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
var document = getDocumentFile(fileDirItem.path)
|
||||
if (document == null && allowCreatingNewFile) {
|
||||
document = getDocumentFile(fileDirItem.getParentPath())
|
||||
|
|
|
@ -52,6 +52,10 @@ class RenamePatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(c
|
|||
|
||||
activity?.baseConfig?.lastRenamePatternUsed = rename_items_value.value
|
||||
activity?.handleSAFDialog(sdFilePath) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
ignoreClicks = true
|
||||
var currentIncrementalNumber = 1
|
||||
var pathsCnt = validPaths.size
|
||||
|
|
|
@ -46,6 +46,10 @@ class RenameSimpleTab(context: Context, attrs: AttributeSet) : RelativeLayout(co
|
|||
}
|
||||
|
||||
activity?.handleSAFDialog(sdFilePath) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
ignoreClicks = true
|
||||
var pathsCnt = validPaths.size
|
||||
for (path in validPaths) {
|
||||
|
|
Loading…
Reference in a new issue