diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/MainActivity.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/MainActivity.kt index 3142e5d977..3831a6140e 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/MainActivity.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/MainActivity.kt @@ -293,21 +293,27 @@ fun AppContent() { } // Model unload confirmation dialog - // TODO-han.yin: show a progress indicator until the model success unloads? + var isUnloading by remember { mutableStateOf(false) } + if (showUnloadDialog) { UnloadModelConfirmationDialog( onConfirm = { - showUnloadDialog = false + isUnloading = true coroutineScope.launch { viewModel.unloadModel() + isUnloading = false + showUnloadDialog = false pendingNavigation?.invoke() pendingNavigation = null } }, onDismiss = { - showUnloadDialog = false - pendingNavigation = null - } + if (!isUnloading) { + showUnloadDialog = false + pendingNavigation = null + } + }, + isUnloading = isUnloading ) } } diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/UnloadModelConfirmationDialog.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/UnloadModelConfirmationDialog.kt index 2f98fc1ef5..620b643d85 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/UnloadModelConfirmationDialog.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/UnloadModelConfirmationDialog.kt @@ -1,9 +1,21 @@ package com.example.llama.revamp.ui.components +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.material3.AlertDialog +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp /** * Confirmation dialog shown when the user attempts to navigate away from @@ -12,27 +24,55 @@ import androidx.compose.runtime.Composable @Composable fun UnloadModelConfirmationDialog( onConfirm: () -> Unit, - onDismiss: () -> Unit + onDismiss: () -> Unit, + isUnloading: Boolean = false ) { AlertDialog( - onDismissRequest = onDismiss, + onDismissRequest = { + // Ignore dismiss requests while unloading the model + if (!isUnloading) onDismiss() + }, title = { Text("Confirm Exit") }, text = { - Text( - "Going back will unload the current model. " + - "This operation cannot be undone. " + - "Any unsaved conversation will be lost." - ) + Column { + Text( + "Going back will unload the current model. " + + "This operation cannot be undone. " + + "Any unsaved conversation will be lost." + ) + + if (isUnloading) { + Spacer(modifier = Modifier.height(16.dp)) + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + CircularProgressIndicator( + modifier = Modifier.size(24.dp), + strokeWidth = 2.dp + ) + Spacer(modifier = Modifier.width(8.dp)) + Text("Unloading model...") + } + } + } }, confirmButton = { - TextButton(onClick = onConfirm) { + TextButton( + onClick = onConfirm, + enabled = !isUnloading + ) { Text("Yes, Exit") } }, dismissButton = { - TextButton(onClick = onDismiss) { + TextButton( + onClick = onDismiss, + enabled = !isUnloading + ) { Text("Cancel") } }