Skip to content

Commit

Permalink
chore: added proxy label to running screen
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Oct 22, 2024
1 parent f85a595 commit 0520b6a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<string name="Dashboard_Running_EstimatedTimeLeft">Estimated time left:</string>
<string name="Dashboard_Running_Stopping_Title">Stopping test…</string>
<string name="Dashboard_Running_Stopping_Notice">Finishing the currently pending tests, please wait…</string>
<string name="Dashboard_Running_ProxyInUse">Proxy in use</string>
<string name="Dashboard_RunV2_Ooni_Title">OONI Tests</string>
<string name="Dashboard_RunV2_Title">OONI Run Links</string>
<string name="Dashboard_RunV2_RunFinished">Run finished. Tap to view results.</string>
Expand Down Expand Up @@ -231,7 +232,7 @@
<string name="Modal_Autorun_BatteryOptimization">OONI Probe cannot run automatically without battery optimization. Do you want to try again?</string>

<!-- New Strings -->
<string name="Dashboard_Runv2_Overview_LastUpdatd">Last updated %1$s</string>
<string name="Dashboard_Runv2_Overview_LastUpdatd">Last updated %1$s</string>
<string name="back">Back</string>
<string name="refresh">refresh</string>
<string name="measurement">Measurement</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class Dependencies(
observeTestRunState = testStateManager.observeState(),
observeTestRunErrors = testStateManager.observeErrors(),
cancelTestRun = testStateManager::cancelTestRun,
preferencesRepository = preferenceRepository,
)

fun runViewModel(onBack: () -> Unit) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.AssistChip
import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -33,13 +35,15 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import ooniprobe.composeapp.generated.resources.Dashboard_Running_EstimatedTimeLeft
import ooniprobe.composeapp.generated.resources.Dashboard_Running_ProxyInUse
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Running
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Stopping_Notice
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Stopping_Title
import ooniprobe.composeapp.generated.resources.Notification_StopTest
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.back
import ooniprobe.composeapp.generated.resources.ooni_empty_state
import ooniprobe.composeapp.generated.resources.test_circumvention
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.ooni.probe.data.models.TestRunState
Expand Down Expand Up @@ -80,7 +84,7 @@ fun RunningScreen(
)

when (state.testRunState) {
is TestRunState.Running -> TestRunning(state.testRunState, onEvent)
is TestRunState.Running -> TestRunning(state.hasProxy, state.testRunState, onEvent)
TestRunState.Stopping -> TestStopping()
else -> Unit
}
Expand All @@ -95,6 +99,7 @@ fun RunningScreen(

@Composable
private fun TestRunning(
hasProxy: Boolean,
state: TestRunState.Running,
onEvent: (RunningViewModel.Event) -> Unit,
) {
Expand All @@ -121,6 +126,29 @@ private fun TestRunning(
fontWeight = FontWeight.Bold,
)
}
if (hasProxy)
{
AssistChip(
onClick = { },
label = {
Text(
text = stringResource(Res.string.Dashboard_Running_ProxyInUse),
style = MaterialTheme.typography.bodyLarge,
)
},
leadingIcon = {
Icon(
painter = painterResource(Res.drawable.test_circumvention),
contentDescription = null,
modifier = Modifier.size(AssistChipDefaults.IconSize),
tint = MaterialTheme.customColors.onDescriptor,
)
},
colors = AssistChipDefaults.assistChipColors(
labelColor = MaterialTheme.customColors.onDescriptor,
),
)
}
}

if (state.descriptor?.animation != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,40 @@ import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import org.ooni.probe.data.models.ProxySettings
import org.ooni.probe.data.models.SettingsKey
import org.ooni.probe.data.models.TestRunError
import org.ooni.probe.data.models.TestRunState
import org.ooni.probe.ui.dashboard.DashboardViewModel.Event
import org.ooni.probe.data.repositories.PreferenceRepository

class RunningViewModel(
onBack: () -> Unit,
goToResults: () -> Unit,
observeTestRunState: Flow<TestRunState>,
observeTestRunErrors: Flow<TestRunError>,
cancelTestRun: () -> Unit,
preferencesRepository: PreferenceRepository,
) : ViewModel() {
private val events = MutableSharedFlow<Event>(extraBufferCapacity = 1)

private val _state = MutableStateFlow(State())
val state = _state.asStateFlow()

init {
preferencesRepository.allSettings(
listOf(
SettingsKey.PROXY_PROTOCOL,
SettingsKey.PROXY_HOSTNAME,
SettingsKey.PROXY_PORT,
),
).onEach { proxySettings ->
val proxy = ProxySettings.newProxySettings(
protocol = proxySettings[SettingsKey.PROXY_PROTOCOL] as? String,
hostname = proxySettings[SettingsKey.PROXY_HOSTNAME] as? String,
port = proxySettings[SettingsKey.PROXY_PORT] as? String,
).getProxyString()
_state.update { it.copy(hasProxy = proxy.isNotEmpty()) }
}.launchIn(viewModelScope)
observeTestRunState
.onEach { testRunState ->
if (testRunState is TestRunState.Idle) {
Expand Down Expand Up @@ -72,6 +89,7 @@ class RunningViewModel(
data class State(
val testRunState: TestRunState? = null,
val testRunErrors: List<TestRunError> = emptyList(),
val hasProxy: Boolean = false,
)

sealed interface Event {
Expand Down

0 comments on commit 0520b6a

Please sign in to comment.