reuse the list of media files of thumbnail view at the fullscreen view

This commit is contained in:
tibbi 2017-05-29 21:21:47 +02:00
parent 28a2f59514
commit 5758b2eee1
2 changed files with 30 additions and 18 deletions

View file

@ -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<Medium>()
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<Medium>()
}
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() {

View file

@ -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<Medium>): 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<Medium>) {
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