UI: handle back press on Model Selection screen

This commit is contained in:
Han Yin 2025-04-20 19:51:32 -07:00
parent d1b018e375
commit a8dc825aef
3 changed files with 22 additions and 4 deletions

View File

@ -293,6 +293,9 @@ fun AppContent(
// Model Selection Screen
composable(AppDestinations.MODEL_SELECTION_ROUTE) {
ModelSelectionScreen(
onNavigateBack = {
navigationActions.navigateUp()
},
onModelConfirmed = { modelInfo ->
navigationActions.navigateToModelLoading()
},

View File

@ -1,5 +1,6 @@
package com.example.llama.revamp.ui.screens
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
@ -47,9 +48,9 @@ fun ModelSelectionScreen(
val models by viewModel.availableModels.collectAsState()
val preselectedModel by viewModel.preselectedModel.collectAsState()
val handleModelSelection = { model: ModelInfo ->
viewModel.confirmSelectedModel(model)
onModelConfirmed(model)
// Handle back button press
BackHandler(preselectedModel != null) {
viewModel.onBackPressed()
}
Box(modifier = Modifier.fillMaxSize()) {
@ -89,7 +90,12 @@ fun ModelSelectionScreen(
exit = scaleOut() + fadeOut()
) {
FloatingActionButton(
onClick = { preselectedModel?.let { handleModelSelection(it) } },
onClick = {
preselectedModel?.let {
viewModel.confirmSelectedModel(it)
onModelConfirmed(it)
}
},
containerColor = MaterialTheme.colorScheme.primary
) {
Icon(

View File

@ -55,6 +55,15 @@ class ModelSelectionViewModel @Inject constructor(
_preselectedModel.value = null
}
/**
* Handle back press from both back button and top bar
*/
fun onBackPressed() {
if (_preselectedModel.value != null) {
resetSelection()
}
}
companion object {
private val TAG = ModelSelectionViewModel::class.java.simpleName