increase the load priority of the current fullscreen image

This commit is contained in:
tibbi 2017-02-26 17:21:49 +01:00
parent aedb7d9144
commit 169b9f45ca

View file

@ -10,6 +10,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.RequestListener
@ -37,6 +38,7 @@ class PhotoFragment : ViewPagerFragment() {
lateinit var medium: Medium lateinit var medium: Medium
lateinit var subsamplingView: SubsamplingScaleImageView lateinit var subsamplingView: SubsamplingScaleImageView
lateinit var glideView: PhotoView lateinit var glideView: PhotoView
private var isFragmentVisible = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val view = inflater.inflate(R.layout.pager_photo_item, container, false) val view = inflater.inflate(R.layout.pager_photo_item, container, false)
@ -99,6 +101,11 @@ class PhotoFragment : ViewPagerFragment() {
return view return view
} }
override fun setMenuVisibility(menuVisible: Boolean) {
super.setMenuVisibility(menuVisible)
isFragmentVisible = menuVisible
}
private fun degreesForRotation(orientation: Int): Int { private fun degreesForRotation(orientation: Int): Int {
return when (orientation) { return when (orientation) {
8 -> 270 8 -> 270
@ -125,6 +132,7 @@ class PhotoFragment : ViewPagerFragment() {
.load(medium.path) .load(medium.path)
.asGif() .asGif()
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.priority(if (isFragmentVisible) Priority.IMMEDIATE else Priority.NORMAL)
.into(glideView) .into(glideView)
} else { } else {
loadBitmap() loadBitmap()
@ -137,6 +145,7 @@ class PhotoFragment : ViewPagerFragment() {
.asBitmap() .asBitmap()
.transform(GlideRotateTransformation(context, degrees)) .transform(GlideRotateTransformation(context, degrees))
.format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565) .format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565)
.priority(if (isFragmentVisible) Priority.IMMEDIATE else Priority.NORMAL)
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.listener(object : RequestListener<String, Bitmap> { .listener(object : RequestListener<String, Bitmap> {
override fun onException(e: Exception?, model: String?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean { override fun onException(e: Exception?, model: String?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {