Skip to content

Commit fe8a023

Browse files
authored
Merge pull request #20940 from wordpress-mobile/issue/20033-show-lists-directly-dropdown-menu-if-2-or-fewer-items
[Reader] Show custom lists directly if there are 2 or fewer items
2 parents a24e5d1 + 03b73d8 commit fe8a023

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt

+20-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,30 @@ class ReaderTopBarMenuHelper @Inject constructor(
5555
.takeIf { it.isNotEmpty() }
5656
?.let { customListsArray ->
5757
add(MenuElementData.Divider)
58-
add(createCustomListsItem(customListsArray))
58+
createCustomListsItems(customListsArray)
5959
}
6060
}
6161
}
6262

63+
private fun MutableList<MenuElementData>.createCustomListsItems(
64+
customListsArray: SparseArrayCompat<ReaderTag>
65+
) {
66+
if (customListsArray.size() > 2) {
67+
// If custom lists has more than 2 items, we add a submenu called "Lists"
68+
add(createCustomListsItem(customListsArray))
69+
} else {
70+
// If the custom lists has 2 or less items, we add the items directly without submenu
71+
customListsArray.forEach { index, readerTag ->
72+
add(
73+
MenuElementData.Item.Single(
74+
id = getMenuItemIdFromReaderTagIndex(index),
75+
text = UiString.UiStringText(readerTag.tagTitle),
76+
)
77+
)
78+
}
79+
}
80+
}
81+
6382
private fun createDiscoverItem(id: String): MenuElementData.Item.Single {
6483
return MenuElementData.Item.Single(
6584
id = id,

WordPress/src/test/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelperTest.kt

+21
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ class ReaderTopBarMenuHelperTest {
7272
assertThat(customList3Item.text).isEqualTo(UiStringText("custom-list-3"))
7373
}
7474

75+
@Test
76+
fun `GIVEN custom lists has 2 items or less WHEN createMenu THEN custom lists items are shown outside a submenu`() {
77+
val tags = ReaderTagList().apply {
78+
add(mockFollowingTag()) // item 0
79+
add(mockDiscoverTag()) // item 1
80+
add(mockSavedTag()) // item 2
81+
add(mockLikedTag()) // item 3
82+
add(mockA8CTag()) // item 4
83+
add(mockFollowedP2sTag()) // item 5
84+
add(createCustomListTag("custom-list-1")) // item 6
85+
add(createCustomListTag("custom-list-2")) // item 7
86+
}
87+
val menu = helper.createMenu(tags)
88+
89+
val customListItem1 = menu.findSingleItem { it.id == "6" }!!
90+
assertThat(customListItem1.text).isEqualTo(UiStringText("custom-list-1"))
91+
92+
val customListItem2 = menu.findSingleItem { it.id == "7" }!!
93+
assertThat(customListItem2.text).isEqualTo(UiStringText("custom-list-2"))
94+
}
95+
7596
@Test
7697
fun `GIVEN all tags are available and tags FF enabled WHEN createMenu THEN all items are created correctly`() {
7798
whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(true)

0 commit comments

Comments
 (0)