diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index cf7ee98bf..1af9c13d0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -592,6 +592,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { folders.filter { !getDoesFilePathExist(it.absolutePath, OTGPath) }.forEach { 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) + } + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/FileDirItem.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/FileDirItem.kt index 726fcc8a9..c67eebabb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/FileDirItem.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/FileDirItem.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.gallery.pro.extensions -import android.os.Environment import com.simplemobiletools.commons.models.FileDirItem -fun FileDirItem.isDownloadsFolder() = path.equals(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(), true) +fun FileDirItem.isDownloadsFolder() = path.isDownloadsFolder() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt index 0d708ce1a..3a8eb02ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.gallery.pro.extensions import android.media.MediaMetadataRetriever +import android.os.Environment import com.simplemobiletools.commons.extensions.doesThisOrParentHaveNoMedia import com.simplemobiletools.commons.helpers.NOMEDIA import java.io.File @@ -70,3 +71,5 @@ fun String.getVideoDuration(): Int { } return seconds } + +fun String.isDownloadsFolder() = equals(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(), true)