From 6234050c7f876d8b0f8c8f50acc39cd156c5d69f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 2 Jan 2020 17:37:41 +0100 Subject: [PATCH] fix #1668, properly delete empty folders when appropriate --- .../gallery/pro/activities/MainActivity.kt | 6 ++++++ .../simplemobiletools/gallery/pro/extensions/FileDirItem.kt | 3 +-- .../com/simplemobiletools/gallery/pro/extensions/String.kt | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) 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)