From 5a8566ad9135e793cf59bc5ede57870062e63535 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 15:13:48 +0530 Subject: [PATCH 01/10] + Adds: Site monitoring parent activity --- .../sitemonitor/SiteMonitorParentActivity.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt new file mode 100644 index 000000000000..f431e69b272e --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt @@ -0,0 +1,46 @@ +package org.wordpress.android.ui.sitemonitor + +import android.annotation.SuppressLint +import android.os.Bundle +import androidx.activity.compose.setContent +import androidx.appcompat.app.AppCompatActivity +import androidx.compose.material.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import org.wordpress.android.R +import org.wordpress.android.ui.compose.components.MainTopAppBar +import org.wordpress.android.ui.compose.components.NavigationIcons +import org.wordpress.android.ui.compose.theme.AppTheme + +class SiteMonitorParentActivity: AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + AppTheme { + SiteMonitorScreen() + } + } + } + + @Composable + @SuppressLint("UnusedMaterialScaffoldPaddingParameter") + fun SiteMonitorScreen(modifier: Modifier = Modifier) { + Scaffold( + topBar = { + MainTopAppBar( + title = stringResource(id = R.string.site_monitoring), + navigationIcon = NavigationIcons.BackIcon, + onNavigationIconClick = onBackPressedDispatcher::onBackPressed, + ) + }, + content = { + TabScreen(modifier = modifier) + } + ) + } + + @Composable + fun TabScreen(modifier: Modifier = Modifier) { + } +} From 1f704c390a981f76386ebc7365132edf60b6ebbf Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 15:18:42 +0530 Subject: [PATCH 02/10] + Adds: Site monitoring parent activity to manifest --- WordPress/src/main/AndroidManifest.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index ebce3220aa18..edba81e6e442 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -1123,6 +1123,11 @@ android:label="@string/stats" android:theme="@style/WordPress.NoActionBar"/> + + From 503221e7b992eaaf131f273046bfcd187e477284 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 15:36:39 +0530 Subject: [PATCH 03/10] + Adds: the logic to navigate to SiteMonitorParentActivity from more --- .../java/org/wordpress/android/ui/ActivityNavigator.kt | 7 ++++--- 1 file changed, 4 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 505f0db65752..b37b30457c37 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt @@ -27,6 +27,7 @@ import org.wordpress.android.ui.mysite.menu.KEY_QUICK_START_EVENT import org.wordpress.android.ui.mysite.menu.MenuActivity import org.wordpress.android.ui.mysite.personalization.PersonalizationActivity import org.wordpress.android.ui.quickstart.QuickStartEvent +import org.wordpress.android.ui.sitemonitor.SiteMonitorParentActivity import org.wordpress.android.util.ToastUtils import org.wordpress.android.util.analytics.AnalyticsUtils import javax.inject.Inject @@ -158,9 +159,9 @@ class ActivityNavigator @Inject constructor() { } fun navigateToSiteMonitoring(context: Context, site: SiteModel) { - // todo: Implement this method after the SiteMonitorActivity is available and remove the lines below - site.name - context.packageName + val intent = Intent(context, SiteMonitorParentActivity::class.java) + intent.putExtra(WordPress.SITE, site) + context.startActivity(intent) } } From 767d7c15f12aefbadd7525d3185b3c9eb84450ef Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 15:37:02 +0530 Subject: [PATCH 04/10] + Adds: Tabs to SiteMonitorParentActivity and resources --- .../sitemonitor/SiteMonitorParentActivity.kt | 42 +++++++++++++++++++ WordPress/src/main/res/values/strings.xml | 3 ++ 2 files changed, 45 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt index f431e69b272e..502891a85189 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt @@ -4,8 +4,18 @@ import android.annotation.SuppressLint import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.MaterialTheme import androidx.compose.material.Scaffold +import androidx.compose.material.TabRow +import androidx.compose.material.Text +import androidx.compose.material3.Tab import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import org.wordpress.android.R @@ -41,6 +51,38 @@ class SiteMonitorParentActivity: AppCompatActivity() { } @Composable + @SuppressLint("UnusedMaterialScaffoldPaddingParameter") fun TabScreen(modifier: Modifier = Modifier) { + var tabIndex by remember { mutableStateOf(0) } + + val tabs = listOf( + R.string.site_monitoring_tab_title_metrics, + R.string.site_monitoring_tab_title_php_logs, + R.string.site_monitoring_tab_title_web_server_logs + ) + + Column(modifier = modifier.fillMaxWidth()) { + TabRow( + selectedTabIndex = tabIndex, + backgroundColor = MaterialTheme.colors.surface, + contentColor = MaterialTheme.colors.onSurface, + ) { + tabs.forEachIndexed { index, title -> + Tab(text = { Text(stringResource(id = title)) }, + selected = tabIndex == index, + onClick = { tabIndex = index } + ) + } + } + when (tabIndex) { + 0 -> SiteMonitoringWebView() + 1 -> SiteMonitoringWebView() + 2 -> SiteMonitoringWebView() + } + } + } + + @Composable + fun SiteMonitoringWebView(){ } } diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index ae6ac289d922..a52ebbf5804e 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -4856,4 +4856,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". --> Site Monitoring + Metrics + PHP Logs + Web Server Logs From 2a15978c86328a22202c1bb739ae0fec6624b9a2 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 17:30:20 +0530 Subject: [PATCH 05/10] + Adds: SiteMonitorParentViewModel class for handling ui logic --- .../sitemonitor/SiteMonitorParentViewModel.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt new file mode 100644 index 000000000000..b415cc609e7d --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt @@ -0,0 +1,26 @@ +package org.wordpress.android.ui.sitemonitor + +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.CoroutineDispatcher +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.modules.BG_THREAD +import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.viewmodel.ScopedViewModel +import javax.inject.Inject +import javax.inject.Named + +@HiltViewModel +class SiteMonitorParentViewModel @Inject constructor( + @param:Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, + private val analyticsTrackerWrapper: AnalyticsTrackerWrapper +) : ScopedViewModel(bgDispatcher) { + private lateinit var site: SiteModel + + fun start(site: SiteModel) { + this.site = site + trackActivityLaunched() + } + + private fun trackActivityLaunched() { + } +} From a0e91725132ab5a2d013ef0b76e68acea1408d19 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 17:30:49 +0530 Subject: [PATCH 06/10] + Adds: Viewmodel to activity and calls to start function --- .../ui/sitemonitor/SiteMonitorParentActivity.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt index 502891a85189..937793055de1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt @@ -3,6 +3,7 @@ package org.wordpress.android.ui.sitemonitor import android.annotation.SuppressLint import android.os.Bundle import androidx.activity.compose.setContent +import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth @@ -18,21 +19,33 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R +import org.wordpress.android.WordPress +import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.compose.components.MainTopAppBar import org.wordpress.android.ui.compose.components.NavigationIcons import org.wordpress.android.ui.compose.theme.AppTheme +import org.wordpress.android.util.extensions.getSerializableExtraCompat +@AndroidEntryPoint class SiteMonitorParentActivity: AppCompatActivity() { + val viewModel:SiteMonitorParentViewModel by viewModels() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { AppTheme { + viewModel.start(getSite()) SiteMonitorScreen() } } } + private fun getSite(): SiteModel { + return requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) as SiteModel + } + @Composable @SuppressLint("UnusedMaterialScaffoldPaddingParameter") fun SiteMonitorScreen(modifier: Modifier = Modifier) { From b84ac3c563280c3b597f65f3198de949995b342c Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 17:31:08 +0530 Subject: [PATCH 07/10] + Adds: Logic to track when the screen is shown --- .../android/ui/sitemonitor/SiteMonitorParentViewModel.kt | 4 ++++ .../org/wordpress/android/analytics/AnalyticsTracker.java | 3 ++- .../wordpress/android/analytics/AnalyticsTrackerNosara.java | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt index b415cc609e7d..164880dc91f1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt @@ -2,6 +2,7 @@ package org.wordpress.android.ui.sitemonitor import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineDispatcher +import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -22,5 +23,8 @@ class SiteMonitorParentViewModel @Inject constructor( } private fun trackActivityLaunched() { + analyticsTrackerWrapper.track( + AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN + ) } } diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index fbc2df7a413e..b00de495bc70 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -1101,7 +1101,8 @@ public enum Stat { DYNAMIC_DASHBOARD_CARD_TAPPED, DYNAMIC_DASHBOARD_CARD_CTA_TAPPED, DYNAMIC_DASHBOARD_CARD_HIDE_TAPPED, - DEEP_LINK_FAILED + DEEP_LINK_FAILED, + SITE_MONITORING_SCREEN_SHOWN } private static final List TRACKERS = new ArrayList<>(); diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index 1ea594ddff90..b6a994767f9c 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -2697,6 +2697,8 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "dynamic_dashboard_card_hide_tapped"; case DEEP_LINK_FAILED: return "deep_link_failed"; + case SITE_MONITORING_SCREEN_SHOWN: + return "site_monitoring_screen_shown"; } return null; } From a16701c4329fe9a8d2bf33955e6eff1e302a01c5 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 17:41:40 +0530 Subject: [PATCH 08/10] * Fixes: Formatting --- .../android/ui/sitemonitor/SiteMonitorParentViewModel.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt index 164880dc91f1..00c337746eed 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt @@ -23,8 +23,6 @@ class SiteMonitorParentViewModel @Inject constructor( } private fun trackActivityLaunched() { - analyticsTrackerWrapper.track( - AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN - ) + analyticsTrackerWrapper.track(AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN) } } From 238734b6bd319a6cbd1116afeab336574e93b2eb Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 17:53:08 +0530 Subject: [PATCH 09/10] + Adds: Unit tests for SiteMonitorParentViewModel --- .../SiteMonitorParentViewModelTest.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 WordPress/src/test/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModelTest.kt diff --git a/WordPress/src/test/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModelTest.kt new file mode 100644 index 000000000000..7f2031d8b1c5 --- /dev/null +++ b/WordPress/src/test/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModelTest.kt @@ -0,0 +1,36 @@ +package org.wordpress.android.ui.sitemonitor + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnitRunner +import org.mockito.kotlin.mock +import org.mockito.kotlin.verify +import org.wordpress.android.BaseUnitTest +import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper + +@ExperimentalCoroutinesApi +@RunWith(MockitoJUnitRunner::class) +class SiteMonitorParentViewModelTest: BaseUnitTest(){ + @Mock + private lateinit var analyticsTrackerWrapper: AnalyticsTrackerWrapper + + private lateinit var viewModel: SiteMonitorParentViewModel + + @Before + fun setUp() { + viewModel = SiteMonitorParentViewModel(testDispatcher(), analyticsTrackerWrapper) + } + + @Test + fun `when viewmodel is started, then screen shown tracking is done`() { + val site = mock() + viewModel.start(site) + + verify(analyticsTrackerWrapper).track(AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN) + } +} From f9109c88e54c211a2bddccdbf7e105e8acbae99d Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 25 Jan 2024 18:13:45 +0530 Subject: [PATCH 10/10] + Adds: Placeholder text view to fix detekt issues --- .../android/ui/sitemonitor/SiteMonitorParentActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt index 937793055de1..96087a86b48e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt @@ -97,5 +97,6 @@ class SiteMonitorParentActivity: AppCompatActivity() { @Composable fun SiteMonitoringWebView(){ + Text(text = "SiteMonitoringWebView") } }