mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-27 06:57:59 +01:00
handle medium grouping at the MediaAdapter
This commit is contained in:
parent
1a04a98040
commit
9eedf64c1b
4 changed files with 37 additions and 7 deletions
|
@ -319,7 +319,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
initZoomListener()
|
initZoomListener()
|
||||||
val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller
|
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)
|
itemClicked((it as Medium).path)
|
||||||
}.apply {
|
}.apply {
|
||||||
setupZoomListener(mZoomListener)
|
setupZoomListener(mZoomListener)
|
||||||
|
|
|
@ -18,12 +18,15 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog
|
import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
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.helpers.VIEW_TYPE_LIST
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.photo_video_item_grid.view.*
|
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<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
|
class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>, 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) {
|
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||||
|
|
||||||
private val INSTANT_LOAD_DURATION = 2000L
|
private val INSTANT_LOAD_DURATION = 2000L
|
||||||
|
@ -36,6 +39,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
private var delayHandler = Handler(Looper.getMainLooper())
|
private var delayHandler = Handler(Looper.getMainLooper())
|
||||||
private var currentMediaHash = media.hashCode()
|
private var currentMediaHash = media.hashCode()
|
||||||
private val hasOTGConnected = activity.hasOTGConnected()
|
private val hasOTGConnected = activity.hasOTGConnected()
|
||||||
|
private var mediumGroups = HashMap<String, ArrayList<Medium>>()
|
||||||
|
|
||||||
private var scrollHorizontally = config.scrollHorizontally
|
private var scrollHorizontally = config.scrollHorizontally
|
||||||
private var animateGifs = config.animateGifs
|
private var animateGifs = config.animateGifs
|
||||||
|
@ -44,6 +48,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setupDragListener(true)
|
setupDragListener(true)
|
||||||
|
groupMedia()
|
||||||
enableInstantLoad()
|
enableInstantLoad()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +294,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
currentMediaHash = newMedia.hashCode()
|
currentMediaHash = newMedia.hashCode()
|
||||||
Handler().postDelayed({
|
Handler().postDelayed({
|
||||||
media = newMedia
|
media = newMedia
|
||||||
|
groupMedia()
|
||||||
enableInstantLoad()
|
enableInstantLoad()
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
|
@ -325,6 +331,21 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
}, INSTANT_LOAD_DURATION)
|
}, 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) {
|
private fun setupView(view: View, medium: Medium) {
|
||||||
view.apply {
|
view.apply {
|
||||||
play_outline.beVisibleIf(medium.isVideo())
|
play_outline.beVisibleIf(medium.isVideo())
|
||||||
|
|
|
@ -62,7 +62,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
|
||||||
return
|
return
|
||||||
|
|
||||||
shownMedia = media
|
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)
|
callback((it as Medium).path)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,12 @@ import android.arch.persistence.room.Index
|
||||||
import android.arch.persistence.room.PrimaryKey
|
import android.arch.persistence.room.PrimaryKey
|
||||||
import com.simplemobiletools.commons.extensions.formatDate
|
import com.simplemobiletools.commons.extensions.formatDate
|
||||||
import com.simplemobiletools.commons.extensions.formatSize
|
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_DATE_MODIFIED
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_PATH
|
import com.simplemobiletools.commons.helpers.SORT_BY_PATH
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||||
import com.simplemobiletools.gallery.helpers.TYPE_GIFS
|
import com.simplemobiletools.gallery.helpers.*
|
||||||
import com.simplemobiletools.gallery.helpers.TYPE_IMAGES
|
|
||||||
import com.simplemobiletools.gallery.helpers.TYPE_RAWS
|
|
||||||
import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
@Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))])
|
@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()
|
sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate()
|
||||||
else -> taken.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 -> ""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue