Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve measurement webview loading UI #291

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ actual fun OoniWebView(
view: WebView,
newProgress: Int,
) {
controller.state = OoniWebViewController.State.Loading(newProgress / 100f)
controller.state = if (newProgress != 100) {
OoniWebViewController.State.Loading(newProgress / 100f)
} else {
OoniWebViewController.State.Finished
}
}
}
webView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ooni.probe.ui.measurement

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
Expand All @@ -9,18 +10,23 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.back
Expand All @@ -41,57 +47,73 @@ fun MeasurementScreen(
onBack: () -> Unit,
onEvent: (MeasurementViewModel.Event) -> Unit,
) {
val controller = OoniWebViewController()
val controller = remember { OoniWebViewController() }

val inputSuffix = input?.let { "?input=${urlEncode(it)}" } ?: ""
val url = "${OrganizationConfig.explorerUrl}/measurement/${reportId.value}$inputSuffix"

Column(Modifier.background(MaterialTheme.colorScheme.background)) {
TopBar(
title = {
Text(stringResource(Res.string.measurement))
},
navigationIcon = {
IconButton(onClick = { onBack() }) {
Icon(
Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(Res.string.back),
)
}
},
actions = {
IconButton(
onClick = {
onEvent(MeasurementViewModel.Event.ShareUrl(url))
},
) {
Icon(
Icons.Default.Share,
contentDescription = null,
)
}
IconButton(
onClick = { controller.reload() },
enabled = controller.state is OoniWebViewController.State.Finished,
) {
Icon(
Icons.Default.Refresh,
contentDescription = stringResource(Res.string.refresh),
)
}
},
)
Box {
TopBar(
title = {
Text(stringResource(Res.string.measurement))
},
navigationIcon = {
IconButton(onClick = { onBack() }) {
Icon(
Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(Res.string.back),
)
}
},
actions = {
IconButton(
onClick = {
onEvent(MeasurementViewModel.Event.ShareUrl(url))
},
) {
Icon(
Icons.Default.Share,
contentDescription = null,
)
}
if (controller.state is OoniWebViewController.State.Loading) {
CircularProgressIndicator(
color = MaterialTheme.colorScheme.onPrimary,
trackColor = Color.Transparent,
strokeWidth = 2.dp,
modifier = Modifier
.padding(12.dp)
.size(24.dp),
)
} else {
IconButton(
onClick = { controller.reload() },
enabled = controller.state is OoniWebViewController.State.Finished,
) {
Icon(
Icons.Default.Refresh,
contentDescription = stringResource(Res.string.refresh),
)
}
}
},
)

LinearProgressIndicator(
progress = {
(controller.state as? OoniWebViewController.State.Loading)?.progress ?: 1f
},
color = MaterialTheme.colorScheme.primary,
trackColor = MaterialTheme.colorScheme.onBackground,
modifier = Modifier
.fillMaxWidth()
.height(1.dp),
)
LinearProgressIndicator(
progress = {
(controller.state as? OoniWebViewController.State.Loading)?.progress ?: 0f
},
color = MaterialTheme.colorScheme.onPrimary,
trackColor = Color.Transparent,
drawStopIndicator = {},
modifier = Modifier
.fillMaxWidth()
.align(Alignment.BottomCenter)
.padding(bottom = 2.dp)
.height(2.dp),
)
}

OoniWebView(
controller = controller,
Expand Down