From e54cadfbdc4d71c12c519d26010f02dec05d5621 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Tue, 4 Apr 2017 16:01:20 +0200 Subject: [PATCH] avoid deleting Downloads folder --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 2 +- .../simplemobiletools/gallery/activities/ViewPagerActivity.kt | 2 +- .../kotlin/com/simplemobiletools/gallery/extensions/file.kt | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) 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()