pass the MediaStoreId with FileDirItems at deleting too

This commit is contained in:
tibbi 2022-06-15 12:20:53 +02:00
parent 87b4bdc6b3
commit ff5019998d
3 changed files with 19 additions and 15 deletions

View file

@ -1104,7 +1104,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun askConfirmDelete() { private fun askConfirmDelete() {
val fileDirItem = File(getCurrentPath()).toFileDirItem(this) val fileDirItem = getCurrentMedium()?.toFileDirItem() ?: return
val size = fileDirItem.getProperSize(this, countHidden = true).formatSize() val size = fileDirItem.getProperSize(this, countHidden = true).formatSize()
val filename = "\"${getCurrentPath().getFilenameFromPath()}\"" val filename = "\"${getCurrentPath().getFilenameFromPath()}\""
val filenameAndSize = "$filename ($size)" val filenameAndSize = "$filename ($size)"
@ -1123,12 +1123,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun deleteConfirmed() { private fun deleteConfirmed() {
val path = getCurrentMedia().getOrNull(mPos)?.path ?: return val currentMedium = getCurrentMedium()
val path = currentMedium?.path ?: return
if (getIsPathDirectory(path) || !path.isMediaFile()) { if (getIsPathDirectory(path) || !path.isMediaFile()) {
return return
} }
val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) val fileDirItem = currentMedium.toFileDirItem()
if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) {
checkManageMediaOrHandleSAFDialogSdk30(fileDirItem.path) { checkManageMediaOrHandleSAFDialogSdk30(fileDirItem.path) {
if (!it) { if (!it) {

View file

@ -38,7 +38,6 @@ import kotlinx.android.synthetic.main.video_item_grid.view.media_item_holder
import kotlinx.android.synthetic.main.video_item_grid.view.medium_check import kotlinx.android.synthetic.main.video_item_grid.view.medium_check
import kotlinx.android.synthetic.main.video_item_grid.view.medium_name import kotlinx.android.synthetic.main.video_item_grid.view.medium_name
import kotlinx.android.synthetic.main.video_item_grid.view.medium_thumbnail import kotlinx.android.synthetic.main.video_item_grid.view.medium_thumbnail
import java.io.File
class MediaAdapter( class MediaAdapter(
activity: BaseSimpleActivity, var media: ArrayList<ThumbnailItem>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, activity: BaseSimpleActivity, var media: ArrayList<ThumbnailItem>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
@ -462,16 +461,17 @@ class MediaAdapter(
private fun askConfirmDelete() { private fun askConfirmDelete() {
val itemsCnt = selectedKeys.size val itemsCnt = selectedKeys.size
val firstPath = getSelectedPaths().first() val selectedMedia = getSelectedItems()
val fileDirItem = File(firstPath).toFileDirItem(activity) val firstPath = selectedMedia.first().path
val fileDirItem = selectedMedia.first().toFileDirItem()
val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize() val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize()
val itemsAndSize = if (itemsCnt == 1) { val itemsAndSize = if (itemsCnt == 1) {
fileDirItem.mediaStoreId = selectedMedia.first().mediaStoreId
"\"${firstPath.getFilenameFromPath()}\" ($size)" "\"${firstPath.getFilenameFromPath()}\" ($size)"
} else { } else {
val paths = getSelectedPaths() val fileDirItems = ArrayList<FileDirItem>(selectedMedia.size)
val fileDirItems = ArrayList<FileDirItem>(paths.size) selectedMedia.forEach { medium ->
paths.forEach { val curFileDirItem = medium.toFileDirItem()
val curFileDirItem = File(it).toFileDirItem(activity)
fileDirItems.add(curFileDirItem) fileDirItems.add(curFileDirItem)
} }
val fileSize = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() val fileSize = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize()
@ -501,8 +501,8 @@ class MediaAdapter(
return@handleSAFDialog return@handleSAFDialog
} }
val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog val sdk30SAFPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog
activity.checkManageMediaOrHandleSAFDialogSdk30(sdk30SafPath) { activity.checkManageMediaOrHandleSAFDialogSdk30(sdk30SAFPath) {
if (!it) { if (!it) {
return@checkManageMediaOrHandleSAFDialogSdk30 return@checkManageMediaOrHandleSAFDialogSdk30
} }
@ -511,9 +511,9 @@ class MediaAdapter(
val removeMedia = ArrayList<Medium>(selectedKeys.size) val removeMedia = ArrayList<Medium>(selectedKeys.size)
val positions = getSelectedItemPositions() val positions = getSelectedItemPositions()
selectedItems.forEach { selectedItems.forEach { medium ->
fileDirItems.add(FileDirItem(it.path, it.name)) fileDirItems.add(medium.toFileDirItem())
removeMedia.add(it) removeMedia.add(medium)
} }
media.removeAll(removeMedia) media.removeAll(removeMedia)

View file

@ -8,6 +8,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.commons.helpers.SORT_BY_NAME import com.simplemobiletools.commons.helpers.SORT_BY_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_PATH
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.helpers.*
import java.io.File import java.io.File
import java.io.Serializable import java.io.Serializable
@ -107,4 +108,6 @@ data class Medium(
} }
fun getKey() = ObjectKey(getSignature()) fun getKey() = ObjectKey(getSignature())
fun toFileDirItem() = FileDirItem(path, name, false, 0, size, modified, mediaStoreId)
} }