UI: hide share fab after clearing all benchmark results
This commit is contained in:
parent
c848005d11
commit
b75377676f
|
|
@ -259,6 +259,7 @@ fun AppContent(
|
||||||
|
|
||||||
// Benchmark screen
|
// Benchmark screen
|
||||||
currentRoute.startsWith(AppDestinations.BENCHMARK_ROUTE) -> {
|
currentRoute.startsWith(AppDestinations.BENCHMARK_ROUTE) -> {
|
||||||
|
val showShareFab by benchmarkViewModel.showShareFab.collectAsState()
|
||||||
val showModelCard by benchmarkViewModel.showModelCard.collectAsState()
|
val showModelCard by benchmarkViewModel.showModelCard.collectAsState()
|
||||||
|
|
||||||
ScaffoldConfig(
|
ScaffoldConfig(
|
||||||
|
|
@ -272,6 +273,7 @@ fun AppContent(
|
||||||
),
|
),
|
||||||
bottomBarConfig = BottomBarConfig.Benchmark(
|
bottomBarConfig = BottomBarConfig.Benchmark(
|
||||||
engineIdle = !engineState.isUninterruptible,
|
engineIdle = !engineState.isUninterruptible,
|
||||||
|
showShareFab = showShareFab,
|
||||||
onShare = { benchmarkViewModel.shareResult(handleScaffoldEvent) },
|
onShare = { benchmarkViewModel.shareResult(handleScaffoldEvent) },
|
||||||
onRerun = { benchmarkViewModel.rerunBenchmark(handleScaffoldEvent) },
|
onRerun = { benchmarkViewModel.rerunBenchmark(handleScaffoldEvent) },
|
||||||
onClear = { benchmarkViewModel.clearResults(handleScaffoldEvent) },
|
onClear = { benchmarkViewModel.clearResults(handleScaffoldEvent) },
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ fun AppScaffold(
|
||||||
|
|
||||||
is BottomBarConfig.Benchmark -> {
|
is BottomBarConfig.Benchmark -> {
|
||||||
BenchmarkBottomBar(
|
BenchmarkBottomBar(
|
||||||
|
showShareFab = config.showShareFab,
|
||||||
engineIdle = config.engineIdle,
|
engineIdle = config.engineIdle,
|
||||||
onShare = config.onShare,
|
onShare = config.onShare,
|
||||||
onRerun = config.onRerun,
|
onRerun = config.onRerun,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import androidx.compose.runtime.Composable
|
||||||
@Composable
|
@Composable
|
||||||
fun BenchmarkBottomBar(
|
fun BenchmarkBottomBar(
|
||||||
engineIdle: Boolean,
|
engineIdle: Boolean,
|
||||||
|
showShareFab: Boolean,
|
||||||
onShare: () -> Unit,
|
onShare: () -> Unit,
|
||||||
onRerun: () -> Unit,
|
onRerun: () -> Unit,
|
||||||
onClear: () -> Unit,
|
onClear: () -> Unit,
|
||||||
|
|
@ -59,7 +60,7 @@ fun BenchmarkBottomBar(
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
// Only show FAB if the benchmark result is ready
|
// Only show FAB if the benchmark result is ready
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = engineIdle,
|
visible = showShareFab,
|
||||||
enter = scaleIn() + fadeIn(),
|
enter = scaleIn() + fadeIn(),
|
||||||
exit = scaleOut() + fadeOut()
|
exit = scaleOut() + fadeOut()
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ sealed class BottomBarConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Benchmark(
|
data class Benchmark(
|
||||||
|
val showShareFab: Boolean,
|
||||||
val engineIdle: Boolean,
|
val engineIdle: Boolean,
|
||||||
val onShare: () -> Unit,
|
val onShare: () -> Unit,
|
||||||
val onRerun: () -> Unit,
|
val onRerun: () -> Unit,
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class BenchmarkViewModel @Inject constructor(
|
||||||
private val _benchmarkResults = MutableStateFlow<List<BenchmarkResult>>(emptyList())
|
private val _benchmarkResults = MutableStateFlow<List<BenchmarkResult>>(emptyList())
|
||||||
val benchmarkResults: StateFlow<List<BenchmarkResult>> = _benchmarkResults.asStateFlow()
|
val benchmarkResults: StateFlow<List<BenchmarkResult>> = _benchmarkResults.asStateFlow()
|
||||||
|
|
||||||
// UI state: Model card
|
// UI state: Model card
|
||||||
private val _showModelCard = MutableStateFlow(false)
|
private val _showModelCard = MutableStateFlow(false)
|
||||||
val showModelCard = _showModelCard.asStateFlow()
|
val showModelCard = _showModelCard.asStateFlow()
|
||||||
|
|
||||||
|
|
@ -38,6 +38,10 @@ class BenchmarkViewModel @Inject constructor(
|
||||||
_showModelCard.value = show
|
_showModelCard.value = show
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UI state: Share FAB
|
||||||
|
private val _showShareFab = MutableStateFlow(false)
|
||||||
|
val showShareFab = _showShareFab.asStateFlow()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
benchmarkService.benchmarkResults
|
benchmarkService.benchmarkResults
|
||||||
|
|
@ -61,10 +65,12 @@ class BenchmarkViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
_showShareFab.value = false
|
||||||
val benchmarkStartTs = System.currentTimeMillis()
|
val benchmarkStartTs = System.currentTimeMillis()
|
||||||
benchmarkService.benchmark(pp, tg, pl, nr)
|
benchmarkService.benchmark(pp, tg, pl, nr)
|
||||||
val benchmarkEndTs = System.currentTimeMillis()
|
val benchmarkEndTs = System.currentTimeMillis()
|
||||||
_benchmarkDuration.emit(benchmarkEndTs - benchmarkStartTs)
|
_benchmarkDuration.emit(benchmarkEndTs - benchmarkStartTs)
|
||||||
|
_showShareFab.value = true
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -76,6 +82,7 @@ class BenchmarkViewModel @Inject constructor(
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
_benchmarkResults.value = emptyList()
|
_benchmarkResults.value = emptyList()
|
||||||
|
_showShareFab.value = false
|
||||||
onScaffoldEvent?.invoke(ScaffoldEvent.ShowSnackbar(
|
onScaffoldEvent?.invoke(ScaffoldEvent.ShowSnackbar(
|
||||||
message = "All benchmark results cleared."
|
message = "All benchmark results cleared."
|
||||||
))
|
))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue