Fix LayoutTransition All Apps divider logic for RTL.

We were checking the wrong index (off by one), leading to a crash if the divider is already in the Taskbar at the correct index. However, we do need to add it after the expected index if the divider isn't there, otherwise it will push the icon that is at that position to the right of the divider (it should be to the left).

Flag: com.android.launcher3.taskbar_recents_layout_transition
Bug: 343521765
Bug: 368522274
Test: go/testedequals
Change-Id: I0263f704728286b53da5b45828784b20aaae31ce
This commit is contained in:
Brian Isganitis
2024-11-21 14:33:39 -05:00
parent 423c85a2eb
commit f04ae6b09f
2 changed files with 21 additions and 7 deletions
@@ -501,16 +501,20 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
}
private void updateAllAppsDivider() {
final int allAppsDividerIndex =
mIsRtl ? getChildCount() - mNumStaticViews : mNumStaticViews;
if (getChildAt(allAppsDividerIndex) == mTaskbarDividerContainer
// Index where All Apps divider would be if it is already in Taskbar.
final int expectedAllAppsDividerIndex =
mIsRtl ? getChildCount() - mNumStaticViews - 1 : mNumStaticViews;
if (getChildAt(expectedAllAppsDividerIndex) == mTaskbarDividerContainer
&& getChildCount() == mNumStaticViews + 1) {
// Only static views with divider so remove divider.
removeView(mTaskbarDividerContainer);
} else if (getChildAt(allAppsDividerIndex) != mTaskbarDividerContainer
} else if (getChildAt(expectedAllAppsDividerIndex) != mTaskbarDividerContainer
&& getChildCount() >= mNumStaticViews + 1) {
// Static views with at least one app icon so add divider.
addView(mTaskbarDividerContainer, allAppsDividerIndex);
// Static views with at least one app icon so add divider. For RTL, add it after the
// icon that is at the expected index.
addView(
mTaskbarDividerContainer,
mIsRtl ? expectedAllAppsDividerIndex + 1 : expectedAllAppsDividerIndex);
}
}
@@ -84,7 +84,17 @@ class TaskbarViewWithLayoutTransitionTest {
@Test
@ForceRtl
fun testUpdateItems_rtl_addHotseatItem_updatesHotseat() {
fun testUpdateItems_rtl_addHotseatItemWithoutRecents_updatesHotseat() {
runOnMainSync {
taskbarView.updateItems(createHotseatItems(1), emptyList())
taskbarView.updateItems(createHotseatItems(2), emptyList())
}
assertThat(taskbarView).hasIconTypes(*HOTSEAT * 2, DIVIDER, ALL_APPS)
}
@Test
@ForceRtl
fun testUpdateItems_rtl_addHotseatItemWithRecents_updatesHotseat() {
runOnMainSync {
taskbarView.updateItems(createHotseatItems(1), createRecents(1))
taskbarView.updateItems(createHotseatItems(2), createRecents(1))