Skip to content

Commit

Permalink
Added append a list and remove a list.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokk committed Apr 17, 2018
1 parent bf70f80 commit f460c94
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import android.view.ViewGroup
* @author jieyi
* @since 9/6/17
*/
abstract class AdaptiveAdapter<VT: ViewTypeFactory, M: IVisitable<VT>, VH: RecyclerView.ViewHolder>:
abstract class AdaptiveAdapter<VT : ViewTypeFactory, M : IVisitable<VT>, VH : RecyclerView.ViewHolder> :
RecyclerView.Adapter<VH>() {
var headerEntity: M? = null
set(value) {
Expand Down Expand Up @@ -51,4 +51,21 @@ abstract class AdaptiveAdapter<VT: ViewTypeFactory, M: IVisitable<VT>, VH: Recyc
return this.typeFactory.createViewHolder(viewType, itemView) as VH
}
//endregion

fun appendList(list: MutableList<M>) {
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()
}
}

0 comments on commit f460c94

Please sign in to comment.