do not show an error at renaming a single SD card file if it succeeds

This commit is contained in:
tibbi 2019-08-01 18:17:24 +02:00
parent 382ea5b2c0
commit 371f88fe36
2 changed files with 12 additions and 14 deletions

View file

@ -541,21 +541,19 @@ fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: ((
}
try {
val uri = DocumentsContract.renameDocument(applicationContext.contentResolver, document.uri, newPath.getFilenameFromPath())
if (document.uri != uri) {
updateInMediaStore(oldPath, newPath)
rescanPaths(arrayListOf(oldPath, newPath)) {
if (!baseConfig.keepLastModified) {
updateLastModified(newPath, System.currentTimeMillis())
}
deleteFromMediaStore(oldPath)
runOnUiThread {
callback?.invoke(true)
}
try {
DocumentsContract.renameDocument(applicationContext.contentResolver, document.uri, newPath.getFilenameFromPath())
} catch (ignored: FileNotFoundException) {
// FileNotFoundException is thrown in some weird cases, but renaming works just fine
}
updateInMediaStore(oldPath, newPath)
rescanPaths(arrayListOf(oldPath, newPath)) {
if (!baseConfig.keepLastModified) {
updateLastModified(newPath, System.currentTimeMillis())
}
} else {
deleteFromMediaStore(oldPath)
runOnUiThread {
callback?.invoke(false)
callback?.invoke(true)
}
}
} catch (e: Exception) {

View file

@ -221,7 +221,7 @@ fun Context.getDocumentFile(path: String): DocumentFile? {
for (part in parts) {
document = document?.findFile(part)
}
return document
document
} catch (ignored: Exception) {
null
}