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..505f0db65752 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt @@ -156,5 +156,11 @@ 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) { + // todo: Implement this method after the SiteMonitorActivity is available and remove the lines below + site.name + context.packageName + } } 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/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() { 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/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"), } 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 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 -> {} } } 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 @@ + + + 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 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)