From 498cd10ba6016a37264e38de6d956a3fd4adaf6d Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Oct 2017 21:53:28 +0200 Subject: [PATCH] add a medium null check at scrollStateChanged trigger --- .../gallery/activities/ViewPagerActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index cc996366f..e9af326b0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -730,10 +730,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun getCurrentMedium(): Medium? { - return if (getCurrentMedia().isEmpty() || mPos == -1) + return if (getCurrentMedia().isEmpty() || mPos == -1) { null - else + } else { getCurrentMedia()[Math.min(mPos, getCurrentMedia().size - 1)] + } } private fun getCurrentMedia() = if (mAreSlideShowMediaVisible) mSlideshowMedia else mMedia @@ -756,7 +757,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } override fun onPageScrollStateChanged(state: Int) { - if (state == ViewPager.SCROLL_STATE_IDLE) { + if (state == ViewPager.SCROLL_STATE_IDLE && getCurrentMedium() != null) { checkOrientation() } }