Skip to content

Commit

Permalink
RxRecyclerViewAdapter onViewRecycled 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
JoosungPark committed Nov 8, 2020
1 parent f7edb88 commit c5b0360
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class RxRecyclerAdapter<D : RxRecyclerAdapterData> constructor(

private var mDataSet: MutableList<D> = mutableListOf()

init {
setHasStableIds(true)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RxRecyclerAdapterViewHolder<D> = delegate.viewHolderForViewType(parent, viewType)

override fun onBindViewHolder(holderRecycler: RxRecyclerAdapterViewHolder<D>, position: Int) {
Expand Down Expand Up @@ -61,7 +65,11 @@ class RxRecyclerAdapter<D : RxRecyclerAdapterData> constructor(
}
}

// FIXME: 임시
override fun onViewRecycled(holder: RxRecyclerAdapterViewHolder<D>) {
super.onViewRecycled(holder)
holder.onViewRecycled()
}

interface Delegate<D : RxRecyclerAdapterData> {
fun inflate(parent: ViewGroup, layoutResId: Int): View = LayoutInflater.from(parent.context).inflate(layoutResId, parent, false)
fun getItemViewType(position: Int, item: D): Int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.joosung.rxrecycleradapter

interface RxRecyclerAdapterData
interface RxRecyclerAdapterData {
val id: Long get() = this::class.simpleName.hashCode().toLong()
}


Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ abstract class RxRecyclerAdapterViewHolder<in D : RxRecyclerAdapterData>(itemVie
dbag = CompositeDisposable()
parentDisposable.add(dbag)
}

open fun onViewRecycled() { }
}

0 comments on commit c5b0360

Please sign in to comment.