Skip to content

Commit

Permalink
Merge pull request #20092 from wordpress-mobile/issue/20089-site-moni…
Browse files Browse the repository at this point in the history
…tor-loading-state-view-adjustments

Fixes: the padding of the Loading Indicator
  • Loading branch information
pantstamp authored Feb 1, 2024
2 parents ec4b610 + e908553 commit 96b6b96
Showing 1 changed file with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,24 @@ class SiteMonitorParentActivity : AppCompatActivity(), SiteMonitorWebViewClient.
val uiState by remember(key1 = tabType) {
siteMonitorParentViewModel.getUiState(tabType)
}
LazyColumn {
item {
when (uiState) {
is SiteMonitorUiState.Preparing -> LoadingState(modifier)
is SiteMonitorUiState.Prepared, is SiteMonitorUiState.Loaded ->
SiteMonitorWebView(uiState, tabType, modifier)
is SiteMonitorUiState.Error -> SiteMonitorError(uiState as SiteMonitorUiState.Error, modifier)
}
}
when (uiState) {
is SiteMonitorUiState.Preparing -> LoadingState(modifier)
is SiteMonitorUiState.Prepared, is SiteMonitorUiState.Loaded ->
SiteMonitorWebViewContent(uiState, tabType, modifier)

is SiteMonitorUiState.Error -> SiteMonitorError(uiState as SiteMonitorUiState.Error, modifier)
}
}

@Composable
fun LoadingState(modifier: Modifier = Modifier) {
Box(
contentAlignment = Alignment.Center,
modifier = modifier.fillMaxSize()
) {
CircularProgressIndicator()
CircularProgressIndicator(
color = MaterialTheme.colors.onSurface
)
}
}

Expand Down Expand Up @@ -276,32 +276,44 @@ class SiteMonitorParentActivity : AppCompatActivity(), SiteMonitorWebViewClient.

@SuppressLint("SetJavaScriptEnabled")
@Composable
private fun SiteMonitorWebView(
private fun SiteMonitorWebViewContent(
uiState: SiteMonitorUiState,
tabType: SiteMonitorType,
modifier: Modifier = Modifier
) {
// retrieve the webview from the actvity
var webView = when (tabType) {
val webView = when (tabType) {
SiteMonitorType.METRICS -> metricsWebView
SiteMonitorType.PHP_LOGS -> phpLogsWebView
SiteMonitorType.WEB_SERVER_LOGS -> webServerLogsWebView
}

if (uiState is SiteMonitorUiState.Prepared) {
webView.postUrl(WPWebViewActivity.WPCOM_LOGIN_URL, uiState.model.addressToLoad.toByteArray())
when(uiState) {
is SiteMonitorUiState.Prepared -> {
webView.postUrl(WPWebViewActivity.WPCOM_LOGIN_URL, uiState.model.addressToLoad.toByteArray())
LoadingState()
}
is SiteMonitorUiState.Loaded -> {
SiteMonitorWebView(webView, modifier)
}
else -> {}
}
}

@Composable
private fun SiteMonitorWebView(tabWebView: WebView, modifier: Modifier = Modifier) {
// the webview is retrieved from the activity, so we need to use a mutable variable
// to assign to android view

var webView = tabWebView
Box(
modifier = modifier.fillMaxSize(),
contentAlignment = Alignment.Center
modifier = modifier
.fillMaxSize()
) {
if (uiState is SiteMonitorUiState.Prepared) {
LoadingState()
} else {
webView.let { theWebView ->
LazyColumn(modifier = Modifier.fillMaxHeight()) {
item {
AndroidView(
factory = { theWebView },
factory = { webView },
update = { webView = it },
modifier = Modifier.fillMaxWidth()
)
Expand Down

0 comments on commit 96b6b96

Please sign in to comment.