do not show an error at renaming a single SD card file if it succeeds
This commit is contained in:
parent
382ea5b2c0
commit
371f88fe36
2 changed files with 12 additions and 14 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue