skip the thumbnail load delay in some cases

This commit is contained in:
tibbi 2018-01-06 19:02:42 +01:00
parent 7a3f136825
commit 616d4098fc

View file

@ -29,11 +29,16 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null,
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
init {
enableInstantLoad()
}
private val config = activity.config private val config = activity.config
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
private var skipConfirmationDialog = false private var skipConfirmationDialog = false
private var visibleItemPaths = ArrayList<String>() private var visibleItemPaths = ArrayList<String>()
private var delayHandler = Handler(Looper.getMainLooper()) private var delayHandler = Handler(Looper.getMainLooper())
private var loadImageInstantly = false
private var scrollHorizontally = config.scrollHorizontally private var scrollHorizontally = config.scrollHorizontally
private var animateGifs = config.animateGifs private var animateGifs = config.animateGifs
@ -239,12 +244,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
fun updateMedia(newMedia: ArrayList<Medium>) { fun updateMedia(newMedia: ArrayList<Medium>) {
media = newMedia media = newMedia
enableInstantLoad()
notifyDataSetChanged() notifyDataSetChanged()
finishActMode() finishActMode()
} }
fun updateDisplayFilenames(displayFilenames: Boolean) { fun updateDisplayFilenames(displayFilenames: Boolean) {
this.displayFilenames = displayFilenames this.displayFilenames = displayFilenames
enableInstantLoad()
notifyDataSetChanged() notifyDataSetChanged()
} }
@ -263,6 +270,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
notifyDataSetChanged() notifyDataSetChanged()
} }
private fun enableInstantLoad() {
loadImageInstantly = true
Handler().postDelayed({
loadImageInstantly = false
}, 1000)
}
private fun setupView(view: View, medium: Medium) { private fun setupView(view: View, medium: Medium) {
view.apply { view.apply {
play_outline.beVisibleIf(medium.video) play_outline.beVisibleIf(medium.video)
@ -270,13 +284,18 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
photo_name.text = medium.name photo_name.text = medium.name
photo_name.tag = medium.path photo_name.tag = medium.path
medium_thumbnail.isHorizontalScrolling = scrollHorizontally if (loadImageInstantly) {
delayHandler.postDelayed({ activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
val isVisible = visibleItemPaths.contains(medium.path) } else {
if (isVisible) { medium_thumbnail.setImageDrawable(null)
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) medium_thumbnail.isHorizontalScrolling = scrollHorizontally
} delayHandler.postDelayed({
}, 200) val isVisible = visibleItemPaths.contains(medium.path)
if (isVisible) {
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
}
}, 200)
}
if (isListViewType) { if (isListViewType) {
photo_name.setTextColor(textColor) photo_name.setTextColor(textColor)