update media screen items on delete, dont recreate

This commit is contained in:
tibbi 2016-12-04 21:01:21 +01:00
parent f06fc85bdb
commit ac9132bf6b
3 changed files with 16 additions and 5 deletions

View file

@ -14,7 +14,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.filepicker.extensions.*
import com.simplemobiletools.gallery.* import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.adapters.DirectoryAdapter
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
@ -302,6 +302,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val adapter = DirectoryAdapter(this, mDirs, this) { val adapter = DirectoryAdapter(this, mDirs, this) {
itemClicked(it.path) itemClicked(it.path)
} }
directories_grid.adapter = adapter directories_grid.adapter = adapter
directories_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false } directories_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false }
} }

View file

@ -16,7 +16,7 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.request.animation.GlideAnimation import com.bumptech.glide.request.animation.GlideAnimation
import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.target.SimpleTarget
import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.filepicker.extensions.*
import com.simplemobiletools.gallery.* import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.adapters.MediaAdapter
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
@ -87,7 +87,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
itemClicked(it.path) itemClicked(it.path)
} }
media_grid.adapter = adapter val currAdapter = media_grid.adapter
if (currAdapter != null) {
(currAdapter as MediaAdapter).updateMedia(mMedia)
} else {
media_grid.adapter = adapter
}
media_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false } media_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false }
} }

View file

@ -14,20 +14,20 @@ import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog
import com.simplemobiletools.filepicker.extensions.toast import com.simplemobiletools.filepicker.extensions.toast
import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
import com.simplemobiletools.gallery.helpers.Config
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.extensions.beVisibleIf import com.simplemobiletools.gallery.extensions.beVisibleIf
import com.simplemobiletools.gallery.extensions.shareMedia import com.simplemobiletools.gallery.extensions.shareMedia
import com.simplemobiletools.gallery.extensions.shareMedium import com.simplemobiletools.gallery.extensions.shareMedium
import com.simplemobiletools.gallery.helpers.Config
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.photo_video_item.view.* import kotlinx.android.synthetic.main.photo_video_item.view.*
import kotlinx.android.synthetic.main.photo_video_tmb.view.* import kotlinx.android.synthetic.main.photo_video_tmb.view.*
import java.io.File import java.io.File
import java.util.* import java.util.*
class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>, val listener: MediaOperationsListener?, val itemClick: (Medium) -> Unit) : class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val itemClick: (Medium) -> Unit) :
RecyclerView.Adapter<MediaAdapter.ViewHolder>() { RecyclerView.Adapter<MediaAdapter.ViewHolder>() {
val multiSelector = MultiSelector() val multiSelector = MultiSelector()
val views = ArrayList<View>() val views = ArrayList<View>()
@ -167,6 +167,11 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>,
override fun getItemCount() = media.size override fun getItemCount() = media.size
fun updateMedia(newMedia: ArrayList<Medium>) {
media = newMedia
notifyDataSetChanged()
}
fun updateDisplayFilenames(display: Boolean) { fun updateDisplayFilenames(display: Boolean) {
displayFilenames = display displayFilenames = display
notifyDataSetChanged() notifyDataSetChanged()