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 6e9ddcddf..eb43adbfb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -40,7 +40,6 @@ import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium -import com.simplemobiletools.gallery.models.ThumbnailMedium import kotlinx.android.synthetic.main.activity_media.* import java.io.File import java.io.IOException @@ -319,10 +318,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mGroupedMedia.clear() val groupedMedia = MediaFetcher(applicationContext).groupMedia(mMedia.clone() as ArrayList, mPath) - groupedMedia.filter { it is ThumbnailMedium }.forEach { - it as ThumbnailMedium - val medium = Medium(0L, it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - mGroupedMedia.add(medium) + groupedMedia.filter { it is Medium }.forEach { + mGroupedMedia.add(it as Medium) } val currAdapter = media_grid.adapter @@ -330,7 +327,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller MediaAdapter(this, groupedMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { - itemClicked((it as ThumbnailMedium).path) + itemClicked((it as Medium).path) }.apply { setupZoomListener(mZoomListener) media_grid.adapter = this 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 6055e3893..f20d59461 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -19,8 +19,8 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST +import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem -import com.simplemobiletools.gallery.models.ThumbnailMedium import com.simplemobiletools.gallery.models.ThumbnailSection import kotlinx.android.synthetic.main.photo_video_item_grid.view.* import kotlinx.android.synthetic.main.thumbnail_section.view.* @@ -77,15 +77,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList - if (tmbItem is ThumbnailMedium) { - setupThumbnailMedium(itemView, tmbItem) + if (tmbItem is Medium) { + setupThumbnail(itemView, tmbItem) } else { - setupThumbnailSection(itemView, tmbItem as ThumbnailSection) + setupSection(itemView, tmbItem as ThumbnailSection) } } bindViewHolder(holder, position, view) @@ -137,7 +137,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList(selectedPositions.size) - val removeMedia = ArrayList(selectedPositions.size) + val removeMedia = ArrayList(selectedPositions.size) if (media.size <= selectedPositions.first()) { finishActMode() return } - val SAFPath = (media[selectedPositions.first()] as ThumbnailMedium).path + val SAFPath = (media[selectedPositions.first()] as Medium).path activity.handleSAFDialog(SAFPath) { selectedPositions.sortedDescending().forEach { val thumbnailItem = media[it] - if (thumbnailItem is ThumbnailMedium) { + if (thumbnailItem is Medium) { fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name)) removeMedia.add(thumbnailItem) } @@ -316,10 +316,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList { - val selectedMedia = ArrayList(selectedPositions.size) + private fun getSelectedMedia(): List { + val selectedMedia = ArrayList(selectedPositions.size) selectedPositions.forEach { - selectedMedia.add(media[it] as ThumbnailMedium) + selectedMedia.add(media[it] as Medium) } return selectedMedia } @@ -367,29 +367,29 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, path: String): ArrayList { - val thumbnailItems = ArrayList() val mediumGroups = LinkedHashMap>() val currentGrouping = context.config.getFolderGrouping(path) if (currentGrouping and GROUP_BY_NONE != 0) { - media.forEach { - val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - thumbnailItems.add(thumbnailMedium) - } - return thumbnailItems + return media as ArrayList } media.forEach { @@ -363,12 +357,10 @@ class MediaFetcher(val context: Context) { mediumGroups[key] = value } + val thumbnailItems = ArrayList() for ((key, value) in mediumGroups) { thumbnailItems.add(ThumbnailSection(getFormattedKey(key, currentGrouping))) - value.forEach { - val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - thumbnailItems.add(thumbnailMedium) - } + thumbnailItems.addAll(value) } return thumbnailItems diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 1097f935f..66ce260fe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -25,7 +25,7 @@ data class Medium( @ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "size") val size: Long, @ColumnInfo(name = "type") val type: Int, - @ColumnInfo(name = "is_favorite") var isFavorite: Boolean) : Serializable { + @ColumnInfo(name = "is_favorite") var isFavorite: Boolean) : Serializable, ThumbnailItem() { companion object { private const val serialVersionUID = -6553149366975455L diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt deleted file mode 100644 index 56124f2a3..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt +++ /dev/null @@ -1,22 +0,0 @@ -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, 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() - } -}