update deleted files from media screen manually
This commit is contained in:
parent
5df874ff43
commit
86d9652204
|
@ -199,6 +199,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteFiles(files: ArrayList<File>) {
|
override fun deleteFiles(files: ArrayList<File>) {
|
||||||
|
var deletedCnt = 0
|
||||||
files.filter { it.exists() && it.isImageVideoGif() }
|
files.filter { it.exists() && it.isImageVideoGif() }
|
||||||
.forEach {
|
.forEach {
|
||||||
if (needsStupidWritePermissions(it.absolutePath)) {
|
if (needsStupidWritePermissions(it.absolutePath)) {
|
||||||
|
@ -214,17 +215,25 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
} else {
|
} else {
|
||||||
it.delete()
|
it.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deleteFromMediaStore(it))
|
||||||
|
deletedCnt++
|
||||||
}
|
}
|
||||||
|
|
||||||
scanFiles(files) {
|
if (deletedCnt == files.size) {
|
||||||
if (mMedia.isEmpty()) {
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
updateMediaView()
|
updateMediaView()
|
||||||
|
} else {
|
||||||
|
scanFiles(files) {
|
||||||
|
updateMediaView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateMediaView() {
|
private fun updateMediaView() {
|
||||||
|
if (mMedia.isEmpty()) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
if (!isDirEmpty()) {
|
if (!isDirEmpty()) {
|
||||||
getMedia()
|
getMedia()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.ContentValues
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -9,6 +10,7 @@ import android.provider.MediaStore
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import com.simplemobiletools.filepicker.extensions.isImageSlow
|
||||||
import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions
|
import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.helpers.Config
|
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 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() {
|
fun showSystemUI() {
|
||||||
supportActionBar?.show()
|
supportActionBar?.show()
|
||||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.simplemobiletools.gallery.activities
|
package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ContentValues
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
|
@ -213,12 +212,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
val values = ContentValues()
|
val deleted = deleteFromMediaStore(file)
|
||||||
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
|
|
||||||
|
|
||||||
if (updated) {
|
if (deleted) {
|
||||||
reloadViewPager()
|
reloadViewPager()
|
||||||
} else {
|
} else {
|
||||||
scanFile(file) {
|
scanFile(file) {
|
||||||
|
|
Loading…
Reference in New Issue