mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
fix #74, properly set the viewpager position after delete
This commit is contained in:
parent
2c9c91396a
commit
de967340ad
1 changed files with 17 additions and 10 deletions
|
@ -38,7 +38,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mDirectory = ""
|
||||
|
||||
private var mIsFullScreen = false
|
||||
private var mPos = 0
|
||||
private var mPos = -1
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -73,8 +73,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
return
|
||||
}
|
||||
|
||||
mPos = 0
|
||||
mIsFullScreen = false
|
||||
mMedia = ArrayList<Medium>()
|
||||
showSystemUI()
|
||||
|
||||
|
@ -246,13 +244,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
if (isDirEmpty())
|
||||
return@GetMediaAsynctask
|
||||
|
||||
var j = 0
|
||||
for (medium in it) {
|
||||
if (medium.path == mPath) {
|
||||
mPos = j
|
||||
break
|
||||
}
|
||||
j++
|
||||
if (mPos == -1) {
|
||||
mPos = getProperPosition()
|
||||
} else {
|
||||
mPos = Math.min(mPos, mMedia.size - 1)
|
||||
}
|
||||
|
||||
updateActionbarTitle()
|
||||
|
@ -261,6 +256,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}.execute()
|
||||
}
|
||||
|
||||
private fun getProperPosition(): Int {
|
||||
mPos = 0
|
||||
var i = 0
|
||||
for (medium in mMedia) {
|
||||
if (medium.path == mPath) {
|
||||
return i
|
||||
}
|
||||
i++
|
||||
}
|
||||
return mPos
|
||||
}
|
||||
|
||||
private fun deleteDirectoryIfEmpty() {
|
||||
val file = File(mDirectory)
|
||||
if (file.isDirectory && file.listFiles().isEmpty()) {
|
||||
|
|
Loading…
Reference in a new issue