mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
fix some issues at reloading the viewpager after deleting an image
This commit is contained in:
parent
c4644c73a5
commit
df5dc70f61
2 changed files with 13 additions and 18 deletions
|
@ -98,7 +98,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
deleteFile()
|
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.menu_set_as_wallpaper -> {
|
R.id.menu_set_as_wallpaper -> {
|
||||||
setAsWallpaper(getCurrentFile())
|
setAsWallpaper(getCurrentFile())
|
||||||
|
@ -195,7 +194,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteFile() {
|
private fun deleteFile() {
|
||||||
val file = File(mPath)
|
val file = File(mMedia!![mPos].path)
|
||||||
if (isShowingPermDialog(file))
|
if (isShowingPermDialog(file))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -241,16 +240,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val adapter = view_pager.adapter as MyPagerAdapter
|
val adapter = view_pager.adapter as MyPagerAdapter
|
||||||
val curPos = view_pager.currentItem
|
val curPos = view_pager.currentItem
|
||||||
mMedia = getMedia()
|
mMedia = getMedia()
|
||||||
|
|
||||||
if (isDirEmpty())
|
if (isDirEmpty())
|
||||||
return
|
return
|
||||||
|
|
||||||
view_pager.adapter = null
|
runOnUiThread {
|
||||||
adapter.updateItems(mMedia!!)
|
adapter.updateItems(mMedia!!)
|
||||||
view_pager.adapter = adapter
|
|
||||||
|
|
||||||
val newPos = Math.min(curPos, adapter.count)
|
val newPos = Math.min(curPos, adapter.count)
|
||||||
view_pager.currentItem = newPos
|
view_pager.currentItem = newPos
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
|
mPos = newPos
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteDirectoryIfEmpty() {
|
private fun deleteDirectoryIfEmpty() {
|
||||||
|
@ -320,7 +321,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fragmentClicked() {
|
override fun fragmentClicked() {
|
||||||
deleteFile()
|
|
||||||
mIsFullScreen = !mIsFullScreen
|
mIsFullScreen = !mIsFullScreen
|
||||||
if (mIsFullScreen) {
|
if (mIsFullScreen) {
|
||||||
hideSystemUI()
|
hideSystemUI()
|
||||||
|
@ -366,12 +366,4 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val adapter = view_pager.adapter as MyPagerAdapter
|
val adapter = view_pager.adapter as MyPagerAdapter
|
||||||
adapter.updateUiVisibility(mIsFullScreen, mPos)
|
adapter.updateUiVisibility(mIsFullScreen, mPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scanCompleted() {
|
|
||||||
runOnUiThread {
|
|
||||||
if (mMedia != null && mMedia!!.size <= 1) {
|
|
||||||
reloadViewPager()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,13 @@ import android.os.Bundle
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v4.app.FragmentManager
|
import android.support.v4.app.FragmentManager
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter
|
import android.support.v4.app.FragmentStatePagerAdapter
|
||||||
|
import android.support.v4.view.PagerAdapter
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import com.simplemobiletools.gallery.helpers.MEDIUM
|
|
||||||
import com.simplemobiletools.gallery.activities.ViewPagerActivity
|
import com.simplemobiletools.gallery.activities.ViewPagerActivity
|
||||||
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
||||||
import com.simplemobiletools.gallery.fragments.VideoFragment
|
import com.simplemobiletools.gallery.fragments.VideoFragment
|
||||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||||
|
import com.simplemobiletools.gallery.helpers.MEDIUM
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
|
|
||||||
class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList<Medium>) : FragmentStatePagerAdapter(fm) {
|
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
|
return fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItemPosition(item: Any?) = PagerAdapter.POSITION_NONE
|
||||||
|
|
||||||
fun itemDragged(pos: Int) {
|
fun itemDragged(pos: Int) {
|
||||||
mFragments[pos]?.itemDragged()
|
mFragments[pos]?.itemDragged()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue