delay loading the zoomable image at fullscreen mode to avoid laggy swipes
This commit is contained in:
parent
2091c8bf4b
commit
addae2045e
1 changed files with 57 additions and 43 deletions
|
@ -47,7 +47,9 @@ import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
class PhotoFragment : ViewPagerFragment() {
|
class PhotoFragment : ViewPagerFragment() {
|
||||||
private var DEFAULT_DOUBLE_TAP_ZOOM = 2f
|
private val DEFAULT_DOUBLE_TAP_ZOOM = 2f
|
||||||
|
private val ZOOMABLE_VIEW_LOAD_DELAY = 1500L
|
||||||
|
|
||||||
private var isFragmentVisible = false
|
private var isFragmentVisible = false
|
||||||
private var isFullscreen = false
|
private var isFullscreen = false
|
||||||
private var wasInit = false
|
private var wasInit = false
|
||||||
|
@ -55,6 +57,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
private var isPanorama = false
|
private var isPanorama = false
|
||||||
private var imageOrientation = -1
|
private var imageOrientation = -1
|
||||||
private var gifDrawable: GifDrawable? = null
|
private var gifDrawable: GifDrawable? = null
|
||||||
|
private var loadZoomableViewHandler = Handler()
|
||||||
|
|
||||||
private var storedShowExtendedDetails = false
|
private var storedShowExtendedDetails = false
|
||||||
private var storedHideExtendedDetails = false
|
private var storedHideExtendedDetails = false
|
||||||
|
@ -184,7 +187,9 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
|
|
||||||
private fun photoFragmentVisibilityChanged(isVisible: Boolean) {
|
private fun photoFragmentVisibilityChanged(isVisible: Boolean) {
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
addZoomableView()
|
scheduleZoomableView()
|
||||||
|
} else {
|
||||||
|
loadZoomableViewHandler.removeCallbacksAndMessages(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,8 +281,9 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
||||||
if (isFragmentVisible)
|
if (isFragmentVisible) {
|
||||||
addZoomableView()
|
scheduleZoomableView()
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}).into(view.photo_view)
|
}).into(view.photo_view)
|
||||||
|
@ -302,8 +308,16 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun scheduleZoomableView() {
|
||||||
|
loadZoomableViewHandler.removeCallbacksAndMessages(null)
|
||||||
|
loadZoomableViewHandler.postDelayed({
|
||||||
|
if (isFragmentVisible && !context!!.config.replaceZoomableImages && medium.isImage() && view.subsampling_view.isGone()) {
|
||||||
|
addZoomableView()
|
||||||
|
}
|
||||||
|
}, ZOOMABLE_VIEW_LOAD_DELAY)
|
||||||
|
}
|
||||||
|
|
||||||
private fun addZoomableView() {
|
private fun addZoomableView() {
|
||||||
if (!context!!.config.replaceZoomableImages && medium.isImage() && isFragmentVisible && view.subsampling_view.isGone()) {
|
|
||||||
ViewPagerActivity.wasDecodedByGlide = false
|
ViewPagerActivity.wasDecodedByGlide = false
|
||||||
view.subsampling_view.apply {
|
view.subsampling_view.apply {
|
||||||
maxScale = 10f
|
maxScale = 10f
|
||||||
|
@ -343,7 +357,6 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkIfPanorama() {
|
private fun checkIfPanorama() {
|
||||||
isPanorama = try {
|
isPanorama = try {
|
||||||
|
@ -431,6 +444,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
Glide.with(context!!).clear(view.photo_view)
|
Glide.with(context!!).clear(view.photo_view)
|
||||||
view.subsampling_view.recycle()
|
view.subsampling_view.recycle()
|
||||||
}
|
}
|
||||||
|
loadZoomableViewHandler.removeCallbacksAndMessages(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
|
Loading…
Reference in a new issue