From 2d8baa740370389cb218e02a11098392734a1741 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:42:41 -0300 Subject: [PATCH 1/3] Show Reader dropdown menu custom lists items directly if there are 2 or fewer items --- .../ui/reader/utils/ReaderTopBarMenuHelper.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt index ba94c014f5c5..33a33e476e69 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt @@ -55,7 +55,20 @@ class ReaderTopBarMenuHelper @Inject constructor( .takeIf { it.isNotEmpty() } ?.let { customListsArray -> add(MenuElementData.Divider) - add(createCustomListsItem(customListsArray)) + if (customListsArray.size() > 2) { + // If custom lists has more than 2 items, we add a submenu called "Lists" + add(createCustomListsItem(customListsArray)) + } else { + // If the custom lists has 2 or less items, we add the items directly without submenu + customListsArray.forEach { index, readerTag -> + add( + MenuElementData.Item.Single( + id = getMenuItemIdFromReaderTagIndex(index), + text = UiString.UiStringText(readerTag.tagTitle), + ) + ) + } + } } } } From cdc8c532e5b2e720c1329ac08c1851883911daab Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:47:39 -0300 Subject: [PATCH 2/3] Fix detekt --- .../ui/reader/utils/ReaderTopBarMenuHelper.kt | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt index 33a33e476e69..e5b979bd9bc3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelper.kt @@ -55,24 +55,30 @@ class ReaderTopBarMenuHelper @Inject constructor( .takeIf { it.isNotEmpty() } ?.let { customListsArray -> add(MenuElementData.Divider) - if (customListsArray.size() > 2) { - // If custom lists has more than 2 items, we add a submenu called "Lists" - add(createCustomListsItem(customListsArray)) - } else { - // If the custom lists has 2 or less items, we add the items directly without submenu - customListsArray.forEach { index, readerTag -> - add( - MenuElementData.Item.Single( - id = getMenuItemIdFromReaderTagIndex(index), - text = UiString.UiStringText(readerTag.tagTitle), - ) - ) - } - } + createCustomListsItems(customListsArray) } } } + private fun MutableList.createCustomListsItems( + customListsArray: SparseArrayCompat + ) { + if (customListsArray.size() > 2) { + // If custom lists has more than 2 items, we add a submenu called "Lists" + add(createCustomListsItem(customListsArray)) + } else { + // If the custom lists has 2 or less items, we add the items directly without submenu + customListsArray.forEach { index, readerTag -> + add( + MenuElementData.Item.Single( + id = getMenuItemIdFromReaderTagIndex(index), + text = UiString.UiStringText(readerTag.tagTitle), + ) + ) + } + } + } + private fun createDiscoverItem(id: String): MenuElementData.Item.Single { return MenuElementData.Item.Single( id = id, From 03b73d84be16089d532201c1cc7390b9378a9c6e Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:32:26 -0300 Subject: [PATCH 3/3] Update ReaderTopBarMenuHelperTest --- .../utils/ReaderTopBarMenuHelperTest.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelperTest.kt index 03e57616424e..e9850dab73b1 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/utils/ReaderTopBarMenuHelperTest.kt @@ -72,6 +72,27 @@ class ReaderTopBarMenuHelperTest { assertThat(customList3Item.text).isEqualTo(UiStringText("custom-list-3")) } + @Test + fun `GIVEN custom lists has 2 items or less WHEN createMenu THEN custom lists items are shown outside a submenu`() { + val tags = ReaderTagList().apply { + add(mockFollowingTag()) // item 0 + add(mockDiscoverTag()) // item 1 + add(mockSavedTag()) // item 2 + add(mockLikedTag()) // item 3 + add(mockA8CTag()) // item 4 + add(mockFollowedP2sTag()) // item 5 + add(createCustomListTag("custom-list-1")) // item 6 + add(createCustomListTag("custom-list-2")) // item 7 + } + val menu = helper.createMenu(tags) + + val customListItem1 = menu.findSingleItem { it.id == "6" }!! + assertThat(customListItem1.text).isEqualTo(UiStringText("custom-list-1")) + + val customListItem2 = menu.findSingleItem { it.id == "7" }!! + assertThat(customListItem2.text).isEqualTo(UiStringText("custom-list-2")) + } + @Test fun `GIVEN all tags are available and tags FF enabled WHEN createMenu THEN all items are created correctly`() { whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(true)