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() {
val fileDirItem = File(getCurrentPath()).toFileDirItem(this)
val fileDirItem = getCurrentMedium()?.toFileDirItem() ?: return
val size = fileDirItem.getProperSize(this, countHidden = true).formatSize()
val filename = "\"${getCurrentPath().getFilenameFromPath()}\""
val filenameAndSize = "$filename ($size)"
@ -1123,12 +1123,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun deleteConfirmed() {
val path = getCurrentMedia().getOrNull(mPos)?.path ?: return
val currentMedium = getCurrentMedium()
val path = currentMedium?.path ?: return
if (getIsPathDirectory(path) || !path.isMediaFile()) {
return
}
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
val fileDirItem = currentMedium.toFileDirItem()
if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) {
checkManageMediaOrHandleSAFDialogSdk30(fileDirItem.path) {
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_name
import kotlinx.android.synthetic.main.video_item_grid.view.medium_thumbnail
import java.io.File
class MediaAdapter(
activity: BaseSimpleActivity, var media: ArrayList<ThumbnailItem>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
@ -462,16 +461,17 @@ class MediaAdapter(
private fun askConfirmDelete() {
val itemsCnt = selectedKeys.size
val firstPath = getSelectedPaths().first()
val fileDirItem = File(firstPath).toFileDirItem(activity)
val selectedMedia = getSelectedItems()
val firstPath = selectedMedia.first().path
val fileDirItem = selectedMedia.first().toFileDirItem()
val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize()
val itemsAndSize = if (itemsCnt == 1) {
fileDirItem.mediaStoreId = selectedMedia.first().mediaStoreId
"\"${firstPath.getFilenameFromPath()}\" ($size)"
} else {
val paths = getSelectedPaths()
val fileDirItems = ArrayList<FileDirItem>(paths.size)
paths.forEach {
val curFileDirItem = File(it).toFileDirItem(activity)
val fileDirItems = ArrayList<FileDirItem>(selectedMedia.size)
selectedMedia.forEach { medium ->
val curFileDirItem = medium.toFileDirItem()
fileDirItems.add(curFileDirItem)
}
val fileSize = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize()
@ -501,8 +501,8 @@ class MediaAdapter(
return@handleSAFDialog
}
val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog
activity.checkManageMediaOrHandleSAFDialogSdk30(sdk30SafPath) {
val sdk30SAFPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog
activity.checkManageMediaOrHandleSAFDialogSdk30(sdk30SAFPath) {
if (!it) {
return@checkManageMediaOrHandleSAFDialogSdk30
}
@ -511,9 +511,9 @@ class MediaAdapter(
val removeMedia = ArrayList<Medium>(selectedKeys.size)
val positions = getSelectedItemPositions()
selectedItems.forEach {
fileDirItems.add(FileDirItem(it.path, it.name))
removeMedia.add(it)
selectedItems.forEach { medium ->
fileDirItems.add(medium.toFileDirItem())
removeMedia.add(medium)
}
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_PATH
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.pro.helpers.*
import java.io.File
import java.io.Serializable
@ -107,4 +108,6 @@ data class Medium(
}
fun getKey() = ObjectKey(getSignature())
fun toFileDirItem() = FileDirItem(path, name, false, 0, size, modified, mediaStoreId)
}