fix #74, properly set the viewpager position after delete

This commit is contained in:
tibbi 2016-12-05 18:50:23 +01:00
parent 2c9c91396a
commit de967340ad

View file

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