fix #1668, properly delete empty folders when appropriate

This commit is contained in:
tibbi 2020-01-02 17:37:41 +01:00
parent fbb20477d6
commit 6234050c7f
3 changed files with 10 additions and 2 deletions

View file

@ -592,6 +592,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
folders.filter { !getDoesFilePathExist(it.absolutePath, OTGPath) }.forEach { folders.filter { !getDoesFilePathExist(it.absolutePath, OTGPath) }.forEach {
mDirectoryDao.deleteDirPath(it.absolutePath) mDirectoryDao.deleteDirPath(it.absolutePath)
} }
if (config.deleteEmptyFolders) {
folders.filter { !it.absolutePath.isDownloadsFolder() && it.isDirectory && it.toFileDirItem(this).getProperFileCount(this, true) == 0 }.forEach {
tryDeleteFileDirItem(it.toFileDirItem(this), true, true)
}
}
} }
} }
} }

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery.pro.extensions package com.simplemobiletools.gallery.pro.extensions
import android.os.Environment
import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.FileDirItem
fun FileDirItem.isDownloadsFolder() = path.equals(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(), true) fun FileDirItem.isDownloadsFolder() = path.isDownloadsFolder()

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.pro.extensions package com.simplemobiletools.gallery.pro.extensions
import android.media.MediaMetadataRetriever import android.media.MediaMetadataRetriever
import android.os.Environment
import com.simplemobiletools.commons.extensions.doesThisOrParentHaveNoMedia import com.simplemobiletools.commons.extensions.doesThisOrParentHaveNoMedia
import com.simplemobiletools.commons.helpers.NOMEDIA import com.simplemobiletools.commons.helpers.NOMEDIA
import java.io.File import java.io.File
@ -70,3 +71,5 @@ fun String.getVideoDuration(): Int {
} }
return seconds return seconds
} }
fun String.isDownloadsFolder() = equals(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(), true)