couple slideshow improvements

This commit is contained in:
tibbi 2017-12-29 22:07:47 +01:00
parent 422b1fb690
commit 46a143e4ac

View file

@ -317,6 +317,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
view_pager.apply { view_pager.apply {
adapter = pagerAdapter adapter = pagerAdapter
currentItem = mPos currentItem = mPos
removeOnPageChangeListener(this@ViewPagerActivity)
addOnPageChangeListener(this@ViewPagerActivity) addOnPageChangeListener(this@ViewPagerActivity)
} }
} }
@ -351,12 +352,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
override fun onAnimationEnd(animation: Animator?) { override fun onAnimationEnd(animation: Animator?) {
if (view_pager.isFakeDragging) {
try {
view_pager.endFakeDrag() view_pager.endFakeDrag()
} catch (ignored: Exception) {
stopSlideshow()
}
if (view_pager.currentItem == oldPosition) { if (view_pager.currentItem == oldPosition) {
slideshowEnded(forward) slideshowEnded(forward)
} }
} }
}
override fun onAnimationCancel(animation: Animator?) { override fun onAnimationCancel(animation: Animator?) {
view_pager.endFakeDrag() view_pager.endFakeDrag()
@ -374,7 +381,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val dragPosition = animation.animatedValue as Int val dragPosition = animation.animatedValue as Int
val dragOffset = dragPosition - oldDragPosition val dragOffset = dragPosition - oldDragPosition
oldDragPosition = dragPosition oldDragPosition = dragPosition
try {
view_pager.fakeDragBy(dragOffset * (if (forward) 1f else -1f)) view_pager.fakeDragBy(dragOffset * (if (forward) 1f else -1f))
} catch (e: Exception) {
stopSlideshow()
}
} }
} }
}) })
@ -399,8 +410,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun stopSlideshow() { private fun stopSlideshow() {
if (mIsSlideshowActive) { if (mIsSlideshowActive) {
showSystemUI()
mIsSlideshowActive = false mIsSlideshowActive = false
showSystemUI()
mSlideshowHandler.removeCallbacksAndMessages(null) mSlideshowHandler.removeCallbacksAndMessages(null)
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} }