From ff5019998dba6125d6d91ae9c8f6247a13ca34d5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 15 Jun 2022 12:20:53 +0200 Subject: [PATCH] pass the MediaStoreId with FileDirItems at deleting too --- .../pro/activities/ViewPagerActivity.kt | 7 +++--- .../gallery/pro/adapters/MediaAdapter.kt | 24 +++++++++---------- .../gallery/pro/models/Medium.kt | 3 +++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index ff4616c0c..574e61df1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index d51aeee05..34d53fee5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -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, 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(paths.size) - paths.forEach { - val curFileDirItem = File(it).toFileDirItem(activity) + val fileDirItems = ArrayList(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(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) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt index 9d6611cc5..0910b9bcd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt @@ -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) }