From f460c9457f1b875376e49c31454a5302a392744f Mon Sep 17 00:00:00 2001 From: Jieyi Date: Tue, 17 Apr 2018 20:20:43 +0900 Subject: [PATCH] Added append a list and remove a list. --- .../adaptiverecyclerview/AdaptiveAdapter.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt b/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt index 2cf771b..0b66f40 100644 --- a/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt +++ b/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt @@ -10,7 +10,7 @@ import android.view.ViewGroup * @author jieyi * @since 9/6/17 */ -abstract class AdaptiveAdapter, VH: RecyclerView.ViewHolder>: +abstract class AdaptiveAdapter, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter() { var headerEntity: M? = null set(value) { @@ -51,4 +51,21 @@ abstract class AdaptiveAdapter, VH: Recyc return this.typeFactory.createViewHolder(viewType, itemView) as VH } //endregion + + fun appendList(list: MutableList) { + val startIndex = dataList.size + + dataList.addAll(startIndex, list) + notifyItemRangeChanged(startIndex, list.size) + } + + fun dropList(startIndex: Int, endIndex: Int) { + when { + startIndex < 0 || endIndex >= dataList.size -> throw IndexOutOfBoundsException("The range is over than list.") + startIndex > endIndex -> throw IndexOutOfBoundsException("startIndex index must be less than endIndex index.") + } + + repeat(endIndex - startIndex + 1) { dataList.removeAt(startIndex) } + notifyDataSetChanged() + } }