Skip to content

Commit

Permalink
Merge pull request #20041 from wordpress-mobile/issue/site-monitor-sk…
Browse files Browse the repository at this point in the history
…eleton-activity-vm

+ Adds: the Skeleton classes for Site Monitoring Screen
  • Loading branch information
zwarm authored Jan 25, 2024
2 parents eefbd25 + f9109c8 commit e55ce76
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 4 deletions.
5 changes: 5 additions & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,11 @@
android:label="@string/stats"
android:theme="@style/WordPress.NoActionBar"/>

<activity android:name=".ui.sitemonitor.SiteMonitorParentActivity"
android:exported="false"
android:label="@string/site_monitoring"
android:theme="@style/WordPress.NoActionBar"/>

<meta-data android:name="io.sentry.traces.activity.enable" android:value="false" />

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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
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 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) {
Scaffold(
topBar = {
MainTopAppBar(
title = stringResource(id = R.string.site_monitoring),
navigationIcon = NavigationIcons.BackIcon,
onNavigationIconClick = onBackPressedDispatcher::onBackPressed,
)
},
content = {
TabScreen(modifier = modifier)
}
)
}

@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(){
Text(text = "SiteMonitoringWebView")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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
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() {
analyticsTrackerWrapper.track(AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN)
}
}
3 changes: 3 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4856,4 +4856,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". -->

<!-- Site Monitoring -->
<string name="site_monitoring">Site Monitoring</string>
<string name="site_monitoring_tab_title_metrics">Metrics</string>
<string name="site_monitoring_tab_title_php_logs">PHP Logs</string>
<string name="site_monitoring_tab_title_web_server_logs">Web Server Logs</string>
</resources>
Original file line number Diff line number Diff line change
@@ -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<SiteModel>()
viewModel.start(site)

verify(analyticsTrackerWrapper).track(AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tracker> TRACKERS = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e55ce76

Please sign in to comment.