-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20041 from wordpress-mobile/issue/site-monitor-sk…
…eleton-activity-vm + Adds: the Skeleton classes for Site Monitoring Screen
- Loading branch information
Showing
8 changed files
with
182 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
WordPress/src/main/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ress/src/test/java/org/wordpress/android/ui/sitemonitor/SiteMonitorParentViewModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters