fix some issues at reloading the viewpager after deleting an image

This commit is contained in:
tibbi 2016-12-04 19:21:59 +01:00
parent c4644c73a5
commit df5dc70f61
2 changed files with 13 additions and 18 deletions

View file

@ -98,7 +98,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
deleteFile()
return when (item.itemId) {
R.id.menu_set_as_wallpaper -> {
setAsWallpaper(getCurrentFile())
@ -195,7 +194,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun deleteFile() {
val file = File(mPath)
val file = File(mMedia!![mPos].path)
if (isShowingPermDialog(file))
return
@ -241,16 +240,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val adapter = view_pager.adapter as MyPagerAdapter
val curPos = view_pager.currentItem
mMedia = getMedia()
if (isDirEmpty())
return
view_pager.adapter = null
adapter.updateItems(mMedia!!)
view_pager.adapter = adapter
runOnUiThread {
adapter.updateItems(mMedia!!)
val newPos = Math.min(curPos, adapter.count)
view_pager.currentItem = newPos
updateActionbarTitle()
val newPos = Math.min(curPos, adapter.count)
view_pager.currentItem = newPos
updateActionbarTitle()
mPos = newPos
}
}
private fun deleteDirectoryIfEmpty() {
@ -320,7 +321,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
override fun fragmentClicked() {
deleteFile()
mIsFullScreen = !mIsFullScreen
if (mIsFullScreen) {
hideSystemUI()
@ -366,12 +366,4 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val adapter = view_pager.adapter as MyPagerAdapter
adapter.updateUiVisibility(mIsFullScreen, mPos)
}
private fun scanCompleted() {
runOnUiThread {
if (mMedia != null && mMedia!!.size <= 1) {
reloadViewPager()
}
}
}
}

View file

@ -4,12 +4,13 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v4.view.PagerAdapter
import android.util.SparseArray
import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.fragments.PhotoFragment
import com.simplemobiletools.gallery.fragments.VideoFragment
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium
class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList<Medium>) : FragmentStatePagerAdapter(fm) {
@ -39,6 +40,8 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m
return fragment
}
override fun getItemPosition(item: Any?) = PagerAdapter.POSITION_NONE
fun itemDragged(pos: Int) {
mFragments[pos]?.itemDragged()
}