From dad1a6e817fc65c8ee2110bbb0992c075d9d0ec2 Mon Sep 17 00:00:00 2001 From: darthpaul Date: Mon, 16 May 2022 18:44:23 +0100 Subject: [PATCH] fix: position returning to 0 - for calling refreshUI(media, true) would refresh the view pager position, cause mPos to be set back to 0, so we retain the original behaviour and call refreshUI(media, false) - when items have been removed up until the last item in the adapter, the ViewPager's OnPageChangeListener.onPageSelected does not get called for the first item so mPos is never set to zero and deletion fails. - we add a call in OnPageChangeListener.onPageScrolled to call onPageSelected(0), when the position == 0 to fix this. --- .../gallery/pro/activities/ViewPagerActivity.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 c254ed128..72b23be1e 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 @@ -1136,7 +1136,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList if (media.isNotEmpty()) { runOnUiThread { - refreshUI(media, true) + refreshUI(media, false) } } @@ -1169,7 +1169,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList if (media.isNotEmpty()) { runOnUiThread { - refreshUI(media, true) + refreshUI(media, false) } } @@ -1413,7 +1413,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun getCurrentPath() = getCurrentMedium()?.path ?: "" - override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { + if (position == 0) { + onPageSelected(0) + } + } override fun onPageSelected(position: Int) { if (mPos != position) {