diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index c2afe97bc..f570be0e8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -356,7 +356,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - private fun getBubbleTextItem(index: Int, sorting: Int) = getMediaAdapter()?.media?.getOrNull(index)?.getBubbleText(sorting) ?: "" + private fun getBubbleTextItem(index: Int, sorting: Int) = getMediaAdapter()?.getItemBubbleText(index, sorting) ?: "" private fun checkLastMediaChanged() { if (isActivityDestroyed()) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index d6db52d6b..4e0fadde2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -321,7 +321,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_open_with -> openPath(getCurrentPath(), true) R.id.menu_hide -> toggleFileVisibility(true) R.id.menu_unhide -> toggleFileVisibility(false) - R.id.menu_share -> shareMedium(getCurrentMedium()!!) + R.id.menu_share -> shareMediumPath(getCurrentPath()) R.id.menu_delete -> checkDeleteConfirmation() R.id.menu_rename -> renameFile() R.id.menu_edit -> openEditor(getCurrentPath()) @@ -769,7 +769,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } bottom_share.setOnClickListener { - shareMedium(getCurrentMedium()!!) + shareMediumPath(getCurrentPath()) } bottom_delete.setOnClickListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index ef03e9aa0..3273a7d7f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -166,7 +166,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun checkHideBtnVisibility(menu: Menu) { var hiddenCnt = 0 var unhiddenCnt = 0 - selectedPositions.mapNotNull { media.getOrNull(it) }.forEach { + getSelectedMedia().forEach { if (it.name.startsWith('.')) { hiddenCnt++ } else { @@ -181,7 +181,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun checkFavoriteBtnVisibility(menu: Menu) { var favoriteCnt = 0 var nonFavoriteCnt = 0 - selectedPositions.mapNotNull { media.getOrNull(it) }.forEach { + getSelectedMedia().forEach { if (it.isFavorite) { favoriteCnt++ } else { @@ -194,16 +194,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } private fun confirmSelection() { - val paths = getSelectedMedia().map { it.path } as ArrayList - listener?.selectedPaths(paths) + listener?.selectedPaths(getSelectedPaths()) } private fun showProperties() { if (selectedPositions.size <= 1) { - PropertiesDialog(activity, media[selectedPositions.first()].path, config.shouldShowHidden) + PropertiesDialog(activity, (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path, config.shouldShowHidden) } else { - val paths = ArrayList() - selectedPositions.forEach { paths.add(media[it].path) } + val paths = getSelectedPaths() PropertiesDialog(activity, paths, config.shouldShowHidden) } } @@ -255,17 +253,19 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun shareMedia() { if (selectedPositions.size == 1 && selectedPositions.first() != -1) { - activity.shareMedium(getSelectedMedia()[0]) + activity.shareMediumPath(getSelectedMedia().first().path) } else if (selectedPositions.size > 1) { - activity.shareMedia(getSelectedMedia()) + activity.shareMediaPaths(getSelectedPaths()) } } private fun copyMoveTo(isCopyOperation: Boolean) { - val paths = ArrayList() - selectedPositions.forEach { paths.add(media[it].path) } + val paths = getSelectedPaths() + + val fileDirItems = paths.map { + FileDirItem(it, it.getFilenameFromPath()) + } as ArrayList - val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) { config.tempFolderPath = "" activity.applicationContext.rescanFolderMedia(it) @@ -293,7 +293,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - private fun getCurrentPath() = media[selectedPositions.first()].path + private fun getCurrentPath() = (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path private fun deleteFiles() { if (selectedPositions.isEmpty()) { @@ -301,33 +301,39 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } val fileDirItems = ArrayList(selectedPositions.size) - val removeMedia = ArrayList(selectedPositions.size) + val removeMedia = ArrayList(selectedPositions.size) - if (media.size <= selectedPositions.first()) { + if (thumbnailItems.size <= selectedPositions.first()) { finishActMode() return } - val SAFPath = media[selectedPositions.first()].path + val SAFPath = (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path activity.handleSAFDialog(SAFPath) { selectedPositions.sortedDescending().forEach { - val medium = media[it] - fileDirItems.add(FileDirItem(medium.path, medium.name)) - removeMedia.add(medium) + val thumbnailItem = thumbnailItems[it] + if (thumbnailItem is ThumbnailMedium) { + fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name)) + removeMedia.add(thumbnailItem) + } } - media.removeAll(removeMedia) + thumbnailItems.removeAll(removeMedia) listener?.tryDeleteFiles(fileDirItems) removeSelectedItems() } } - private fun getSelectedMedia(): List { - val selectedMedia = ArrayList(selectedPositions.size) - selectedPositions.forEach { selectedMedia.add(media[it]) } + private fun getSelectedMedia(): List { + val selectedMedia = ArrayList(selectedPositions.size) + selectedPositions.forEach { + selectedMedia.add(thumbnailItems[it] as ThumbnailMedium) + } return selectedMedia } + private fun getSelectedPaths() = getSelectedMedia().map { it.path } as ArrayList + fun updateMedia(newMedia: ArrayList) { if (newMedia.hashCode() != currentMediaHash || currentGrouping != config.getFolderGrouping(path)) { currentMediaHash = newMedia.hashCode() @@ -432,6 +438,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, return activity.getString(stringId) } + fun getItemBubbleText(position: Int, sorting: Int) = (thumbnailItems[position] as? ThumbnailMedium)?.getBubbleText(sorting) + private fun setupThumbnailMedium(view: View, medium: ThumbnailMedium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index e9ae79e4e..48ae4e495 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -15,7 +15,6 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog import com.simplemobiletools.gallery.helpers.NOMEDIA -import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.* @@ -27,12 +26,11 @@ fun Activity.sharePaths(paths: ArrayList) { sharePathsIntent(paths, BuildConfig.APPLICATION_ID) } -fun Activity.shareMedium(medium: Medium) { - sharePath(medium.path) +fun Activity.shareMediumPath(path: String) { + sharePath(path) } -fun Activity.shareMedia(media: List) { - val paths = media.map { it.path } as ArrayList +fun Activity.shareMediaPaths(paths: ArrayList) { sharePaths(paths) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt index c0703ed5f..56124f2a3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt @@ -1,8 +1,22 @@ package com.simplemobiletools.gallery.models +import com.simplemobiletools.commons.extensions.formatDate +import com.simplemobiletools.commons.extensions.formatSize +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.gallery.helpers.TYPE_VIDEOS data class ThumbnailMedium(val name: String, val path: String, val parentPath: String, val modified: Long, val taken: Long, val size: Long, - val type: Int, val isFavorite: Boolean) : ThumbnailItem() { + val type: Int, var isFavorite: Boolean) : ThumbnailItem() { fun isVideo() = type == TYPE_VIDEOS + + fun getBubbleText(sorting: Int) = when { + sorting and SORT_BY_NAME != 0 -> name + sorting and SORT_BY_PATH != 0 -> path + sorting and SORT_BY_SIZE != 0 -> size.formatSize() + sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate() + else -> taken.formatDate() + } }