Use one model row for image and translation downloads
Image settings, translation settings, and the restore prompt each listed models differently. Share ModelDownloadList so every model shows the same name, size, status, selection, and download, cancel, or remove action. Co-authored-by: zjs81 <zjs81@users.noreply.github.com>
This commit is contained in:
50 files changed
+2524
-833
No files matched your search
@@ -22,6 +22,7 @@ import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/model_download_list.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
|
||||
class BackupRestoreScreen extends StatefulWidget {
|
||||
@@ -630,12 +631,6 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
required ImageCodecService imageCodecService,
|
||||
}) async {
|
||||
final l10n = context.l10n;
|
||||
final modelNames = [
|
||||
if (translationModel != null)
|
||||
translationModelFriendlyName(translationModel),
|
||||
if (imageCodecModel != null)
|
||||
imageCodecSpec?.label ?? imageCodecModel.name,
|
||||
];
|
||||
var starting = false;
|
||||
var cancelRequested = false;
|
||||
var translationDone = translationModel == null;
|
||||
@@ -658,16 +653,9 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
starting ||
|
||||
translationService.isDownloading ||
|
||||
imageCodecService.isDownloading;
|
||||
final currentProgress = currentModel == translationModel?.name
|
||||
? translationService.downloadProgress
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadProgress
|
||||
: null;
|
||||
final currentFile = currentModel == translationModel?.name
|
||||
? translationService.downloadFileName
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadFileName
|
||||
: null;
|
||||
final translationCurrent = currentModel == translationModel?.name;
|
||||
final imageCurrent = currentModel == imageCodecModel?.name;
|
||||
final failure = downloadError;
|
||||
|
||||
void requestDownloadCancel() {
|
||||
cancelRequested = true;
|
||||
@@ -682,31 +670,73 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
},
|
||||
child: AlertDialog(
|
||||
title: Text(l10n.backupRestore_missingModelsTitle),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.backupRestore_missingModelsMessage(
|
||||
modelNames.join('\n'),
|
||||
),
|
||||
),
|
||||
if (isDownloading) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(currentFile ?? currentModel ?? ''),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(value: currentProgress),
|
||||
],
|
||||
if (downloadError != null) ...[
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.backupRestore_missingModelsMessage),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.backupRestore_failed(downloadError!),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
ModelDownloadList(
|
||||
rowPadding: const EdgeInsets.symmetric(vertical: 4),
|
||||
items: [
|
||||
if (translationModel != null)
|
||||
_missingModelItem(
|
||||
id: 'translation-${translationModel.id}',
|
||||
name: translationModelFriendlyName(
|
||||
translationModel,
|
||||
),
|
||||
sizeBytes: translationModel.fileSizeBytes,
|
||||
done: translationDone,
|
||||
current: translationCurrent,
|
||||
downloading:
|
||||
translationService.isDownloading ||
|
||||
(starting && translationCurrent),
|
||||
progress: translationService.downloadProgress,
|
||||
downloadedBytes:
|
||||
translationService.downloadedBytes,
|
||||
totalBytes: translationService.downloadTotalBytes,
|
||||
detail:
|
||||
translationService.downloadFileName ==
|
||||
'Merging chunks...'
|
||||
? l10n.translation_mergingChunks
|
||||
: null,
|
||||
error: failure == null
|
||||
? null
|
||||
: l10n.backupRestore_failed(failure),
|
||||
),
|
||||
if (imageCodecModel != null)
|
||||
_missingModelItem(
|
||||
id: 'image-${imageCodecModel.id}',
|
||||
name:
|
||||
imageCodecSpec?.label ??
|
||||
imageCodecModelFriendlyName(imageCodecModel),
|
||||
sizeBytes:
|
||||
imageCodecSpec?.totalSizeBytes ??
|
||||
imageCodecModel.fileSizeBytes,
|
||||
done: imageCodecDone,
|
||||
current: imageCurrent,
|
||||
downloading:
|
||||
imageCodecService.isDownloading ||
|
||||
(starting && imageCurrent),
|
||||
progress: imageCodecService.downloadProgress,
|
||||
downloadedBytes:
|
||||
imageCodecService.downloadedBytes,
|
||||
totalBytes: imageCodecService.downloadTotalBytes,
|
||||
detail:
|
||||
imageCodecService.downloadFileName
|
||||
?.startsWith('Verifying ') ==
|
||||
true
|
||||
? l10n.modelDownload_verifying
|
||||
: null,
|
||||
error: failure == null
|
||||
? null
|
||||
: l10n.backupRestore_failed(failure),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -830,3 +860,40 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
showDismissibleSnackBar(context, content: Text(message));
|
||||
}
|
||||
}
|
||||
|
||||
ModelDownloadItem _missingModelItem({
|
||||
required String id,
|
||||
required String name,
|
||||
required int sizeBytes,
|
||||
required bool done,
|
||||
required bool current,
|
||||
required bool downloading,
|
||||
required double? progress,
|
||||
required int downloadedBytes,
|
||||
required int? totalBytes,
|
||||
required String? detail,
|
||||
required String? error,
|
||||
}) {
|
||||
final inProgress = downloading && current && !done;
|
||||
final failed = error != null && current && !inProgress && !done;
|
||||
return ModelDownloadItem(
|
||||
id: id,
|
||||
name: name,
|
||||
sizeBytes: sizeBytes > 0 ? sizeBytes : null,
|
||||
status: done
|
||||
? ModelDownloadStatus.ready
|
||||
: failed
|
||||
? ModelDownloadStatus.error
|
||||
: inProgress
|
||||
? ModelDownloadStatus.downloading
|
||||
: ModelDownloadStatus.notDownloaded,
|
||||
progress: inProgress ? progress : null,
|
||||
downloadedBytes: inProgress ? downloadedBytes : 0,
|
||||
totalBytes: inProgress ? totalBytes : null,
|
||||
detail: failed
|
||||
? error
|
||||
: inProgress
|
||||
? detail
|
||||
: null,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user