@@ -4,6 +4,8 @@ import android.support.v7.widget.RecyclerView
44import android.view.View
55import android.view.ViewGroup
66import io.armcha.ribble.presentation.utils.extensions.inflate
7+ import io.reactivex.annotations.Experimental
8+ import kotlin.system.measureNanoTime
79
810/* *
911 * Created by Chatikyan on 14.08.2017.
@@ -12,9 +14,7 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
1214 private val layoutResId : Int )
1315 : RecyclerView .Adapter <AbstractAdapter .Holder >() {
1416
15- override fun getItemCount (): Int {
16- return itemList.size
17- }
17+ override fun getItemCount () = itemList.size
1818
1919 override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): Holder {
2020 val view = parent inflate layoutResId
@@ -34,12 +34,23 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
3434 holder.itemView.bind(item)
3535 }
3636
37- fun update (itemList : List <ITEM >) {
38- this .itemList = itemList
39- notifyDataSetChanged()// TODO
37+ fun addAll (itemList : List <ITEM >) {
38+ val startPosition = this .itemList.size
39+ this .itemList.toMutableList().addAll(itemList)
40+ notifyItemRangeInserted(startPosition, this .itemList.size)
41+ }
42+
43+ fun add (item : ITEM ) {
44+ itemList.toMutableList().add(item)
45+ notifyItemInserted(itemList.size)
46+ }
47+
48+ fun remove (position : Int ) {
49+ itemList.toMutableList().removeAt(position)
50+ notifyItemRemoved(position)
4051 }
4152
42- final override fun onViewRecycled (holder : AbstractAdapter . Holder ) {
53+ final override fun onViewRecycled (holder : Holder ) {
4354 super .onViewRecycled(holder)
4455 onViewRecycled(holder.itemView)
4556 }
@@ -50,8 +61,7 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
5061 protected open fun onItemClick (itemView : View , position : Int ) {
5162 }
5263
53- open fun View.bind (item : ITEM ){
54- // NO-OP
64+ protected open fun View.bind (item : ITEM ) {
5565 }
5666
5767 class Holder (itemView : View ) : RecyclerView.ViewHolder(itemView)
0 commit comments