avoid deleting Downloads folder

This commit is contained in:
Tibor Kaputa 2017-04-04 16:01:20 +02:00
parent 0960897225
commit e54cadfbdc
3 changed files with 5 additions and 2 deletions

View file

@ -207,7 +207,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun deleteDirectoryIfEmpty() { private fun deleteDirectoryIfEmpty() {
val file = File(mPath) val file = File(mPath)
if (file.isDirectory && file.listFiles()?.isEmpty() == true) { if (!file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) {
file.delete() file.delete()
} }
} }

View file

@ -431,7 +431,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun deleteDirectoryIfEmpty() { private fun deleteDirectoryIfEmpty() {
val file = File(mDirectory) val file = File(mDirectory)
if (file.isDirectory && file.listFiles()?.isEmpty() == true) { if (!file.isDownloadsFolder() && file.isDirectory && file.listFiles()?.isEmpty() == true) {
file.delete() file.delete()
} }

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.extensions package com.simplemobiletools.gallery.extensions
import android.graphics.Bitmap import android.graphics.Bitmap
import android.os.Environment
import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.helpers.NOMEDIA
import java.io.File import java.io.File
@ -13,3 +14,5 @@ fun File.getCompressionFormat(): Bitmap.CompressFormat {
} }
fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists() fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists()
fun File.isDownloadsFolder() = absolutePath == Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()