Merge "Fix jank regression from AllAppsRecyclerViewPoolTest" into main
diff --git a/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt b/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt
index 0a7beab..78ce3a2 100644
--- a/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt
+++ b/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt
@@ -62,6 +62,10 @@
fun preInflateAllAppsViewHolders(context: T) {
val appsView = context.appsView ?: return
val activeRv: RecyclerView = appsView.activeRecyclerView ?: return
+ val preInflateCount = getPreinflateCount(context)
+ if (preInflateCount <= 0) {
+ return
+ }
if (activeRv.layoutManager == null) {
if (BuildConfig.IS_STUDIO_BUILD) {
@@ -99,7 +103,12 @@
override fun getLayoutManager(): RecyclerView.LayoutManager? = null
}
- preInflateAllAppsViewHolders(adapter, BaseAllAppsAdapter.VIEW_TYPE_ICON, activeRv) {
+ preInflateAllAppsViewHolders(
+ adapter,
+ BaseAllAppsAdapter.VIEW_TYPE_ICON,
+ activeRv,
+ preInflateCount
+ ) {
getPreinflateCount(context)
}
}
@@ -109,10 +118,10 @@
adapter: RecyclerView.Adapter<*>,
viewType: Int,
parent: ViewGroup,
+ preInflationCount: Int,
preInflationCountProvider: () -> Int
) {
- val preinflationCount = preInflationCountProvider.invoke()
- if (preinflationCount <= 0) {
+ if (preInflationCount <= 0) {
return
}
mCancellableTask?.cancel()
@@ -121,7 +130,7 @@
CancellableTask(
{
val list: ArrayList<ViewHolder> = ArrayList()
- for (i in 0 until preinflationCount) {
+ for (i in 0 until preInflationCount) {
if (task?.canceled == true) {
break
}
@@ -132,8 +141,8 @@
MAIN_EXECUTOR,
{ viewHolders ->
// Run preInflationCountProvider again as the needed VH might have changed
- val newPreinflationCount = preInflationCountProvider.invoke()
- for (i in 0 until minOf(viewHolders.size, newPreinflationCount)) {
+ val newPreInflationCount = preInflationCountProvider.invoke()
+ for (i in 0 until minOf(viewHolders.size, newPreInflationCount)) {
putRecycledView(viewHolders[i])
}
}
diff --git a/tests/multivalentTests/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPoolTest.kt b/tests/multivalentTests/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPoolTest.kt
index 8204313..3e6aae2 100644
--- a/tests/multivalentTests/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPoolTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPoolTest.kt
@@ -65,7 +65,7 @@
@Test
fun preinflate_success() {
- underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent) { 10 }
+ underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent, 10) { 10 }
awaitTasksCompleted()
assertThat(underTest.getRecycledViewCount(VIEW_TYPE)).isEqualTo(10)
@@ -73,7 +73,7 @@
@Test
fun preinflate_not_triggered() {
- underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent) { 0 }
+ underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent, 0) { 0 }
awaitTasksCompleted()
assertThat(underTest.getRecycledViewCount(VIEW_TYPE)).isEqualTo(0)
@@ -81,7 +81,7 @@
@Test
fun preinflate_cancel_before_runOnMainThread() {
- underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent) { 10 }
+ underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent, 10) { 10 }
assertThat(underTest.mCancellableTask!!.canceled).isFalse()
underTest.clear()
@@ -94,7 +94,7 @@
@Test
fun preinflate_cancel_after_run() {
- underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent) { 10 }
+ underTest.preInflateAllAppsViewHolders(adapter, VIEW_TYPE, parent, 10) { 10 }
assertThat(underTest.mCancellableTask!!.canceled).isFalse()
awaitTasksCompleted()