diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 6c9c9671d..b46d88011 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -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() - } - } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt index 454578b58..5cb9ade53 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MyPagerAdapter.kt @@ -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) : 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() }