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,6 +284,10 @@ 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
if (loadImageInstantly) {
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
} else {
medium_thumbnail.setImageDrawable(null)
medium_thumbnail.isHorizontalScrolling = scrollHorizontally medium_thumbnail.isHorizontalScrolling = scrollHorizontally
delayHandler.postDelayed({ delayHandler.postDelayed({
val isVisible = visibleItemPaths.contains(medium.path) val isVisible = visibleItemPaths.contains(medium.path)
@ -277,6 +295,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
} }
}, 200) }, 200)
}
if (isListViewType) { if (isListViewType) {
photo_name.setTextColor(textColor) photo_name.setTextColor(textColor)