update deleted files from media screen manually

This commit is contained in:
tibbi 2016-12-07 20:50:19 +01:00
parent 5df874ff43
commit 86d9652204
3 changed files with 24 additions and 10 deletions

View File

@ -199,6 +199,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
override fun deleteFiles(files: ArrayList<File>) {
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()
}

View File

@ -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

View File

@ -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) {