From c3931e1c168c8c8fdac6f23df4a384562109e469 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 13:45:00 -0500 Subject: [PATCH 1/9] Add tool as the placeholder icon for site monitoring --- WordPress/src/main/res/drawable/gb_ic_tool.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 WordPress/src/main/res/drawable/gb_ic_tool.xml diff --git a/WordPress/src/main/res/drawable/gb_ic_tool.xml b/WordPress/src/main/res/drawable/gb_ic_tool.xml new file mode 100644 index 000000000000..5f664e419d2c --- /dev/null +++ b/WordPress/src/main/res/drawable/gb_ic_tool.xml @@ -0,0 +1,10 @@ + + + From 5828c76bd9a404fbededba766754fbd87f8c1d04 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 13:45:54 -0500 Subject: [PATCH 2/9] Add site monitoring string resource --- WordPress/src/main/res/values/strings.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index e9449d4c778d..ae6ac289d922 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -4854,4 +4854,6 @@ translators: %s: Select control option value e.g: "Auto, 25%". --> Working Offline Waiting for connection + + Site Monitoring From 229366a4d6be90241038ade868c9d157ef714177 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 13:49:15 -0500 Subject: [PATCH 3/9] Add navigation action for SiteMonitoring --- .../java/org/wordpress/android/ui/mysite/SiteNavigationAction.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/SiteNavigationAction.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/SiteNavigationAction.kt index 4fbfff996878..95fe3002cd46 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/SiteNavigationAction.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/SiteNavigationAction.kt @@ -110,6 +110,7 @@ sealed class SiteNavigationAction { object OpenDashboardPersonalization : SiteNavigationAction() data class OpenBloganuaryNudgeOverlay(val isPromptsEnabled: Boolean): SiteNavigationAction() + data class OpenSiteMonitoring(val site: SiteModel) : SiteNavigationAction() } sealed class BloggingPromptCardNavigationAction: SiteNavigationAction() { From 42776d04a8c3b73c742d2963168a1f6cf78132bb Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 13:50:53 -0500 Subject: [PATCH 4/9] Add navigation handler for launching the site monitoring activity - still to come --- .../main/java/org/wordpress/android/ui/ActivityNavigator.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt index d3e0c0760d7e..03a8b9883878 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt @@ -2,6 +2,7 @@ package org.wordpress.android.ui import android.content.Context import android.content.Intent +import android.util.Log import androidx.core.app.TaskStackBuilder import org.wordpress.android.R import org.wordpress.android.WordPress @@ -156,5 +157,10 @@ class ActivityNavigator @Inject constructor() { mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) return mainActivityIntent } + + fun navigateToSiteMonitoring(context: Context, site: SiteModel) { + Log.i(javaClass.simpleName, "Request to navigateToSiteMonitoring for ${site.name} within ${context.packageName}") + // todo: Implement this method after the SiteMonitorActivity is available + } } From 402236b52bbc195d8c23d30d936b27f21c7e7f69 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 13:51:20 -0500 Subject: [PATCH 5/9] Add SITE_MONITORING to the list of actions --- .../wordpress/android/ui/mysite/items/listitem/ListItemAction.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/ListItemAction.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/ListItemAction.kt index 86d06002ca40..4fd019acca11 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/ListItemAction.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/ListItemAction.kt @@ -20,4 +20,5 @@ enum class ListItemAction (val trackingLabel: String) { BLAZE("blaze"), ME("me"), MORE("more"), + SITE_MONITORING("site_monitoring"), } From 4f13e3257c8cc6c77bdacf56cd50ab6ae1a8f1c6 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 13:52:46 -0500 Subject: [PATCH 6/9] Handle navigation actions for site monitoring --- .../java/org/wordpress/android/ui/mysite/MySiteFragment.kt | 5 +++++ .../android/ui/mysite/cards/ListItemActionHandler.kt | 1 + .../org/wordpress/android/ui/mysite/menu/MenuActivity.kt | 1 + 3 files changed, 7 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt index debb2b7b5aab..6034341af6b4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt @@ -726,6 +726,11 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), .newInstance(action.isPromptsEnabled) .show(requireActivity().supportFragmentManager, BloganuaryNudgeLearnMoreOverlayFragment.TAG) } + + is SiteNavigationAction.OpenSiteMonitoring -> activityNavigator.navigateToSiteMonitoring( + requireActivity(), + action.site + ) } private fun handleNavigation(action: BloggingPromptCardNavigationAction) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt index ba55fc1133c3..cc01fc6a663e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt @@ -41,6 +41,7 @@ class ListItemActionHandler @Inject constructor( ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite) ListItemAction.BLAZE -> onBlazeMenuItemClick() ListItemAction.MORE -> SiteNavigationAction.OpenMore(selectedSite, quickStartEvent) + ListItemAction.SITE_MONITORING -> SiteNavigationAction.OpenSiteMonitoring(selectedSite) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt index 4fc94a8deeeb..b80d28a42095 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt @@ -152,6 +152,7 @@ class MenuActivity : AppCompatActivity() { this, action.campaignListingPageSource ) + is SiteNavigationAction.OpenSiteMonitoring -> activityNavigator.navigateToSiteMonitoring(this, action.site) else -> {} } } From ba867143c3d422fd2c90b427e54f80d1b914fc7d Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 13:54:13 -0500 Subject: [PATCH 7/9] Add logic to build and show the site monitoring item on the more menu --- .../ui/mysite/items/listitem/SiteItemsBuilder.kt | 8 ++++++++ .../ui/mysite/items/listitem/SiteListItemBuilder.kt | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsBuilder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsBuilder.kt index b9c940ccfecc..fb3fcc0fdad5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsBuilder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsBuilder.kt @@ -91,6 +91,7 @@ class SiteItemsBuilder @Inject constructor( private fun getManageSiteItems( params: SiteItemsBuilderParams ): List { + val siteMonitoring = buildSiteMonitoringOptionsIfNeeded(params) val manageSiteItems = buildManageSiteItems(params) val emptyHeaderItem1 = CategoryEmptyHeaderItem(UiString.UiStringText("")) @@ -101,6 +102,7 @@ class SiteItemsBuilder @Inject constructor( val emptyHeaderItem2 = CategoryEmptyHeaderItem(UiString.UiStringText("")) val admin = siteListItemBuilder.buildAdminItemIfAvailable(params.site, params.onClick) return listOf(manageHeader) + + siteMonitoring + manageSiteItems + emptyHeaderItem1 + jetpackConfiguration + @@ -126,6 +128,12 @@ class SiteItemsBuilder @Inject constructor( ) } + private fun buildSiteMonitoringOptionsIfNeeded(params: SiteItemsBuilderParams): List { + return listOfNotNull( + siteListItemBuilder.buildSiteMonitoringItemIfAvailable(params.site, params.onClick) + ) + } + private fun buildManageSiteItems(params: SiteItemsBuilderParams): List{ if(jetpackFeatureRemovalOverlayUtil.shouldHideJetpackFeatures()) return emptyList() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt index d768502c5bd8..d847635c9626 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt @@ -245,6 +245,18 @@ class SiteListItemBuilder @Inject constructor( } else null } + fun buildSiteMonitoringItemIfAvailable(site: SiteModel, onClick: (ListItemAction) -> Unit): MySiteCardAndItem? { + // todo: Add the feature flag wrapper once it is available + return if (buildConfigWrapper.isJetpackApp && site.isWPComAtomic && site.isAdmin) { + ListItem( + R.drawable.gb_ic_tool, + UiStringRes(R.string.site_monitoring), + onClick = ListItemInteraction.create(ListItemAction.SITE_MONITORING, onClick), + listItemAction = ListItemAction.SITE_MONITORING + ) + } else null + } + companion object { const val HIDE_WP_ADMIN_YEAR = 2015 const val HIDE_WP_ADMIN_MONTH = 9 From b12f1c3c7bc93996c2b0c08977ee551191e23476 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 14:21:18 -0500 Subject: [PATCH 8/9] Add and update unit tests for site monitoring --- .../mysite/cards/ListItemActionHandlerTest.kt | 9 +++- .../ui/mysite/items/SiteItemFixtures.kt | 6 +++ .../ui/mysite/items/SiteItemsBuilderTest.kt | 8 +++ .../items/listitem/SiteListItemBuilderTest.kt | 53 +++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt index 0f7c4a007ec7..ddad2ff8e7c3 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt @@ -190,7 +190,14 @@ class ListItemActionHandlerTest: BaseUnitTest() { ) } - private fun invokeItemClickAction(action: ListItemAction, ): SiteNavigationAction { + @Test + fun `when site monitoring item click, then emits OpenSiteMonitoring navigation event`() { + val navigationAction = invokeItemClickAction(action = ListItemAction.SITE_MONITORING) + + assertEquals(navigationAction, SiteNavigationAction.OpenSiteMonitoring(site)) + } + + private fun invokeItemClickAction(action: ListItemAction): SiteNavigationAction { return listItemActionHandler.handleAction(action, site) } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemFixtures.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemFixtures.kt index a69a3f69eb0d..1d142d9edb79 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemFixtures.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemFixtures.kt @@ -115,3 +115,9 @@ val DOMAINS_ITEM = ListItem( onClick = ListItemInteraction.create(DOMAINS, SITE_ITEM_ACTION), listItemAction = DOMAINS ) +val SITE_MONITORING_ITEM = ListItem( + R.drawable.gb_ic_tool, + UiStringRes(R.string.site_monitoring), + onClick = ListItemInteraction.create(ListItemAction.SITE_MONITORING, SITE_ITEM_ACTION), + listItemAction = ListItemAction.SITE_MONITORING +) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsBuilderTest.kt index 3f872f8158d6..073277c6f50e 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsBuilderTest.kt @@ -76,6 +76,7 @@ class SiteItemsBuilderTest { @Test fun `adds all the items in the correct order`() { setupHeaders( + addSiteMonitoringItem = true, addActivityLogItem = true, addPlanItem = false, addPagesItem = true, @@ -106,6 +107,7 @@ class SiteItemsBuilderTest { TRAFFIC_HEADER, STATS_ITEM, MANAGE_HEADER, + SITE_MONITORING_ITEM, ACTIVITY_ITEM, BACKUP_ITEM, SCAN_ITEM, @@ -229,6 +231,7 @@ class SiteItemsBuilderTest { @Suppress("ComplexMethod", "LongMethod") private fun setupHeaders( + addSiteMonitoringItem: Boolean = false, addActivityLogItem: Boolean = false, addPlanItem: Boolean = false, addPagesItem: Boolean = false, @@ -255,6 +258,11 @@ class SiteItemsBuilderTest { PLAN_ITEM.copy(showFocusPoint = showPlansFocusPoint) ) } + if (addSiteMonitoringItem) { + whenever(siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)).thenReturn( + SITE_MONITORING_ITEM + ) + } if (addActivityLogItem) { whenever(siteListItemBuilder.buildActivityLogItemIfAvailable(siteModel, SITE_ITEM_ACTION)).thenReturn( ACTIVITY_ITEM diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt index 12f5777b438a..7d579919727b 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt @@ -23,6 +23,7 @@ import org.wordpress.android.ui.mysite.items.PLUGINS_ITEM import org.wordpress.android.ui.mysite.items.SCAN_ITEM import org.wordpress.android.ui.mysite.items.SHARING_ITEM import org.wordpress.android.ui.mysite.items.SITE_ITEM_ACTION +import org.wordpress.android.ui.mysite.items.SITE_MONITORING_ITEM import org.wordpress.android.ui.mysite.items.SITE_SETTINGS_ITEM import org.wordpress.android.ui.plugins.PluginUtilsWrapper import org.wordpress.android.ui.themes.ThemeBrowserUtils @@ -414,6 +415,58 @@ class SiteListItemBuilderTest { assertThat(item).isNull() } + /* SITE MONITORING */ + @Test + fun `give jetpack app, when is atomic and admin, then site monitoring item is built`() { + setupSiteMonitoringItems() + + val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) + + assertThat(item).isEqualTo(SITE_MONITORING_ITEM) + } + + @Test + fun `give jetpack app, when is not atomic, then site monitoring item is not built`() { + setupSiteMonitoringItems( + isAtomic = false + ) + + val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) + + assertThat(item).isNull() + } + + @Test + fun `give jetpack app, when is not admin, then site monitoring item is not built`() { + setupSiteMonitoringItems( + isAdmin = false + ) + + val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) + + assertThat(item).isNull() + } + + @Test + fun `give not jetpack app, when site monitoring item requested, then site monitoring item is not built`() { + setupSiteMonitoringItems( + isJetpackApp = false + ) + + val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) + + assertThat(item).isNull() + } + + private fun setupSiteMonitoringItems( + isJetpackApp: Boolean = true, + isAtomic: Boolean = true, + isAdmin: Boolean = true + ) { + whenever(buildConfigWrapper.isJetpackApp).thenReturn(isJetpackApp) + whenever(siteModel.isAdmin).thenReturn(isAdmin) + whenever(siteModel.isWPComAtomic).thenReturn(isAtomic) + } private fun setupSiteSettings(canManageOptions: Boolean = false, isAccessedViaWPComRest: Boolean = true) { whenever(siteModel.hasCapabilityManageOptions).thenReturn(canManageOptions) whenever(siteUtilsWrapper.isAccessedViaWPComRest(siteModel)).thenReturn(isAccessedViaWPComRest) From dfe3b6f42a3ff9b8360c797fe461c269fe7e96ef Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 24 Jan 2024 14:44:01 -0500 Subject: [PATCH 9/9] Fix detekt --- .../main/java/org/wordpress/android/ui/ActivityNavigator.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt index 03a8b9883878..505f0db65752 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt @@ -2,7 +2,6 @@ package org.wordpress.android.ui import android.content.Context import android.content.Intent -import android.util.Log import androidx.core.app.TaskStackBuilder import org.wordpress.android.R import org.wordpress.android.WordPress @@ -159,8 +158,9 @@ class ActivityNavigator @Inject constructor() { } fun navigateToSiteMonitoring(context: Context, site: SiteModel) { - Log.i(javaClass.simpleName, "Request to navigateToSiteMonitoring for ${site.name} within ${context.packageName}") - // todo: Implement this method after the SiteMonitorActivity is available + // todo: Implement this method after the SiteMonitorActivity is available and remove the lines below + site.name + context.packageName } }