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

Hide tap results after tap #287

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -414,6 +414,7 @@ class Dependencies(
goToReviewDescriptorUpdates = goToReviewDescriptorUpdates,
getTestDescriptors = getTestDescriptors::invoke,
observeRunBackgroundState = runBackgroundStateManager.observeState(),
setRunBackgroundState = runBackgroundStateManager::updateState,
observeTestRunErrors = runBackgroundStateManager.observeErrors(),
shouldShowVpnWarning = shouldShowVpnWarning::invoke,
fetchDescriptorUpdate = fetchDescriptorUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.take
Expand All @@ -15,8 +16,8 @@ import org.ooni.probe.data.models.Descriptor
import org.ooni.probe.data.models.DescriptorType
import org.ooni.probe.data.models.DescriptorUpdatesStatus
import org.ooni.probe.data.models.InstalledTestDescriptorModel
import org.ooni.probe.data.models.TestRunError
import org.ooni.probe.data.models.RunBackgroundState
import org.ooni.probe.data.models.TestRunError
import org.ooni.probe.data.models.UpdateStatusType

class DashboardViewModel(
Expand All @@ -29,6 +30,7 @@ class DashboardViewModel(
goToReviewDescriptorUpdates: () -> Unit,
getTestDescriptors: () -> Flow<List<Descriptor>>,
observeRunBackgroundState: Flow<RunBackgroundState>,
setRunBackgroundState: ((RunBackgroundState) -> RunBackgroundState) -> Unit,
observeTestRunErrors: Flow<TestRunError>,
shouldShowVpnWarning: suspend () -> Boolean,
fetchDescriptorUpdate: suspend (List<InstalledTestDescriptorModel>) -> Unit,
Expand All @@ -47,14 +49,17 @@ class DashboardViewModel(
.onEach { firstRun -> if (firstRun) goToOnboarding() }
.launchIn(viewModelScope)

observeAvailableUpdatesState().onEach { updates ->
_state.update {
it.copy(
availableUpdates = updates.availableUpdates.toList(),
refreshType = updates.refreshType,
)
observeAvailableUpdatesState()
.onEach { updates ->
_state.update {
it.copy(
availableUpdates = updates.availableUpdates.toList(),
refreshType = updates.refreshType,
)
}
}
}.launchIn(viewModelScope)
.launchIn(viewModelScope)

getTestDescriptors()
.onEach { tests ->
_state.update { it.copy(descriptors = tests.groupByType()) }
Expand Down Expand Up @@ -85,7 +90,13 @@ class DashboardViewModel(

events
.filterIsInstance<Event.SeeResultsClick>()
.onEach { goToResults() }
.onEach {
val runState = observeRunBackgroundState.first()
if (runState is RunBackgroundState.Idle && runState.justFinishedTest) {
setRunBackgroundState { runState.copy(justFinishedTest = false) }
}
goToResults()
}
.launchIn(viewModelScope)

events
Expand All @@ -97,9 +108,7 @@ class DashboardViewModel(

events
.filterIsInstance<Event.DescriptorClicked>()
.onEach { event ->
goToDescriptor(event.descriptor.key)
}
.onEach { event -> goToDescriptor(event.descriptor.key) }
.launchIn(viewModelScope)

events
Expand All @@ -109,30 +118,40 @@ class DashboardViewModel(
}
.launchIn(viewModelScope)

events.filterIsInstance<Event.FetchUpdatedDescriptors>().onEach {
state.value.descriptors[DescriptorType.Installed]
?.map { (it.source as Descriptor.Source.Installed).value }
?.let { descriptors ->
fetchDescriptorUpdate(descriptors)
events
.filterIsInstance<Event.FetchUpdatedDescriptors>()
.onEach {
state.value.descriptors[DescriptorType.Installed]
?.map { (it.source as Descriptor.Source.Installed).value }
?.let { descriptors ->
fetchDescriptorUpdate(descriptors)
}
}.launchIn(viewModelScope)

events
.filterIsInstance<Event.ReviewUpdatesClicked>()
.onEach {
_state.update {
it.copy(
refreshType = UpdateStatusType.None,
)
}
}.launchIn(viewModelScope)
events.filterIsInstance<Event.ReviewUpdatesClicked>().onEach {
_state.update {
it.copy(
refreshType = UpdateStatusType.None,
)
reviewUpdates(state.value.availableUpdates)
goToReviewDescriptorUpdates()
}
reviewUpdates(state.value.availableUpdates)
goToReviewDescriptorUpdates()
}.launchIn(viewModelScope)
events.filterIsInstance<Event.CancelUpdatesClicked>().onEach {
cancelUpdates(state.value.availableUpdates)
_state.update {
it.copy(
refreshType = UpdateStatusType.None,
)
.launchIn(viewModelScope)

events
.filterIsInstance<Event.CancelUpdatesClicked>()
.onEach {
cancelUpdates(state.value.availableUpdates)
_state.update {
it.copy(
refreshType = UpdateStatusType.None,
)
}
}
}.launchIn(viewModelScope)
.launchIn(viewModelScope)
}

fun onEvent(event: Event) {
Expand Down