Merge pull request #2543 from Naveen3Singh/viewpager_fixes

Properly handle media loading and cache
This commit is contained in:
Tibor Kaputa 2022-07-06 23:35:35 +02:00 committed by GitHub
commit a91f4441cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View file

@ -828,6 +828,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
putExtra(SHOW_ALL, mShowAll) putExtra(SHOW_ALL, mShowAll)
putExtra(SHOW_FAVORITES, mPath == FAVORITES) putExtra(SHOW_FAVORITES, mPath == FAVORITES)
putExtra(SHOW_RECYCLE_BIN, mPath == RECYCLE_BIN) putExtra(SHOW_RECYCLE_BIN, mPath == RECYCLE_BIN)
putExtra(IS_FROM_GALLERY, true)
startActivity(this) startActivity(this)
} }
} }

View file

@ -288,7 +288,9 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
} }
private fun openViewPager(path: String) { private fun openViewPager(path: String) {
MediaActivity.mMedia.clear() if (!intent.getBooleanExtra(IS_FROM_GALLERY, false)) {
MediaActivity.mMedia.clear()
}
runOnUiThread { runOnUiThread {
hideKeyboard() hideKeyboard()
Intent(this, ViewPagerActivity::class.java).apply { Intent(this, ViewPagerActivity::class.java).apply {

View file

@ -58,6 +58,7 @@ import kotlinx.android.synthetic.main.activity_medium.*
import kotlinx.android.synthetic.main.bottom_actions.* import kotlinx.android.synthetic.main.bottom_actions.*
import java.io.File import java.io.File
import java.io.OutputStream import java.io.OutputStream
import kotlin.math.min
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener { class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener {
@ -95,7 +96,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
window.decorView.setBackgroundColor(getProperBackgroundColor()) window.decorView.setBackgroundColor(getProperBackgroundColor())
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
checkNotchSupport() checkNotchSupport()
(MediaActivity.mMedia.clone() as ArrayList<ThumbnailItem>).filter { it is Medium }.mapTo(mMediaFiles) { it as Medium } (MediaActivity.mMedia.clone() as ArrayList<ThumbnailItem>).filterIsInstanceTo(mMediaFiles, Medium::class.java)
handlePermission(PERMISSION_WRITE_STORAGE) { handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) { if (it) {
@ -157,7 +158,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (config.isThirdPartyIntent) { if (config.isThirdPartyIntent) {
config.isThirdPartyIntent = false config.isThirdPartyIntent = false
if (intent.extras == null || !intent.getBooleanExtra(IS_FROM_GALLERY, false)) { if (intent.extras == null || isExternalIntent()) {
mMediaFiles.clear() mMediaFiles.clear()
} }
} }
@ -1228,7 +1229,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun refreshViewPager(refetchPosition: Boolean = false) { private fun refreshViewPager(refetchPosition: Boolean = false) {
if (config.getFolderSorting(mDirectory) and SORT_BY_RANDOM == 0) { val isRandomSorting = config.getFolderSorting(mDirectory) and SORT_BY_RANDOM != 0
if (!isRandomSorting || isExternalIntent()) {
GetMediaAsynctask(applicationContext, mDirectory, isPickImage = false, isPickVideo = false, showAll = mShowAll) { GetMediaAsynctask(applicationContext, mDirectory, isPickImage = false, isPickVideo = false, showAll = mShowAll) {
gotMedia(it, refetchViewPagerPosition = refetchPosition) gotMedia(it, refetchViewPagerPosition = refetchPosition)
}.execute() }.execute()
@ -1244,7 +1246,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return return
} }
if (!ignorePlayingVideos && (getCurrentFragment() as? VideoFragment)?.mIsPlaying == true) { val isPlaying = (getCurrentFragment() as? VideoFragment)?.mIsPlaying == true
if (!ignorePlayingVideos && isPlaying && !isExternalIntent()) {
return return
} }
@ -1258,7 +1261,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (refetchViewPagerPosition || mPos == -1) { if (refetchViewPagerPosition || mPos == -1) {
mPos = getPositionInList(media) mPos = getPositionInList(media)
if (mPos == -1) { if (mPos == -1) {
Math.min(mPos, media.size - 1) min(mPos, media.size - 1)
} }
} }
@ -1412,7 +1415,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return if (getCurrentMedia().isEmpty() || mPos == -1) { return if (getCurrentMedia().isEmpty() || mPos == -1) {
null null
} else { } else {
getCurrentMedia()[Math.min(mPos, getCurrentMedia().size - 1)] getCurrentMedia()[min(mPos, getCurrentMedia().size - 1)]
} }
} }
@ -1436,4 +1439,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
checkOrientation() checkOrientation()
} }
} }
private fun isExternalIntent(): Boolean {
return !intent.getBooleanExtra(IS_FROM_GALLERY, false)
}
} }