From af586a209f3148ef1af5281d71ea2bc1bb0b0e34 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 19 Dec 2017 17:14:08 +0100 Subject: [PATCH] create a copy of the mediafiles in the viewpager activity --- .../gallery/activities/MediaActivity.kt | 1 + .../gallery/activities/ViewPagerActivity.kt | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 0125673b1..3efc0f5e7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -134,6 +134,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { super.onDestroy() if (config.showAll) config.temporarilyShowHidden = false + mMedia.clear() } 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 7db412eb6..c0db101ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -32,7 +32,6 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.commons.helpers.REQUEST_SET_AS import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.MediaActivity.Companion.mMedia import com.simplemobiletools.gallery.adapters.MyPagerAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog @@ -70,6 +69,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mIsOrientationLocked = false private var mStoredUseEnglish = false + private var mMediaFiles = ArrayList() companion object { var screenWidth = 0 @@ -81,6 +81,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View super.onCreate(savedInstanceState) setContentView(R.layout.activity_medium) setTranslucentNavigation() + mMediaFiles = MediaActivity.mMedia.clone() as ArrayList handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { @@ -139,7 +140,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View config.isThirdPartyIntent = false if (intent.extras == null || !intent.getBooleanExtra(IS_FROM_GALLERY, false)) { - mMedia.clear() + mMediaFiles.clear() } } } @@ -193,8 +194,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View view_pager.onGlobalLayout { if (!isActivityDestroyed()) { - if (mMedia.isNotEmpty()) { - gotMedia(mMedia) + if (mMediaFiles.isNotEmpty()) { + gotMedia(mMediaFiles) } } } @@ -424,7 +425,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun getMediaForSlideshow(): Boolean { - mSlideshowMedia = mMedia.toMutableList() + mSlideshowMedia = mMediaFiles.toMutableList() if (!config.slideshowIncludePhotos) { mSlideshowMedia = mSlideshowMedia.filter { !it.isImage() } as MutableList } @@ -774,15 +775,15 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } mPrevHashcode = media.hashCode() - mMedia = media + mMediaFiles = media mPos = if (mPos == -1) { getPositionInList(media) } else { - Math.min(mPos, mMedia.size - 1) + Math.min(mPos, mMediaFiles.size - 1) } updateActionbarTitle() - updatePagerItems(mMedia.toMutableList()) + updatePagerItems(mMediaFiles.toMutableList()) invalidateOptionsMenu() checkOrientation() } @@ -853,7 +854,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - private fun getCurrentMedia() = if (mAreSlideShowMediaVisible) mSlideshowMedia else mMedia + private fun getCurrentMedia() = if (mAreSlideShowMediaVisible) mSlideshowMedia else mMediaFiles private fun getCurrentPath() = getCurrentMedium()!!.path