translate: drop the load-failure retry UI, back to the loading state (#842)
- Commit
4da2fd61d4aef2dd9993f5405718620a60c95771- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-06 04:43 UTC (1 month ago)
- Parents
f31534b
Undo 197deb2fe. That commit replaced the endless "Loading translator…" spinner with a terminal error state and a Retry button on the text and camera screens. The retry UI is not wanted, so the translate screens go back to their pre-197deb2fe behavior: a failed NLLB load leaves the "Loading translator…" state showing, as originally reported in #842. The underlying load failure (on GPUs without shaderFloat16 / storageBuffer16BitAccess, the shared Vulkan context refuses every model) is unchanged and #842 stays open. Verified: `git diff 197deb2fe^ -- translate/` is empty, so translate/ is byte-identical to before that commit.
Diff
translate/src/main/java/com/vayunmathur/translate/platform/NllbTranslator.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/platform/NllbTranslator.kt b/translate/src/main/java/com/vayunmathur/translate/platform/NllbTranslator.ktindex aa4bdcc813..090983cf13 100644--- a/translate/src/main/java/com/vayunmathur/translate/platform/NllbTranslator.kt+++ b/translate/src/main/java/com/vayunmathur/translate/platform/NllbTranslator.kt@@ -37,20 +37,11 @@ class NllbTranslator(private val context: Context) : TranslationEngine { private var model: NllbHandle? = null private var attempts = 0 private var closed = false- private var failed = false override suspend fun isAvailable(): Boolean = withContext(Dispatchers.Default) { lock.withLock { ensure() != null } } - /**- * True once [ensure] has failed terminally (missing native library, no fp16- * Vulkan device, corrupt weights). Distinct from "still loading": when the- * engine is only warming up this is false, so the UI can show a spinner in- * one case and a retryable error in the other instead of spinning forever.- */- suspend fun loadFailed(): Boolean = lock.withLock { failed && model == null }- override suspend fun detectLanguage(text: String): String? = null // Broad catch is deliberate: the native translator throws undocumented@@ -75,10 +66,7 @@ class NllbTranslator(private val context: Context) : TranslationEngine { } /** Call after a successful model download so the next use loads it. */- suspend fun reset() = lock.withLock {- attempts = 0- failed = false- }+ suspend fun reset() = lock.withLock { attempts = 0 } /** * Free the model. Terminal: nothing loads again afterwards, and it is idempotent.@@ -105,13 +93,7 @@ class NllbTranslator(private val context: Context) : TranslationEngine { */ private fun ensure(): NllbHandle? { model?.let { return it }- if (closed || attempts >= MAX_ATTEMPTS) {- // Both attempts failed, or the translator was already attempted and- // closed: this is a terminal load failure, not a download still in- // flight. Latch it so the UI can say so instead of spinning forever.- failed = attempts >= MAX_ATTEMPTS- return null- }+ if (closed || attempts >= MAX_ATTEMPTS) return null if (!NllbModel.isDownloaded(context)) return null attempts++ val reclaimed = NllbModel.deleteRetired(context)@@ -121,7 +103,6 @@ class NllbTranslator(private val context: Context) : TranslationEngine { val handle = NllbHandle.inDirectory(NllbModel.modelDir(context)) if (!handle.isAvailable) { handle.close()- if (attempts >= MAX_ATTEMPTS) failed = true return null } model = handle
translate/src/main/java/com/vayunmathur/translate/platform/TranslateUiContract.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/platform/TranslateUiContract.kt b/translate/src/main/java/com/vayunmathur/translate/platform/TranslateUiContract.ktindex 1c2f94fd59..2bccbd8aaf 100644--- a/translate/src/main/java/com/vayunmathur/translate/platform/TranslateUiContract.kt+++ b/translate/src/main/java/com/vayunmathur/translate/platform/TranslateUiContract.kt@@ -35,8 +35,6 @@ data class TextTranslateUiState( val targetLang: String = "es", /** False only while the NLLB engine is still loading; the model itself is pre-installed. */ val translationAvailable: Boolean = false,- /** True once loading the engine has failed terminally; pairs with a Retry action. */- val translationLoadFailed: Boolean = false, val inputText: String = "", val outputText: String = "", val isTranslating: Boolean = false,@@ -61,9 +59,6 @@ interface TextTranslateActions { /** The mic FAB: start listening, stop, or — while transcribing — nothing. */ fun toggleMic() {} - /** Retry loading the translation engine after a terminal load failure. */- fun retryTranslator() {}- fun copyOutput() {} fun speakOutput() {} fun toggleFavorite() {}
translate/src/main/java/com/vayunmathur/translate/platform/TranslateViewModel.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/platform/TranslateViewModel.kt b/translate/src/main/java/com/vayunmathur/translate/platform/TranslateViewModel.ktindex 8c2cb4b9b7..dd76ebbcc8 100644--- a/translate/src/main/java/com/vayunmathur/translate/platform/TranslateViewModel.kt+++ b/translate/src/main/java/com/vayunmathur/translate/platform/TranslateViewModel.kt@@ -50,15 +50,6 @@ class TranslateViewModel(app: Application) : AndroidViewModel(app) { private val _translationAvailable = MutableStateFlow(false) val translationAvailable: StateFlow<Boolean> = _translationAvailable.asStateFlow() - /**- * True once loading the engine has failed terminally (missing native- * library, no fp16 Vulkan device, corrupt weights) rather than merely not- * yet finished. The text screen shows a retryable error in that case- * instead of an endless "loading" spinner.- */- private val _translationLoadFailed = MutableStateFlow(false)- val translationLoadFailed: StateFlow<Boolean> = _translationLoadFailed.asStateFlow()- /** Saved translations, favorites first then newest — for the history screen. */ val history: StateFlow<List<TranslationRecord>> = historyRepo.history.stateIn( viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList(),@@ -75,26 +66,7 @@ class TranslateViewModel(app: Application) : AndroidViewModel(app) { _targetLang.value = settings.target() _recentSourceLangs.value = settings.recentSources() _recentTargetLangs.value = settings.recentTargets()- refreshTranslatorState()- }- }-- /** Re-read the engine state after init or a manual retry. */- private suspend fun refreshTranslatorState() {- _translationAvailable.value = translator.isAvailable()- _translationLoadFailed.value =- !_translationAvailable.value && (translator as? NllbTranslator)?.loadFailed() == true- }-- /**- * Retry loading the translation engine after a terminal load failure.- * Clears the attempt latch so [refreshTranslatorState] gets a fresh answer.- */- fun retryTranslator() {- viewModelScope.launch {- (translator as? NllbTranslator)?.reset()- _translationLoadFailed.value = false- refreshTranslatorState()+ _translationAvailable.value = translator.isAvailable() } }
translate/src/main/java/com/vayunmathur/translate/ui/CameraOverlay.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/ui/CameraOverlay.kt b/translate/src/main/java/com/vayunmathur/translate/ui/CameraOverlay.ktindex 20d6a1322b..ad5d67f52f 100644--- a/translate/src/main/java/com/vayunmathur/translate/ui/CameraOverlay.kt+++ b/translate/src/main/java/com/vayunmathur/translate/ui/CameraOverlay.kt@@ -52,8 +52,6 @@ internal fun CameraOverlay( overlays: List<OverlayBox>, translations: Map<String, String>, translationAvailable: Boolean,- translationLoadFailed: Boolean = false,- onRetryTranslator: () -> Unit = {}, frameW: Int, frameH: Int, viewW: Int,@@ -83,31 +81,15 @@ internal fun CameraOverlay( } if (!translationAvailable) {- // A terminal engine failure says so (rather than blaming the install- // the download screen just finished); tap retries the load.- if (translationLoadFailed) {- TextButton(onClick = onRetryTranslator) {- Text(- text = stringResource(R.string.translation_failed_to_load),- color = Color.White,- modifier = Modifier- .statusBarsPadding()- .padding(top = 12.dp)- .background(Color(0xB3000000), RoundedCornerShape(12.dp))- .padding(horizontal = 12.dp, vertical = 6.dp),- )- }- } else {- Text(- text = stringResource(R.string.translation_model_not_installed_showing),- color = Color.White,- modifier = Modifier- .statusBarsPadding()- .padding(top = 12.dp)- .background(Color(0xB3000000), RoundedCornerShape(12.dp))- .padding(horizontal = 12.dp, vertical = 6.dp),- )- }+ Text(+ text = stringResource(R.string.translation_model_not_installed_showing),+ color = Color.White,+ modifier = Modifier+ .statusBarsPadding()+ .padding(top = 12.dp)+ .background(Color(0xB3000000), RoundedCornerShape(12.dp))+ .padding(horizontal = 12.dp, vertical = 6.dp),+ ) } // The analysed frame *is* the visible region now, so placing a box is a
translate/src/main/java/com/vayunmathur/translate/ui/CameraPreviewLayer.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/ui/CameraPreviewLayer.kt b/translate/src/main/java/com/vayunmathur/translate/ui/CameraPreviewLayer.ktindex 7005d1a13b..811db21f2e 100644--- a/translate/src/main/java/com/vayunmathur/translate/ui/CameraPreviewLayer.kt+++ b/translate/src/main/java/com/vayunmathur/translate/ui/CameraPreviewLayer.kt@@ -45,7 +45,6 @@ internal fun CameraPreviewLayer( val sourceLang by viewModel.sourceLang.collectAsState() val targetLang by viewModel.targetLang.collectAsState() val translationAvailable by viewModel.translationAvailable.collectAsState()- val translationLoadFailed by viewModel.translationLoadFailed.collectAsState() var camera by remember { mutableStateOf<androidx.camera.core.Camera?>(null) } var provider by remember { mutableStateOf<androidx.camera.lifecycle.ProcessCameraProvider?>(null) }@@ -147,8 +146,6 @@ internal fun CameraPreviewLayer( overlays = overlays.value, translations = translations.value, translationAvailable = translationAvailable,- translationLoadFailed = translationLoadFailed,- onRetryTranslator = viewModel::retryTranslator, frameW = frameW.value, frameH = frameH.value, viewW = viewSize.width,
translate/src/main/java/com/vayunmathur/translate/ui/ImageTranslateScreen.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/ui/ImageTranslateScreen.kt b/translate/src/main/java/com/vayunmathur/translate/ui/ImageTranslateScreen.ktindex e8975619c4..3abdad2982 100644--- a/translate/src/main/java/com/vayunmathur/translate/ui/ImageTranslateScreen.kt+++ b/translate/src/main/java/com/vayunmathur/translate/ui/ImageTranslateScreen.kt@@ -80,7 +80,6 @@ fun ImageTranslateScreen( val sourceLang by viewModel.sourceLang.collectAsState() val targetLang by viewModel.targetLang.collectAsState() val translationAvailable by viewModel.translationAvailable.collectAsState()- val translationLoadFailed by viewModel.translationLoadFailed.collectAsState() DisposableEffect(imageUri) { onDispose {@@ -171,8 +170,6 @@ fun ImageTranslateScreen( overlays = overlays.value, translations = translations.value, translationAvailable = translationAvailable,- translationLoadFailed = translationLoadFailed,- onRetryTranslator = viewModel::retryTranslator, frameW = bmp.width, frameH = bmp.height, viewW = dispWpx,
translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.ktindex 6d06db0747..c747f4537f 100644--- a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt+++ b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt@@ -62,7 +62,6 @@ fun TextTranslatePage( val sourceLang by viewModel.sourceLang.collectAsState() val targetLang by viewModel.targetLang.collectAsState() val translationAvailable by viewModel.translationAvailable.collectAsState()- val translationLoadFailed by viewModel.translationLoadFailed.collectAsState() val history by viewModel.history.collectAsState() var inputText by remember { mutableStateOf(initialText) }@@ -155,7 +154,6 @@ fun TextTranslatePage( sourceLang = sourceLang, targetLang = targetLang, translationAvailable = translationAvailable,- translationLoadFailed = translationLoadFailed, inputText = inputText, outputText = outputText, isTranslating = isTranslating,@@ -190,8 +188,6 @@ fun TextTranslatePage( } } - override fun retryTranslator() = viewModel.retryTranslator()- override fun copyOutput() = copyToClipboard(context, outputText) // Star the current translation: if it is already saved, flip its flag;
translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.ktindex 07fc71c1ce..b694728891 100644--- a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt+++ b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt@@ -40,7 +40,6 @@ import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.ui.isExpandedWidth-import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.translate.domain.Languages import com.vayunmathur.translate.platform.MicState import com.vayunmathur.translate.platform.TextTranslateActions@@ -131,7 +130,6 @@ fun TextTranslateScreen(state: TextTranslateUiState, actions: TextTranslateActio ) { OutputCard( translationAvailable = state.translationAvailable,- translationLoadFailed = state.translationLoadFailed, isTranslating = state.isTranslating, outputText = state.outputText, isFavorite = state.isFavorite,@@ -139,7 +137,6 @@ fun TextTranslateScreen(state: TextTranslateUiState, actions: TextTranslateActio onCopy = actions::copyOutput, onSpeak = actions::speakOutput, onToggleFavorite = actions::toggleFavorite,- onRetryTranslator = actions::retryTranslator, ) } }@@ -153,7 +150,6 @@ fun TextTranslateScreen(state: TextTranslateUiState, actions: TextTranslateActio OutputCard( translationAvailable = state.translationAvailable,- translationLoadFailed = state.translationLoadFailed, isTranslating = state.isTranslating, outputText = state.outputText, isFavorite = state.isFavorite,@@ -161,7 +157,6 @@ fun TextTranslateScreen(state: TextTranslateUiState, actions: TextTranslateActio onCopy = actions::copyOutput, onSpeak = actions::speakOutput, onToggleFavorite = actions::toggleFavorite,- onRetryTranslator = actions::retryTranslator, ) } }@@ -242,7 +237,6 @@ private fun LanguageBar( @Composable private fun OutputCard( translationAvailable: Boolean,- translationLoadFailed: Boolean, isTranslating: Boolean, outputText: String, isFavorite: Boolean,@@ -250,7 +244,6 @@ private fun OutputCard( onCopy: () -> Unit, onSpeak: () -> Unit, onToggleFavorite: () -> Unit,- onRetryTranslator: () -> Unit, ) { Card(modifier = Modifier.fillMaxWidth()) { Column(@@ -260,33 +253,14 @@ private fun OutputCard( verticalArrangement = Arrangement.spacedBy(12.dp), ) { if (!translationAvailable) {- if (translationLoadFailed) {- // The engine failed to load (missing native library, no fp16- // Vulkan device, corrupt weights) even though the download- // screen finished. Say so with a retry instead of spinning- // forever — the old failure mode of issue #842.- Text(- stringResource(R.string.translation_failed_to_load),- fontWeight = FontWeight.Medium,- color = MaterialTheme.colorScheme.error,- )- Text(- stringResource(R.string.translation_failed_to_load_hint),- color = MaterialTheme.colorScheme.onSurfaceVariant,- )- TextButton(onClick = onRetryTranslator) {- Text(stringResource(UiR.string.retry))- }- } else {- // The outer InitialModelDownloadChecker downloads the model- // before any Navigation is composed, and TranslateViewModel- // loads the engine on init. Show a spinner while the engine- // is still initializing.- Row(verticalAlignment = Alignment.CenterVertically) {- CircularProgressIndicator(modifier = Modifier.size(16.dp), strokeWidth = 2.dp)- Spacer(Modifier.width(8.dp))- Text(stringResource(R.string.loading_translator), color = MaterialTheme.colorScheme.onSurfaceVariant)- }+ // Should never happen — the outer InitialModelDownloadChecker+ // downloads the model before any Navigation is composed, and+ // TranslateViewModel loads the engine on init. Show a loading+ // spinner if the engine is still initializing.+ Row(verticalAlignment = Alignment.CenterVertically) {+ CircularProgressIndicator(modifier = Modifier.size(16.dp), strokeWidth = 2.dp)+ Spacer(Modifier.width(8.dp))+ Text(stringResource(R.string.loading_translator), color = MaterialTheme.colorScheme.onSurfaceVariant) } return@Column }
translate/src/main/res/values/strings.xml
diff --git a/translate/src/main/res/values/strings.xml b/translate/src/main/res/values/strings.xmlindex cc81a50749..0e030b5448 100644--- a/translate/src/main/res/values/strings.xml+++ b/translate/src/main/res/values/strings.xml@@ -3,8 +3,6 @@ <string name="app_name">Translate</string> <string name="enter_text">Enter text</string> <string name="loading_translator">Loading translator…</string>- <string name="translation_failed_to_load">Couldn’t load the translator</string>- <string name="translation_failed_to_load_hint">The model downloaded, but this device couldn’t start it. Try again, or reinstall the model from storage settings.</string> <string name="copy">Copy</string> <string name="speak">Speak</string> <string name="translation">Translation</string>