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() } }