From 2c9b1d37e0a3b67bb7faf1416682f61eb2fadff5 Mon Sep 17 00:00:00 2001 From: Han Yin Date: Mon, 4 Aug 2025 09:04:49 -0700 Subject: [PATCH] UI: add "Learn More" hyperlinks to Error dialog upon model import failures --- .../ui/screens/ModelsManagementScreen.kt | 21 +++++++++++++++++++ .../viewmodel/ModelsManagementViewModel.kt | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelsManagementScreen.kt b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelsManagementScreen.kt index 6e1de7f2b5..df9a0e8d8a 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelsManagementScreen.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelsManagementScreen.kt @@ -1,5 +1,6 @@ package com.example.llama.ui.screens +import android.content.Intent import androidx.activity.compose.BackHandler import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.layout.Arrangement @@ -17,6 +18,7 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.outlined.ContactSupport import androidx.compose.material.icons.filled.Attribution import androidx.compose.material.icons.filled.Download import androidx.compose.material.icons.filled.Error @@ -45,14 +47,17 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.window.DialogProperties +import androidx.core.net.toUri import com.example.llama.data.model.ModelInfo import com.example.llama.data.source.remote.HuggingFaceModel +import com.example.llama.ui.components.InfoAction import com.example.llama.ui.components.InfoView import com.example.llama.ui.components.ModelCardFullExpandable import com.example.llama.ui.scaffold.ScaffoldEvent @@ -185,6 +190,7 @@ fun ModelsManagementScreen( ErrorDialog( title = "Import Failed", message = state.message, + learnMoreUrl = state.learnMoreUrl, onDismiss = { viewModel.resetManagementState() } ) } @@ -662,8 +668,22 @@ private fun BatchDeleteConfirmationDialog( private fun ErrorDialog( title: String, message: String, + learnMoreUrl: String? = null, onDismiss: () -> Unit ) { + val context = LocalContext.current + + val action = learnMoreUrl?.let { url -> + InfoAction( + label = "Learn More", + icon = Icons.AutoMirrored.Outlined.ContactSupport, + onAction = { + val intent = Intent(Intent.ACTION_VIEW, url.toUri()) + context.startActivity(intent) + } + ) + } + AlertDialog( onDismissRequest = onDismiss, text = { @@ -672,6 +692,7 @@ private fun ErrorDialog( title = title, icon = Icons.Default.Error, message = message, + action = action ) }, confirmButton = { diff --git a/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ModelsManagementViewModel.kt b/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ModelsManagementViewModel.kt index 79ed1ea0ec..ff5090d784 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ModelsManagementViewModel.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ModelsManagementViewModel.kt @@ -212,10 +212,12 @@ class ModelsManagementViewModel @Inject constructor( } catch (_: InvalidFileFormatException) { _managementState.value = Importation.Error( message = "Not a valid GGUF model!", + learnMoreUrl = "https://huggingface.co/docs/hub/en/gguf", ) } catch (e: InsufficientStorageException) { _managementState.value = Importation.Error( message = e.message ?: "Insufficient storage space to import $fileName", + learnMoreUrl = "https://support.google.com/android/answer/7431795?hl=en", ) } catch (e: Exception) { Log.e(TAG, "Unknown exception importing $fileName", e) @@ -382,8 +384,7 @@ sealed class ModelManagementState { data class Confirming(val uri: Uri, val fileName: String, val fileSize: Long) : Importation() data class Importing(val progress: Float = 0f, val fileName: String, val fileSize: Long, val isCancelling: Boolean = false) : Importation() data class Success(val model: ModelInfo) : Importation() - // TODO-han.yin: Add an optional explanation URL for more info! - data class Error(val message: String) : Importation() + data class Error(val message: String, val learnMoreUrl: String? = null) : Importation() } sealed class Download: ModelManagementState() {