Skip to content

Commit 1af212a

Browse files
committed
update(adapter): using same RecycledViewPool for both RecyclerViews
1 parent bccb43a commit 1af212a

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/hoc/pagination_mvi/ui/main/HorizontalAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.hoc.pagination_mvi.ui.main
22

3+
import android.util.Log
34
import android.view.LayoutInflater
45
import android.view.View
56
import android.view.ViewGroup
@@ -61,8 +62,9 @@ class HorizontalAdapter(
6162

6263
override fun onBindViewHolder(holder: VH, position: Int) = holder.bind(getItem(position))
6364

64-
override fun onBindViewHolder(holder: VH, position: Int, payloads: MutableList<Any>) {
65+
override fun onBindViewHolder(holder: VH, position: Int, payloads: List<Any>) {
6566
if (payloads.isEmpty()) return holder.bind(getItem(position))
67+
Log.d("###", "[PAYLOAD] HORIZONTAL size=${payloads.size}")
6668
payloads.forEach { payload ->
6769
when {
6870
payload is PostVS && holder is PostVH -> holder.update(payload)

app/src/main/java/com/hoc/pagination_mvi/ui/main/MainAdapter.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ private object DiffUtilItemCallback : DiffUtil.ItemCallback<Item>() {
5050
}
5151
}
5252

53-
class MainAdapter(private val compositeDisposable: CompositeDisposable) :
53+
class MainAdapter(
54+
private val compositeDisposable: CompositeDisposable,
55+
private val viewPool: RecyclerView.RecycledViewPool
56+
) :
5457
ListAdapter<Item, MainAdapter.VH>(DiffUtilItemCallback) {
5558
private val scrollToFirst = PublishSubject.create<Unit>()
5659
private var layoutManagerSavedState: Parcelable? = null
@@ -79,8 +82,9 @@ class MainAdapter(private val compositeDisposable: CompositeDisposable) :
7982

8083
override fun onBindViewHolder(holder: VH, position: Int) = holder.bind(getItem(position))
8184

82-
override fun onBindViewHolder(holder: VH, position: Int, payloads: MutableList<Any>) {
85+
override fun onBindViewHolder(holder: VH, position: Int, payloads: List<Any>) {
8386
if (payloads.isEmpty()) return holder.bind(getItem(position))
87+
Log.d("###", "[PAYLOAD] MAIN size=${payloads.size}")
8488
payloads.forEach { payload ->
8589
Log.d("###", "[PAYLOAD] $payload")
8690
when {
@@ -166,7 +170,7 @@ class MainAdapter(private val compositeDisposable: CompositeDisposable) :
166170
}
167171

168172
private inner class HorizontalListVH(itemView: View, parent: ViewGroup) : VH(itemView) {
169-
private val recycler = itemView.recycler_horizontal!!
173+
private val recycler = itemView.recycler_horizontal!!.apply { setRecycledViewPool(viewPool) }
170174
private val progressBar = itemView.progress_bar_horizontal!!
171175
private val textError = itemView.text_error_horizontal!!
172176
private val buttonRetry = itemView.button_retry_horizontal!!

app/src/main/java/com/hoc/pagination_mvi/ui/main/MainFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import kotlinx.android.synthetic.main.fragment_main.*
2929
import kotlinx.coroutines.ExperimentalCoroutinesApi
3030
import java.util.concurrent.TimeUnit
3131
import javax.inject.Inject
32+
import kotlin.LazyThreadSafetyMode.NONE
3233

3334
@ExperimentalCoroutinesApi
3435
class MainFragment : Fragment() {
@@ -40,7 +41,7 @@ class MainFragment : Fragment() {
4041
private val maxSpanCount get() = if (requireContext().isOrientationPortrait) 2 else 4
4142
private val visibleThreshold get() = 2 * maxSpanCount + 1
4243

43-
private val adapter = MainAdapter(compositeDisposable)
44+
private val adapter by lazy(NONE) { MainAdapter(compositeDisposable, recycler.recycledViewPool) }
4445

4546
override fun onCreate(savedInstanceState: Bundle?) {
4647
AndroidSupportInjection.inject(this)

0 commit comments

Comments
 (0)