|
|
@ -88,6 +88,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
this.items.addAll(items) |
|
|
|
this.items.addAll(items) |
|
|
|
} |
|
|
|
} |
|
|
|
notifyDataSetChanged() |
|
|
|
notifyDataSetChanged() |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -100,6 +101,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
this.items.addAll(items) |
|
|
|
this.items.addAll(items) |
|
|
|
} |
|
|
|
} |
|
|
|
diffResult.dispatchUpdatesTo(this) |
|
|
|
diffResult.dispatchUpdatesTo(this) |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -110,6 +112,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
this.items[position] = item |
|
|
|
this.items[position] = item |
|
|
|
notifyItemChanged(position + getHeaderCount()) |
|
|
|
notifyItemChanged(position + getHeaderCount()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -119,6 +122,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
if (this.items.add(item)) { |
|
|
|
if (this.items.add(item)) { |
|
|
|
notifyItemInserted(oldSize + getHeaderCount()) |
|
|
|
notifyItemInserted(oldSize + getHeaderCount()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -127,6 +131,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
if (this.items.addAll(position, newItems)) { |
|
|
|
if (this.items.addAll(position, newItems)) { |
|
|
|
notifyItemRangeInserted(position + getHeaderCount(), newItems.size) |
|
|
|
notifyItemRangeInserted(position + getHeaderCount(), newItems.size) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -140,6 +145,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
notifyItemRangeInserted(oldSize + getHeaderCount(), newItems.size) |
|
|
|
notifyItemRangeInserted(oldSize + getHeaderCount(), newItems.size) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -148,6 +154,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
if (this.items.removeAt(position) != null) { |
|
|
|
if (this.items.removeAt(position) != null) { |
|
|
|
notifyItemRemoved(position + getHeaderCount()) |
|
|
|
notifyItemRemoved(position + getHeaderCount()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -156,6 +163,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
if (this.items.remove(item)) { |
|
|
|
if (this.items.remove(item)) { |
|
|
|
notifyItemRemoved(this.items.indexOf(item) + getHeaderCount()) |
|
|
|
notifyItemRemoved(this.items.indexOf(item) + getHeaderCount()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -164,6 +172,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
if (this.items.removeAll(items)) { |
|
|
|
if (this.items.removeAll(items)) { |
|
|
|
notifyDataSetChanged() |
|
|
|
notifyDataSetChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -176,6 +185,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
Collections.swap(this.items, srcPosition, targetPosition) |
|
|
|
Collections.swap(this.items, srcPosition, targetPosition) |
|
|
|
notifyItemMoved(srcPosition, targetPosition) |
|
|
|
notifyItemMoved(srcPosition, targetPosition) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -186,6 +196,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
this.items[index] = item |
|
|
|
this.items[index] = item |
|
|
|
notifyItemChanged(index) |
|
|
|
notifyItemChanged(index) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun updateItem(position: Int, payload: Any) = |
|
|
|
fun updateItem(position: Int, payload: Any) = |
|
|
@ -208,11 +219,11 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun clearItems() = |
|
|
|
fun clearItems() = synchronized(lock) { |
|
|
|
synchronized(lock) { |
|
|
|
this.items.clear() |
|
|
|
this.items.clear() |
|
|
|
notifyDataSetChanged() |
|
|
|
notifyDataSetChanged() |
|
|
|
onCurrentListChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun isEmpty() = items.isEmpty() |
|
|
|
fun isEmpty() = items.isEmpty() |
|
|
|
|
|
|
|
|
|
|
@ -252,6 +263,10 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co |
|
|
|
} ?: 0 |
|
|
|
} ?: 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open fun onCurrentListChanged() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when { |
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when { |
|
|
|
viewType < TYPE_HEADER_VIEW + getHeaderCount() -> { |
|
|
|
viewType < TYPE_HEADER_VIEW + getHeaderCount() -> { |
|
|
|
ItemViewHolder(headerItems.get(viewType).invoke(parent)) |
|
|
|
ItemViewHolder(headerItems.get(viewType).invoke(parent)) |
|
|
|