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 53a4ca619..dc636309e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -22,6 +22,9 @@ import com.simplemobiletools.gallery.helpers.GROUP_BY_NONE import com.simplemobiletools.gallery.helpers.GROUP_DESCENDING 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 java.util.* import kotlin.collections.ArrayList @@ -32,10 +35,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private val INSTANT_LOAD_DURATION = 2000L private val IMAGE_LOAD_DELAY = 100L + private val ITEM_SECTION = 0 + private val ITEM_MEDIUM = 1 private val config = activity.config private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST private var visibleItemPaths = ArrayList() + private var thumbnailItems = ArrayList() private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() @@ -70,15 +76,22 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { - val medium = media.getOrNull(position) ?: return - visibleItemPaths.add(medium.path) - val view = holder.bindView(medium, !allowMultiplePicks) { itemView, adapterPosition -> - setupView(itemView, medium) + val tmbItem = thumbnailItems.getOrNull(position) ?: return + if (tmbItem is ThumbnailMedium) { + visibleItemPaths.add(tmbItem.path) + } + + val view = holder.bindView(tmbItem, !allowMultiplePicks) { itemView, adapterPosition -> + if (tmbItem is ThumbnailMedium) { + setupThumbnailMedium(itemView, tmbItem) + } else { + setupThumbnailSection(itemView, tmbItem as ThumbnailSection) + } } bindViewHolder(holder, position, view) } - override fun getItemCount() = media.size + override fun getItemCount() = thumbnailItems.size override fun prepareActionMode(menu: Menu) { menu.apply { @@ -353,9 +366,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, sorted.forEach { key, value -> mediumGroups[key] = value } + + media.forEach { + val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) + thumbnailItems.add(thumbnailMedium) + } } - private fun setupView(view: View, medium: Medium) { + private fun setupThumbnailMedium(view: View, medium: ThumbnailMedium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) photo_name.beVisibleIf(displayFilenames || isListViewType) @@ -387,6 +405,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } + private fun setupThumbnailSection(view: View, section: ThumbnailSection) { + view.apply { + + } + } + interface MediaOperationsListener { fun refreshItems() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailItem.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailItem.kt new file mode 100644 index 000000000..f53c5df10 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailItem.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.gallery.models + +open class ThumbnailItem diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt new file mode 100644 index 000000000..c0703ed5f --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt @@ -0,0 +1,8 @@ +package com.simplemobiletools.gallery.models + +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() { + fun isVideo() = type == TYPE_VIDEOS +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailSection.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailSection.kt new file mode 100644 index 000000000..fc501383f --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailSection.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.gallery.models + +data class ThumbnailSection(val title: String) : ThumbnailItem()