From e6039d07cb7d65ad370b6b2d416c482972474e80 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 19 Jun 2022 17:19:35 +0530 Subject: [PATCH] Remove page change listener before changing adapter --- .../gallery/pro/activities/ViewPagerActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index ff922e2e7..988a2fecf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -462,11 +462,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (!isDestroyed) { pagerAdapter.shouldInitFragment = mPos < 5 view_pager.apply { + // must remove the listener before changing adapter, otherwise it might cause `mPos` to be set to 0 + removeOnPageChangeListener(this@ViewPagerActivity) adapter = pagerAdapter pagerAdapter.shouldInitFragment = true - currentItem = mPos - removeOnPageChangeListener(this@ViewPagerActivity) addOnPageChangeListener(this@ViewPagerActivity) + currentItem = mPos } } }