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 d9c674e9c..fdb2b876d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -319,7 +319,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller - MediaAdapter(this, media, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { + MediaAdapter(this, media, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller, mPath) { itemClicked((it as Medium).path) }.apply { setupZoomListener(mZoomListener) 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 c501eb471..3e40cc918 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -18,12 +18,15 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* +import com.simplemobiletools.gallery.helpers.GROUP_BY_NONE import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.photo_video_item_grid.view.* +import java.util.HashMap +import kotlin.collections.ArrayList class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, - val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, + val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, val path: String, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { private val INSTANT_LOAD_DURATION = 2000L @@ -36,6 +39,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() private val hasOTGConnected = activity.hasOTGConnected() + private var mediumGroups = HashMap>() private var scrollHorizontally = config.scrollHorizontally private var animateGifs = config.animateGifs @@ -44,6 +48,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, init { setupDragListener(true) + groupMedia() enableInstantLoad() } @@ -289,6 +294,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, currentMediaHash = newMedia.hashCode() Handler().postDelayed({ media = newMedia + groupMedia() enableInstantLoad() notifyDataSetChanged() finishActMode() @@ -325,6 +331,21 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, }, INSTANT_LOAD_DURATION) } + private fun groupMedia() { + val grouping = activity.config.getFolderGrouping(path) + if (grouping and GROUP_BY_NONE != 0) { + return + } + + media.forEach { + val key = it.getGroupingKey(grouping) + if (!mediumGroups.containsKey(key)) { + mediumGroups[key] = ArrayList() + } + mediumGroups[key]!!.add(it) + } + } + private fun setupView(view: View, medium: Medium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 3998ec75d..8a2fb0f4b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -62,7 +62,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c return shownMedia = media - val adapter = MediaAdapter(activity, media, null, true, false, view.media_grid) { + val adapter = MediaAdapter(activity, media, null, true, false, view.media_grid, null, path) { callback((it as Medium).path) dialog.dismiss() } 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 60e551038..e4441f6d5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -6,14 +6,12 @@ import android.arch.persistence.room.Index import android.arch.persistence.room.PrimaryKey import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize +import com.simplemobiletools.commons.extensions.getFilenameExtension 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_GIFS -import com.simplemobiletools.gallery.helpers.TYPE_IMAGES -import com.simplemobiletools.gallery.helpers.TYPE_RAWS -import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS +import com.simplemobiletools.gallery.helpers.* import java.io.Serializable @Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))]) @@ -47,4 +45,15 @@ data class Medium( sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate() else -> taken.formatDate() } + + fun getGroupingKey(groupBy: Int): String { + return when { + groupBy and GROUP_BY_LAST_MODIFIED != 0 -> modified.toString() + groupBy and GROUP_BY_DATE_TAKEN != 0 -> taken.toString() + groupBy and GROUP_BY_FILE_TYPE != 0 -> type.toString() + groupBy and GROUP_BY_EXTENSION != 0 -> name.getFilenameExtension().toLowerCase() + groupBy and GROUP_BY_FOLDER != 0 -> parentPath + else -> "" + } + } }