try renaming files only if the permission has been granted

This commit is contained in:
tibbi 2021-12-19 18:48:57 +01:00
parent 39350e0a86
commit 7266618cd2

View file

@ -798,16 +798,20 @@ fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: ((
} catch (exception: Exception) {
if (isRPlus() && exception is java.nio.file.FileSystemException) {
val fileUris = getFileUrisFromFileDirItems(arrayListOf(File(oldPath).toFileDirItem(this)))
updateSDK30Uris(fileUris) {
val values = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, newPath.getFilenameFromPath())
}
updateSDK30Uris(fileUris) { success ->
if (success ) {
val values = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, newPath.getFilenameFromPath())
}
try {
contentResolver.update(fileUris.first(), values, null, null)
callback?.invoke(true)
} catch (e: Exception) {
showErrorToast(e)
try {
contentResolver.update(fileUris.first(), values, null, null)
callback?.invoke(true)
} catch (e: Exception) {
showErrorToast(e)
callback?.invoke(false)
}
} else {
callback?.invoke(false)
}
}