@@ -455,74 +455,78 @@ class ItemsAdapter(
455455 showFAB = true ,
456456 canAddShowHiddenButton = true ,
457457 showFavoritesButton = true
458- ) {
459- config.lastCopyPath = it
460- if (activity.isPathOnRoot(it ) || activity.isPathOnRoot(firstFile.path)) {
461- copyMoveRootItems(files, it , isCopyOperation)
458+ ) { destination ->
459+ config.lastCopyPath = destination
460+ if (activity.isPathOnRoot(destination ) || activity.isPathOnRoot(firstFile.path)) {
461+ copyMoveRootItems(files, destination , isCopyOperation)
462462 } else {
463463 activity.copyMoveFilesTo(
464464 fileDirItems = files,
465465 source = source,
466- destination = it ,
466+ destination = destination ,
467467 isCopyOperation = isCopyOperation,
468468 copyPhotoVideoOnly = false ,
469469 copyHidden = config.shouldShowHidden()
470470 ) {
471471 if (! isCopyOperation) {
472- ensureBackgroundThread {
473- val sourceFoldersToCheck = HashSet <String >()
474-
475- files.forEach { sourceFileDir ->
476- val sourcePath = sourceFileDir.path
477-
478- if (activity.getDoesFilePathExist(sourcePath)) {
479- activity.deleteFile(sourceFileDir, true ) {
480- val parentPath = sourcePath.getParentPath()
481- if (parentPath.isNotEmpty()) {
482- sourceFoldersToCheck.add(parentPath)
483- }
484- }
485- }
486- }
487-
488- sourceFoldersToCheck.forEach { folderPath ->
489- checkAndDeleteEmptyFolder(folderPath)
490- }
472+ cleanupAfterMove(files)
473+ } else {
474+ refreshUI()
475+ }
476+ }
477+ }
478+ }
479+ }
491480
492- activity.runOnUiThread {
493- listener?.refreshFragment()
494- finishActMode()
495- }
481+ private fun cleanupAfterMove (files : List <FileDirItem >) {
482+ ensureBackgroundThread {
483+ val foldersToCheck = HashSet <String >()
484+ files.forEach { fileItem ->
485+ val path = fileItem.path
486+ if (activity.getDoesFilePathExist(path)) {
487+ activity.deleteFile(fileItem, true ) {
488+ val parentPath = path.getParentPath()
489+ if (parentPath.isNotEmpty()) {
490+ foldersToCheck.add(parentPath)
496491 }
497- } else {
498- listener?.refreshFragment()
499- finishActMode()
500492 }
501493 }
502494 }
495+
496+ foldersToCheck.forEach { folderPath ->
497+ deleteEmptyFoldersRecursively(folderPath)
498+ }
499+
500+ refreshUI()
503501 }
504502 }
505503
506- private fun checkAndDeleteEmptyFolder (folderPath : String ) {
504+ private fun deleteEmptyFoldersRecursively (folderPath : String ) {
507505 if (! activity.getDoesFilePathExist(folderPath) || ! activity.getIsPathDirectory(folderPath)) {
508506 return
509507 }
510508
511509 val folder = File (folderPath)
512- val contents = folder.listFiles()
513-
514- if (contents == null || contents.isEmpty()) {
510+ val contents = folder.listFiles() ? : return
511+ if (contents.isEmpty()) {
515512 val parentPath = folderPath.getParentPath()
516513 val folderItem = folder.toFileDirItem(activity)
517514
518515 activity.deleteFile(folderItem, true ) {
519516 if (parentPath.isNotEmpty()) {
520- checkAndDeleteEmptyFolder (parentPath)
517+ deleteEmptyFoldersRecursively (parentPath)
521518 }
522519 }
523520 }
524521 }
525522
523+ private fun refreshUI () {
524+ activity.runOnUiThread {
525+ listener?.refreshFragment()
526+ finishActMode()
527+ }
528+ }
529+
526530 private fun copyMoveRootItems (
527531 files : ArrayList <FileDirItem >,
528532 destinationPath : String ,
0 commit comments