diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index dfaa19ccf..5ae2904ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -207,7 +207,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun deleteDirectoryIfEmpty() { val file = File(mPath) - if (file.isDirectory && file.listFiles()?.isEmpty() == true) { + if (!file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) { file.delete() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index b44898be0..7169d878b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -431,7 +431,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteDirectoryIfEmpty() { val file = File(mDirectory) - if (file.isDirectory && file.listFiles()?.isEmpty() == true) { + if (!file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) { file.delete() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt index b990dfc56..a2156588c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.gallery.extensions import android.graphics.Bitmap +import android.os.Environment import com.simplemobiletools.gallery.helpers.NOMEDIA import java.io.File @@ -13,3 +14,5 @@ fun File.getCompressionFormat(): Bitmap.CompressFormat { } fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists() + +fun File.isDownloadsFolder() = absolutePath == Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()