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 aa4c60771..2563d84bf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -199,6 +199,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } override fun deleteFiles(files: ArrayList) { + var deletedCnt = 0 files.filter { it.exists() && it.isImageVideoGif() } .forEach { if (needsStupidWritePermissions(it.absolutePath)) { @@ -214,17 +215,25 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } else { it.delete() } + + if (deleteFromMediaStore(it)) + deletedCnt++ } - scanFiles(files) { - if (mMedia.isEmpty()) { - finish() - } + if (deletedCnt == files.size) { updateMediaView() + } else { + scanFiles(files) { + updateMediaView() + } } } private fun updateMediaView() { + if (mMedia.isEmpty()) { + finish() + } + if (!isDirEmpty()) { getMedia() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt index c7585dd98..9aa3b6d49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.activities import android.annotation.TargetApi import android.app.Activity +import android.content.ContentValues import android.content.Intent import android.os.Build import android.os.Bundle @@ -9,6 +10,7 @@ import android.provider.MediaStore import android.support.v7.app.AppCompatActivity import android.view.MenuItem import android.view.View +import com.simplemobiletools.filepicker.extensions.isImageSlow import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.helpers.Config @@ -68,6 +70,13 @@ open class SimpleActivity : AppCompatActivity() { fun isShowingPermDialog(file: File) = isShowingWritePermissions(file, mConfig.treeUri, OPEN_DOCUMENT_TREE) + fun deleteFromMediaStore(file: File): Boolean { + val values = ContentValues() + values.put(MediaStore.MediaColumns.DATA, file.absolutePath) + val uri = if (file.isImageSlow()) MediaStore.Images.Media.EXTERNAL_CONTENT_URI else MediaStore.Video.Media.EXTERNAL_CONTENT_URI + return contentResolver.delete(uri, "${MediaStore.MediaColumns.DATA} = '${file.absolutePath}'", null) == 1 + } + fun showSystemUI() { supportActionBar?.show() window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or 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 58cef5980..c32ea4af9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.gallery.activities import android.app.Activity -import android.content.ContentValues import android.content.Intent import android.content.res.Configuration import android.database.Cursor @@ -213,12 +212,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View file.delete() } - val values = ContentValues() - values.put(MediaStore.MediaColumns.DATA, file.absolutePath) - val uri = if (file.isImageSlow()) MediaStore.Images.Media.EXTERNAL_CONTENT_URI else MediaStore.Video.Media.EXTERNAL_CONTENT_URI - val updated = contentResolver.delete(uri, "${MediaStore.MediaColumns.DATA} = '${file.absolutePath}'", null) == 1 + val deleted = deleteFromMediaStore(file) - if (updated) { + if (deleted) { reloadViewPager() } else { scanFile(file) {