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 f3b861a9b..8e9d307c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -37,8 +37,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private val SAVE_MEDIA_CNT = 40 private val LAST_MEDIA_CHECK_PERIOD = 3000L - private var mMedia = ArrayList() - private var mPath = "" private var mIsGetImageIntent = false private var mIsGetVideoIntent = false @@ -51,6 +49,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mLastMediaModified = 0 private var mLastMediaHandler = Handler() + companion object { + var mMedia = ArrayList() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_media) @@ -95,6 +97,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun onDestroy() { super.onDestroy() config.temporarilyShowHidden = false + mMedia.clear() } private fun tryloadGallery() { 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 01a77afb3..24aa738e7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -97,6 +97,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mDirectory = File(mPath).parent title = mPath.getFilenameFromPath() + + if (MediaActivity.mMedia.isNotEmpty()) + gotMedia(MediaActivity.mMedia) + reloadViewPager() scanPath(mPath) {} setupOrientationEventListener() @@ -379,8 +383,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - private fun isDirEmpty(): Boolean { - return if (mMedia.size <= 0) { + private fun isDirEmpty(media: ArrayList): Boolean { + return if (media.isEmpty()) { deleteDirectoryIfEmpty() finish() true @@ -415,23 +419,28 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun reloadViewPager() { GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) { - mMedia = it - if (isDirEmpty()) - return@GetMediaAsynctask - - if (mPos == -1) { - mPos = getProperPosition() - } else { - mPos = Math.min(mPos, mMedia.size - 1) - } - - updateActionbarTitle() - updatePagerItems() - invalidateOptionsMenu() - checkOrientation() + gotMedia(it) }.execute() } + private fun gotMedia(media: ArrayList) { + if (isDirEmpty(media) || mMedia.hashCode() == media.hashCode()) { + return + } + + mMedia = media + if (mPos == -1) { + mPos = getProperPosition() + } else { + mPos = Math.min(mPos, mMedia.size - 1) + } + + updateActionbarTitle() + updatePagerItems() + invalidateOptionsMenu() + checkOrientation() + } + private fun getProperPosition(): Int { mPos = 0 var i = 0