From 61440e2f2202693bd7c8cbf1a084df69ac4f95fb Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 28 Feb 2022 17:29:17 +0100 Subject: [PATCH] avoid refetching viewpager position after file deleting --- .../pro/activities/ViewPagerActivity.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 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 654932d50..9861ecf46 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 @@ -374,7 +374,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View view_pager.onGlobalLayout { if (!isDestroyed) { if (mMediaFiles.isNotEmpty()) { - gotMedia(mMediaFiles as ArrayList) + gotMedia(mMediaFiles as ArrayList, refetchViewPagerPosition = true) checkSlideshowOnEnter() } } @@ -1112,7 +1112,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mIgnoredPaths.add(fileDirItem.path) val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList runOnUiThread { - gotMedia(media, true) + gotMedia(media, true, false) } movePathsInRecycleBin(arrayListOf(path)) { @@ -1134,7 +1134,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mIgnoredPaths.add(fileDirItem.path) val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList runOnUiThread { - gotMedia(media, true) + gotMedia(media, true, false) } tryDeleteFileDirItem(fileDirItem, false, true) { @@ -1171,12 +1171,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun refreshViewPager() { if (config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0) { GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) { - gotMedia(it) + gotMedia(it, refetchViewPagerPosition = true) }.execute() } } - private fun gotMedia(thumbnailItems: ArrayList, ignorePlayingVideos: Boolean = false) { + private fun gotMedia(thumbnailItems: ArrayList, ignorePlayingVideos: Boolean = false, refetchViewPagerPosition: Boolean = false) { val media = thumbnailItems.asSequence().filter { it is Medium && !mIgnoredPaths.contains(it.path) }.map { it as Medium }.toMutableList() as ArrayList @@ -1191,9 +1191,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mPrevHashcode = media.hashCode() mMediaFiles = media - mPos = getPositionInList(media) - if (mPos == -1) { - Math.min(mPos, mMediaFiles.size - 1) + + if (refetchViewPagerPosition) { + mPos = getPositionInList(media) + if (mPos == -1) { + Math.min(mPos, mMediaFiles.size - 1) + } } updateActionbarTitle()