dont always recreate the list, just update the items
This commit is contained in:
parent
b7b0eb463a
commit
6d7363fced
2 changed files with 16 additions and 5 deletions
|
@ -26,7 +26,7 @@ import kotlinx.android.synthetic.main.list_item.view.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) :
|
||||
class ItemsAdapter(val activity: SimpleActivity, var mItems: List<FileDirItem>, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) :
|
||||
RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
|
||||
val multiSelector = MultiSelector()
|
||||
val views = ArrayList<View>()
|
||||
|
@ -179,6 +179,11 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
return selectedMedia
|
||||
}
|
||||
|
||||
fun updateItems(newItems: List<FileDirItem>) {
|
||||
mItems = newItems
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent?.context).inflate(R.layout.list_item, parent, false)
|
||||
return ViewHolder(activity, view, itemClick)
|
||||
|
|
|
@ -76,11 +76,17 @@ class ItemsFragment : android.support.v4.app.Fragment(), ItemsAdapter.ItemOperat
|
|||
val adapter = ItemsAdapter(activity as SimpleActivity, mItems, this) {
|
||||
itemClicked(it)
|
||||
}
|
||||
|
||||
val currAdapter = items_list.adapter
|
||||
if (currAdapter == null) {
|
||||
items_list.apply {
|
||||
this@apply.adapter = adapter
|
||||
addItemDecoration(RecyclerViewDivider(context))
|
||||
setOnTouchListener { view, motionEvent -> checkDelete(); false }
|
||||
}
|
||||
} else {
|
||||
(currAdapter as ItemsAdapter).updateItems(mItems)
|
||||
}
|
||||
}
|
||||
|
||||
fun setListener(listener: ItemInteractionListener) {
|
||||
|
|
Loading…
Reference in a new issue