From a8bfae66a7928b6d2415562eeb62ad2c55b39f96 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 4 Jul 2022 16:10:19 +0530 Subject: [PATCH 1/8] Clear cached media only for external intents --- .../gallery/pro/activities/PhotoVideoActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt index 732cc416e..8660bd1c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt @@ -288,7 +288,9 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList } private fun openViewPager(path: String) { - MediaActivity.mMedia.clear() + if (!intent.getBooleanExtra(IS_FROM_GALLERY, false)) { + MediaActivity.mMedia.clear() + } runOnUiThread { hideKeyboard() Intent(this, ViewPagerActivity::class.java).apply { From 5fba1ad8102476704e705ca57b520abdbcf370ff Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 4 Jul 2022 16:29:59 +0530 Subject: [PATCH 2/8] Simplify code --- .../gallery/pro/activities/ViewPagerActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 988a2fecf..a52545aff 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 @@ -95,7 +95,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View window.decorView.setBackgroundColor(getProperBackgroundColor()) top_shadow.layoutParams.height = statusBarHeight + actionBarHeight checkNotchSupport() - (MediaActivity.mMedia.clone() as ArrayList).filter { it is Medium }.mapTo(mMediaFiles) { it as Medium } + (MediaActivity.mMedia.clone() as ArrayList).filterIsInstanceTo(mMediaFiles, Medium::class.java) handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { From bccf86a1bf3e01bd336e967ed93e53e4ab1dea75 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 4 Jul 2022 17:42:50 +0530 Subject: [PATCH 3/8] Enable random sorting for external intents --- .../gallery/pro/activities/ViewPagerActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 a52545aff..659756c1d 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 @@ -1228,7 +1228,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun refreshViewPager(refetchPosition: Boolean = false) { - if (config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0) { + val isSortingRandom = config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0 + val isExternalIntent = !intent.getBooleanExtra(IS_FROM_GALLERY, false) + if (!isSortingRandom || isExternalIntent) { GetMediaAsynctask(applicationContext, mDirectory, isPickImage = false, isPickVideo = false, showAll = mShowAll) { gotMedia(it, refetchViewPagerPosition = refetchPosition) }.execute() From be3ee0de8d9f4043fffa84db4a9edc5912eeae83 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 4 Jul 2022 18:07:42 +0530 Subject: [PATCH 4/8] Enable refreshing for external intents even when video is playing --- .../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 659756c1d..c2bd43f79 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 @@ -1229,8 +1229,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun refreshViewPager(refetchPosition: Boolean = false) { val isSortingRandom = config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0 - val isExternalIntent = !intent.getBooleanExtra(IS_FROM_GALLERY, false) - if (!isSortingRandom || isExternalIntent) { + if (!isSortingRandom || isExternalIntent()) { GetMediaAsynctask(applicationContext, mDirectory, isPickImage = false, isPickVideo = false, showAll = mShowAll) { gotMedia(it, refetchViewPagerPosition = refetchPosition) }.execute() @@ -1246,7 +1245,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } - if (!ignorePlayingVideos && (getCurrentFragment() as? VideoFragment)?.mIsPlaying == true) { + val isPlaying = (getCurrentFragment() as? VideoFragment)?.mIsPlaying == true + if (!ignorePlayingVideos && isPlaying && !isExternalIntent()) { return } @@ -1438,4 +1438,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View checkOrientation() } } + + private fun isExternalIntent(): Boolean { + return !intent.getBooleanExtra(IS_FROM_GALLERY, false) + } } From 54dc6c41b57bda36a6b86268a996ea53762dab84 Mon Sep 17 00:00:00 2001 From: Naveen Date: Tue, 5 Jul 2022 18:27:24 +0530 Subject: [PATCH 5/8] Use `isExternalIntent()` function --- .../gallery/pro/activities/ViewPagerActivity.kt | 7 ++++--- 1 file changed, 4 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 c2bd43f79..234c3bf94 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 @@ -58,6 +58,7 @@ import kotlinx.android.synthetic.main.activity_medium.* import kotlinx.android.synthetic.main.bottom_actions.* import java.io.File import java.io.OutputStream +import kotlin.math.min @Suppress("UNCHECKED_CAST") class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener { @@ -157,7 +158,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (config.isThirdPartyIntent) { config.isThirdPartyIntent = false - if (intent.extras == null || !intent.getBooleanExtra(IS_FROM_GALLERY, false)) { + if (intent.extras == null || isExternalIntent()) { mMediaFiles.clear() } } @@ -1260,7 +1261,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (refetchViewPagerPosition || mPos == -1) { mPos = getPositionInList(media) if (mPos == -1) { - Math.min(mPos, media.size - 1) + min(mPos, media.size - 1) } } @@ -1414,7 +1415,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return if (getCurrentMedia().isEmpty() || mPos == -1) { null } else { - getCurrentMedia()[Math.min(mPos, getCurrentMedia().size - 1)] + getCurrentMedia()[min(mPos, getCurrentMedia().size - 1)] } } From e4aff60852d9564360b0a1f3be975bd486ed5b2c Mon Sep 17 00:00:00 2001 From: Naveen Date: Tue, 5 Jul 2022 20:14:56 +0530 Subject: [PATCH 6/8] Fix typo error --- .../gallery/pro/activities/ViewPagerActivity.kt | 4 ++-- 1 file changed, 2 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 234c3bf94..6b477ebeb 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 @@ -1229,8 +1229,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun refreshViewPager(refetchPosition: Boolean = false) { - val isSortingRandom = config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0 - if (!isSortingRandom || isExternalIntent()) { + val isNotRandomSorting = config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0 + if (isNotRandomSorting || isExternalIntent()) { GetMediaAsynctask(applicationContext, mDirectory, isPickImage = false, isPickVideo = false, showAll = mShowAll) { gotMedia(it, refetchViewPagerPosition = refetchPosition) }.execute() From caf6b7c5535f653ad10b997526758c6226d6a505 Mon Sep 17 00:00:00 2001 From: Naveen Date: Wed, 6 Jul 2022 15:44:43 +0530 Subject: [PATCH 7/8] Minor code improvement --- .../gallery/pro/activities/ViewPagerActivity.kt | 4 ++-- 1 file changed, 2 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 6b477ebeb..fc6da9746 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 @@ -1229,8 +1229,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun refreshViewPager(refetchPosition: Boolean = false) { - val isNotRandomSorting = config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0 - if (isNotRandomSorting || isExternalIntent()) { + val isRandomSorting = config.getFolderSorting(mDirectory) and SORT_BY_RANDOM != 0 + if (!isRandomSorting || isExternalIntent()) { GetMediaAsynctask(applicationContext, mDirectory, isPickImage = false, isPickVideo = false, showAll = mShowAll) { gotMedia(it, refetchViewPagerPosition = refetchPosition) }.execute() From 378fea1cce47a214afacc600d291a6b91bd120bf Mon Sep 17 00:00:00 2001 From: Naveen Date: Thu, 7 Jul 2022 01:51:55 +0530 Subject: [PATCH 8/8] Add `IS_FROM_GALLERY` to image intents as well --- .../simplemobiletools/gallery/pro/activities/MediaActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index bbd226ea1..398c34578 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -828,6 +828,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { putExtra(SHOW_ALL, mShowAll) putExtra(SHOW_FAVORITES, mPath == FAVORITES) putExtra(SHOW_RECYCLE_BIN, mPath == RECYCLE_BIN) + putExtra(IS_FROM_GALLERY, true) startActivity(this) } }