基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat(collect): redesign manual sync
Predidite140ecd8a5c7
diff --git a/lib/pages/collect/collect_controller.dart b/lib/pages/collect/collect_controller.dartindex 9532e1a1..e47e2517 100644--- a/lib/pages/collect/collect_controller.dart+++ b/lib/pages/collect/collect_controller.dart@@ -8,13 +8,11 @@ import 'package:kazumi/services/sync/bangumi_sync_service.dart';import 'package:kazumi/services/storage/storage.dart';import 'package:kazumi/services/sync/webdav.dart';import 'package:kazumi/repositories/collect_crud_repository.dart';-import 'package:kazumi/repositories/collect_repository.dart';import 'package:mobx/mobx.dart';import 'package:kazumi/services/logging/logger.dart';part 'collect_controller.g.dart';-// Define actions for handling Bangumi collect deletion.enum _BangumiDeleteSyncAction {deleteLocalOnly,markAbandoned,@@ -25,15 +23,9 @@ enum _BangumiDeleteSyncAction {class CollectController = _CollectController with _$CollectController;abstract class _CollectController with Store {- _CollectController(- this._collectCrudRepository,- this._collectRepository,- );+ _CollectController(this._collectCrudRepository);final ICollectCrudRepository _collectCrudRepository;- final ICollectRepository _collectRepository;-- List<BangumiItem> get favorites => _collectCrudRepository.getFavorites();@observableObservableList<CollectedBangumi> collectibles =@@ -48,10 +40,6 @@ abstract class _CollectController with Store {return _collectCrudRepository.getCollectType(bangumiItem.id);}- BangumiItem? getCollectibleBangumiItem(int id) {- return _collectCrudRepository.getCollectible(id)?.bangumiItem;- }-@actionFuture<void> addCollect(BangumiItem bangumiItem, {type = 1}) async {if (type == 0) {@@ -59,7 +47,6 @@ abstract class _CollectController with Store {return;}- // 1. Sync with Bangumi if enabledfinal bool syncSucceeded = await _syncBangumiCollectIfEnabled(bangumiItem.id,type,@@ -71,7 +58,6 @@ abstract class _CollectController with Store {final int currentCollectType = getCollectType(bangumiItem);final int collectChangeAction = currentCollectType == 0 ? 1 : 2;- // 2. Update local database and change logsawait _collectCrudRepository.addCollectible(bangumiItem, type);await GStorage.appendCollectChange(bangumiId: bangumiItem.id,@@ -83,7 +69,6 @@ abstract class _CollectController with Store {@actionFuture<void> deleteCollect(BangumiItem bangumiItem) async {- // Resolve how to handle deletion with userfinal action = await _resolveBangumiDeleteSyncAction(bangumiItem);switch (action) {case _BangumiDeleteSyncAction.markAbandoned:@@ -222,85 +207,68 @@ abstract class _CollectController with Store {loadCollectibles();}- Future<bool> syncCollectibles({bool showSuccessToast = true}) async {+ void _reportSyncError(String message, ValueChanged<String> onError,+ {Object? error}) {+ if (error != null) {+ KazumiLogger().e(message, error: error);+ }+ onError(message);+ }++ Future<bool> _connectWebDav(ValueChanged<String> onError) async {final bool webDavCollectEnable =GStorage.getSetting(SettingsKeys.webDavEnableCollect);if (!webDavCollectEnable) {- KazumiDialog.showToast(message: '未开启WebDav收藏同步');+ _reportSyncError('请开启 WebDAV 收藏同步', onError);return false;}if (!WebDav().initialized) {- KazumiDialog.showToast(message: '未开启WebDav同步或配置无效');+ _reportSyncError('WebDAV 未连接,请检查配置', onError);return false;}- bool flag = true;try {await WebDav().ping();} catch (e) {- KazumiLogger().e('WebDav: WebDav connection failed', error: e);- KazumiDialog.showToast(message: 'WebDav连接失败: $e');- flag = false;- }- if (!flag) {+ _reportSyncError('WebDAV 连接失败,请检查网络或配置', onError, error: e);return false;}+ return true;+ }++ Future<bool> syncCollectibles({+ required ValueChanged<String> onError,+ }) async {+ if (!await _connectWebDav(onError)) return false;try {await WebDav().syncCollectibles();- if (showSuccessToast) {- KazumiDialog.showToast(message: 'WebDav同步完成');- }} catch (e) {- KazumiDialog.showToast(message: 'WebDav同步失败 $e');+ _reportSyncError('WebDAV 同步失败,请检查连接', onError, error: e);return false;}loadCollectibles();return true;}- /// Only upload local collectibles and change logs to WebDAV, without downloading and merging.- /// Used by full sync to push Bangumi-updated local changes back to WebDAV.- Future<bool> uploadCollectiblesToWebDav(- {bool showSuccessToast = true}) async {- final bool webDavCollectEnable =- GStorage.getSetting(SettingsKeys.webDavEnableCollect);- if (!webDavCollectEnable) {- KazumiDialog.showToast(message: '未开启WebDav收藏同步');- return false;- }- if (!WebDav().initialized) {- KazumiDialog.showToast(message: '未开启WebDav同步或配置无效');- return false;- }- bool flag = true;- try {- await WebDav().ping();- } catch (e) {- KazumiLogger().e('WebDav: WebDav connection failed', error: e);- KazumiDialog.showToast(message: 'WebDav连接失败: $e');- flag = false;- }- if (!flag) {- return false;- }+ // Upload without merging again after Bangumi updates the local collection.+ Future<bool> uploadCollectiblesToWebDav({+ required ValueChanged<String> onError,+ }) async {+ if (!await _connectWebDav(onError)) return false;try {await WebDav().updateCollectibles();- if (showSuccessToast) {- KazumiDialog.showToast(message: 'WebDav上传完成');- }} catch (e) {- KazumiDialog.showToast(message: 'WebDav上传失败 $e');+ _reportSyncError('WebDAV 回传失败,请检查连接', onError, error: e);return false;}return true;}- // migrate collect from old version (favorites)Future<void> migrateCollect() async {+ final favorites = _collectCrudRepository.getFavorites();if (favorites.isNotEmpty) {int count = 0;for (BangumiItem bangumiItem in favorites) {- // Migration should never depend on runtime Bangumi initialization.- // Persist locally and append change logs, then let later sync handle remote updates.+ // Migration must work before Bangumi is initialized.final int currentCollectType = getCollectType(bangumiItem);final int collectChangeAction = currentCollectType == 0 ? 1 : 2;await _collectCrudRepository.addCollectible(bangumiItem, 1);@@ -318,56 +286,30 @@ abstract class _CollectController with Store {}}- /// 根据收藏类型获取番剧ID集合- ///- /// [type] 收藏类型- /// 返回番剧ID集合- Set<int> getBangumiIdsByType(CollectType type) {- return _collectRepository.getBangumiIdsByType(type);- }-- /// 过滤掉指定收藏类型的番剧- ///- /// [bangumiList] 原始番剧列表- /// [excludeType] 要排除的收藏类型- /// 返回过滤后的番剧列表- List<BangumiItem> filterBangumiByType(- List<BangumiItem> bangumiList, CollectType excludeType) {- final excludeIds = getBangumiIdsByType(excludeType);- return bangumiList.where((item) => !excludeIds.contains(item.id)).toList();- }-- /// Sync Bangumi collectibles.- Future<bool> syncCollectiblesBangumi(- {void Function(String message, int current, int total)? onProgress,- bool showSuccessToast = true}) async {+ Future<bool> syncCollectiblesBangumi({+ required void Function(String message, int current, int total) onProgress,+ required ValueChanged<String> onError,+ }) async {final bool syncEnable = GStorage.getSetting(SettingsKeys.bangumiSyncEnable);if (!syncEnable) {- KazumiDialog.showToast(message: '未开启Bangumi同步,请先在设置中启用');+ _reportSyncError('请开启 Bangumi 同步', onError);return false;}if (!BangumiSyncService().initialized) {- KazumiDialog.showToast(message: 'Bangumi同步已开启但未初始化,请检查Token后重试');+ _reportSyncError('Bangumi 未连接,请检查令牌', onError);return false;}try {await BangumiSyncService().ping();- try {- final hasChanges =- await BangumiSyncService().syncCollectibles(onProgress: onProgress);- if (showSuccessToast) {- KazumiDialog.showToast(- message: hasChanges ? 'Bangumi同步完成' : '未发现状态差异,无需同步',- );- }- } catch (e) {- KazumiDialog.showToast(message: 'Bangumi同步失败 $e');- return false;- }} catch (e) {- KazumiLogger().e('Bangumi: Bangumi connection failed', error: e);- KazumiDialog.showToast(message: 'Bangumi访问失败: $e');+ _reportSyncError('Bangumi 连接失败,请检查网络或令牌', onError, error: e);+ return false;+ }+ try {+ await BangumiSyncService().syncCollectibles(onProgress: onProgress);+ } catch (e) {+ _reportSyncError('Bangumi 同步失败,请检查连接或令牌', onError, error: e);return false;}loadCollectibles();diff --git a/lib/pages/collect/collect_page.dart b/lib/pages/collect/collect_page.dartindex b136c14d..8451df2a 100644--- a/lib/pages/collect/collect_page.dart+++ b/lib/pages/collect/collect_page.dart@@ -6,12 +6,14 @@ import 'package:flutter_modular/flutter_modular.dart';import 'package:kazumi/bean/appbar/sys_app_bar.dart';import 'package:kazumi/bean/dialog/dialog_helper.dart';-import 'package:kazumi/bean/widget/loading_indicator.dart';+import 'package:kazumi/bean/widget/state_presentation.dart';import 'package:kazumi/modules/bangumi/bangumi_item.dart';+import 'package:kazumi/modules/bangumi/sync_priority.dart';import 'package:kazumi/modules/collect/collect_sync_plan.dart';import 'package:kazumi/modules/collect/collect_type.dart';import 'package:kazumi/pages/collect/collect_controller.dart';import 'package:kazumi/pages/collect/collect_library_view.dart';+import 'package:kazumi/pages/collect/collect_sync_dialog.dart';import 'package:kazumi/services/storage/storage.dart';class CollectPage extends StatefulWidget {@@ -28,71 +30,26 @@ class CollectPage extends StatefulWidget {class _CollectPageState extends State<CollectPage> with KazumiDialogOwner {CollectController get collectController => widget.controller;- bool get _syncing => dialogs.isRunning;+ bool get _syncDialogOpen => dialogs.isRunning;final Set<int> _pendingIds = {};- Future<void> _runFullSync({- required CollectSyncPlan plan,+ Future<bool> _syncStep(+ CollectSyncStep step, {+ required ValueChanged<String> onError,+ required void Function(String message, int current, int total) onProgress,}) =>- dialogs.run((task) async {- final progressDialogKey = GlobalKey<_FullSyncProgressDialogState>();- bool webDavSynced = false;- bool bangumiSynced = false;- bool webDavUploaded = false;-- await task.loading(- builder: (context) => _FullSyncProgressDialog(key: progressDialogKey),- action: () async {- await WidgetsBinding.instance.endOfFrame;- if (plan.shouldSyncWebDavCollectibles) {- progressDialogKey.currentState?.update('正在同步 WebDav 收藏...', null);- webDavSynced = await collectController.syncCollectibles(- showSuccessToast: false);- }-- if (plan.shouldSyncBangumi) {- progressDialogKey.currentState- ?.update('准备同步 Bangumi 收藏...', null);- bangumiSynced = await collectController.syncCollectiblesBangumi(- showSuccessToast: false,- onProgress: (message, current, total) {- progressDialogKey.currentState?.update(- total > 0 ? '$message ($current/$total)' : message,- total > 0- ? (current / total).clamp(0.0, 1.0).toDouble()- : null,- );- },- );- }-- if (plan.shouldUploadWebDavAfterBangumi(- webDavSynced: webDavSynced,- bangumiSynced: bangumiSynced,- )) {- progressDialogKey.currentState- ?.update('正在回传最新收藏到 WebDav...', null);- webDavUploaded =- await collectController.uploadCollectiblesToWebDav(- showSuccessToast: false,- );- }- },- );-- final states = [- if (plan.shouldSyncWebDavCollectibles)- webDavSynced ? 'WebDav 已同步' : 'WebDav 未完成',- if (plan.shouldSyncBangumi)- bangumiSynced ? 'Bangumi 已同步' : 'Bangumi 未完成',- if (plan.shouldUploadWebDavAfterBangumi(- webDavSynced: webDavSynced,- bangumiSynced: bangumiSynced,- ))- webDavUploaded ? 'WebDav 已回传最新数据' : 'WebDav 未回传最新数据',- ];- KazumiDialog.showToast(message: states.join(','));- }, errorMessage: '同步未完成,请稍后重试');+ switch (step) {+ CollectSyncStep.webDav => collectController.syncCollectibles(+ onError: onError,+ ),+ CollectSyncStep.bangumi => collectController.syncCollectiblesBangumi(+ onError: onError,+ onProgress: onProgress,+ ),+ CollectSyncStep.upload => collectController.uploadCollectiblesToWebDav(+ onError: onError,+ ),+ };@overridevoid initState() {@@ -101,7 +58,7 @@ class _CollectPageState extends State<CollectPage> with KazumiDialogOwner {}Future<void> _changeType(BangumiItem item, CollectType type) async {- if (_syncing || _pendingIds.contains(item.id)) return;+ if (_syncDialogOpen || _pendingIds.contains(item.id)) return;setState(() => _pendingIds.add(item.id));try {await collectController.addCollect(item, type: type.value);@@ -113,23 +70,32 @@ class _CollectPageState extends State<CollectPage> with KazumiDialogOwner {}Future<void> _sync() async {- if (_syncing || _pendingIds.isNotEmpty) return;+ if (_syncDialogOpen || _pendingIds.isNotEmpty) return;final plan = CollectSyncPlan(webDavEnabled: GStorage.getSetting(SettingsKeys.webDavEnable),webDavCollectiblesEnabled:GStorage.getSetting(SettingsKeys.webDavEnableCollect),bangumiEnabled: GStorage.getSetting(SettingsKeys.bangumiSyncEnable),);- if (!plan.canSync) {- KazumiDialog.showToast(message: '同步功能不可用,请至少开启一个同步功能');- return;- }- await _runFullSync(plan: plan);+ await dialogs.run((task) async {+ final destination = await task.show<CollectSyncDestination>(+ builder: (_) => CollectSyncDialog(+ plan: plan,+ priority: BangumiSyncPriority.fromValue(+ GStorage.getSetting(SettingsKeys.bangumiSyncPriority),+ ),+ onSync: _syncStep,+ ),+ );+ task.withContext((context) => context.pushNamed(switch (destination) {+ CollectSyncDestination.webDavSettings => '/settings/webdav/',+ CollectSyncDestination.bangumiSettings => '/settings/bangumi/',+ }));+ }, errorMessage: '同步未完成,请稍后重试');}@overrideWidget build(BuildContext context) {- final colors = Theme.of(context).colorScheme;return Scaffold(appBar: SysAppBar(needTopOffset: false,@@ -144,16 +110,14 @@ class _CollectPageState extends State<CollectPage> with KazumiDialogOwner {actions: [Padding(padding: const EdgeInsets.only(right: 8),- child: IconButton.filledTonal(- tooltip: _syncing ? '正在同步收藏' : '同步收藏',- onPressed: _syncing || _pendingIds.isNotEmpty ? null : _sync,- icon: _syncing- ? LoadingIndicator(- size: 24,- color: colors.onSecondaryContainer,- semanticsLabel: '正在同步收藏',- )- : const Icon(Icons.sync_rounded),+ child: Tooltip(+ message: '同步收藏',+ child: StateActionButton.tonal(+ text: '同步',+ onPressed:+ _syncDialogOpen || _pendingIds.isNotEmpty ? null : _sync,+ icon: Icons.sync_rounded,+ ),),),],@@ -164,7 +128,8 @@ class _CollectPageState extends State<CollectPage> with KazumiDialogOwner {child: Observer(builder: (context) => CollectLibraryView(entries: collectController.collectibles.toList(),- canEdit: (item) => !_syncing && !_pendingIds.contains(item.id),+ canEdit: (item) =>+ !_syncDialogOpen && !_pendingIds.contains(item.id),onOpen: (item) => context.pushNamed('/info/', arguments: item),onChangeType: (item, type) => unawaited(_changeType(item, type)),),@@ -173,56 +138,3 @@ class _CollectPageState extends State<CollectPage> with KazumiDialogOwner {);}}--class _FullSyncProgressDialog extends StatefulWidget {- const _FullSyncProgressDialog({super.key});-- @override- State<_FullSyncProgressDialog> createState() =>- _FullSyncProgressDialogState();-}--class _FullSyncProgressDialogState extends State<_FullSyncProgressDialog> {- String _progressText = '准备开始同步收藏...';- double? _progressValue;-- void update(String text, double? value) {- if (!mounted) return;- setState(() {- _progressText = text;- _progressValue = value;- });- }-- @override- Widget build(BuildContext context) {- return PopScope(- canPop: false,- child: Dialog(- child: Padding(- padding: const EdgeInsets.all(20.0),- child: SizedBox(- width: 340,- child: Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.start,- children: [- const Text(- '收藏全量同步中',- style: TextStyle(- fontSize: 16,- fontWeight: FontWeight.w600,- ),- ),- const SizedBox(height: 12),- Text(_progressText),- const SizedBox(height: 12),- LinearProgressIndicator(value: _progressValue),- ],- ),- ),- ),- ),- );- }-}diff --git a/lib/pages/collect/collect_sync_dialog.dart b/lib/pages/collect/collect_sync_dialog.dartnew file mode 100644index 00000000..583dc45c--- /dev/null+++ b/lib/pages/collect/collect_sync_dialog.dart@@ -0,0 +1,430 @@+import 'package:flutter/material.dart';++import 'package:kazumi/bean/widget/loading_indicator.dart';+import 'package:kazumi/bean/widget/state_presentation.dart';+import 'package:kazumi/modules/bangumi/sync_priority.dart';+import 'package:kazumi/modules/collect/collect_sync_plan.dart';++enum CollectSyncDestination { webDavSettings, bangumiSettings }++enum CollectSyncStep {+ webDav('WebDAV 收藏', '合并本地与云端收藏', Icons.cloud_sync_rounded),+ bangumi('Bangumi 状态', '同步追番状态', Icons.bookmarks_rounded),+ upload('回传 WebDAV', '上传合并后的收藏', Icons.cloud_upload_rounded);++ const CollectSyncStep(this._title, this._description, this._icon);++ final String _title;+ final String _description;+ final IconData _icon;++ CollectSyncDestination get _settings => switch (this) {+ bangumi => CollectSyncDestination.bangumiSettings,+ webDav || upload => CollectSyncDestination.webDavSettings,+ };+}++typedef CollectSyncOperation = Future<bool> Function(+ CollectSyncStep step, {+ required ValueChanged<String> onError,+ required void Function(String message, int current, int total) onProgress,+});++enum _StepStatus { waiting, running, succeeded, failed, skipped }++enum _SyncPhase { ready, running, finished }++class _StepState {+ _StepState(this.step);++ final CollectSyncStep step;+ _StepStatus status = _StepStatus.waiting;+ String? message;+ double? progress;+}++class CollectSyncDialog extends StatefulWidget {+ const CollectSyncDialog({+ super.key,+ required this.plan,+ required this.priority,+ required this.onSync,+ });++ final CollectSyncPlan plan;+ final BangumiSyncPriority priority;+ final CollectSyncOperation onSync;++ @override+ State<CollectSyncDialog> createState() => _CollectSyncDialogState();+}++class _CollectSyncDialogState extends State<CollectSyncDialog> {+ late List<_StepState> _steps = _createSteps();+ _SyncPhase _phase = _SyncPhase.ready;++ bool get _running => _phase == _SyncPhase.running;+ bool get _finished => _phase == _SyncPhase.finished;++ List<_StepState> _createSteps() => [+ if (widget.plan.shouldSyncWebDavCollectibles)+ _StepState(CollectSyncStep.webDav),+ if (widget.plan.shouldSyncBangumi) _StepState(CollectSyncStep.bangumi),+ if (widget.plan.shouldSyncWebDavCollectibles &&+ widget.plan.shouldSyncBangumi)+ _StepState(CollectSyncStep.upload),+ ];++ // Removed routes can stay mounted until their exit animation ends.+ bool get _active => mounted && (ModalRoute.of(context)?.isActive ?? false);+ bool get _hasFailure =>+ _steps.any((step) => step.status == _StepStatus.failed);+ bool get _hasSuccess =>+ _steps.any((step) => step.status == _StepStatus.succeeded);++ Future<void> _start() async {+ if (_running || !widget.plan.canSync) return;+ setState(() {+ _steps = _createSteps();+ _phase = _SyncPhase.running;+ });+ for (final state in _steps) {+ if (!_active) return;+ if (state.step == CollectSyncStep.upload &&+ !widget.plan.shouldUploadWebDavAfterBangumi(+ webDavSynced: _steps.any((s) =>+ s.step == CollectSyncStep.webDav &&+ s.status == _StepStatus.succeeded),+ bangumiSynced: _steps.any((s) =>+ s.step == CollectSyncStep.bangumi &&+ s.status == _StepStatus.succeeded),+ )) {+ setState(() {+ state.status = _StepStatus.skipped;+ state.message = '前两步未全部完成';+ });+ continue;+ }+ setState(() {+ state.status = _StepStatus.running;+ state.message = '正在连接…';+ });+ bool succeeded = false;+ String? failure;+ try {+ succeeded = await widget.onSync(+ state.step,+ onError: (message) => failure = message,+ onProgress: (message, current, total) {+ if (!_active || state.status != _StepStatus.running) return;+ setState(() {+ state.message =+ total > 0 ? '$message · $current / $total' : message;+ state.progress = total > 0+ ? (current / total).clamp(0.0, 1.0).toDouble()+ : null;+ });+ },+ );+ } catch (_) {+ failure ??= '连接中断,请检查网络或设置';+ }+ if (!_active) return;+ setState(() {+ state.status = succeeded ? _StepStatus.succeeded : _StepStatus.failed;+ state.message = succeeded ? null : failure ?? '请检查网络或同步设置';+ state.progress = null;+ });+ }+ if (!_active) return;+ setState(() => _phase = _SyncPhase.finished);+ }++ String get _title {+ if (!widget.plan.canSync) return '开启收藏同步';+ if (_running) return '正在同步收藏';+ if (!_finished) return '同步收藏';+ if (!_hasFailure) return '收藏已同步';+ return _hasSuccess ? '部分同步完成' : '同步未完成';+ }++ String? get _description {+ if (!widget.plan.canSync) return '选择同步服务';+ if (_running) {+ final current = _steps.indexWhere((s) => s.status == _StepStatus.running);+ return '第 ${current + 1} / ${_steps.length} 步 · 请保持应用开启';+ }+ if (!_finished) return '同步全部收藏分类';+ if (_hasFailure && _hasSuccess) return '已完成的更改已保留';+ return null;+ }++ @override+ Widget build(BuildContext context) {+ final theme = Theme.of(context);+ final colors = theme.colorScheme;+ final duration = MediaQuery.disableAnimationsOf(context)+ ? Duration.zero+ : const Duration(milliseconds: 200);+ final failed = _finished && _hasFailure;+ final description = _description;+ return PopScope(+ canPop: !_running,+ child: AlertDialog(+ constraints: const BoxConstraints(minWidth: 280, maxWidth: 440),+ insetPadding: const EdgeInsets.all(24),+ backgroundColor: colors.surfaceContainerHigh,+ surfaceTintColor: Colors.transparent,+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(28)),+ clipBehavior: Clip.antiAlias,+ scrollable: true,+ iconPadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),+ icon: Center(+ child: AnimatedSwitcher(+ duration: duration,+ child: _running+ ? LoadingIndicator(+ key: const ValueKey('syncing'),+ size: 64,+ color: colors.primary,+ semanticsLabel: '正在同步收藏',+ )+ : StateIconBadge(+ key: ValueKey((_finished, failed)),+ icon: failed+ ? Icons.sync_problem_rounded+ : _finished+ ? Icons.done_all_rounded+ : Icons.sync_rounded,+ size: 64,+ iconSize: 32,+ backgroundColor: failed+ ? colors.errorContainer+ : colors.primaryContainer,+ foregroundColor: failed+ ? colors.onErrorContainer+ : colors.onPrimaryContainer,+ ),+ ),+ ),+ titlePadding: const EdgeInsets.fromLTRB(24, 16, 24, 0),+ title: Semantics(+ liveRegion: true,+ child: Text(_title, textAlign: TextAlign.center),+ ),+ titleTextStyle: theme.textTheme.headlineSmall?.copyWith(+ color: colors.onSurface,+ fontWeight: FontWeight.w600,+ ),+ contentPadding: const EdgeInsets.fromLTRB(24, 12, 24, 24),+ content: SizedBox(+ width: 392,+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ if (description != null) ...[+ Text(description,+ textAlign: TextAlign.center,+ style: theme.textTheme.bodyMedium+ ?.copyWith(color: colors.onSurfaceVariant)),+ const SizedBox(height: 24),+ ],+ if (!widget.plan.canSync) ...[+ _setupRow(CollectSyncDestination.webDavSettings),+ const SizedBox(height: 4),+ _setupRow(CollectSyncDestination.bangumiSettings),+ ] else ...[+ for (var i = 0; i < _steps.length; i++) ...[+ if (i > 0) const SizedBox(height: 4),+ _stepRow(_steps[i], i),+ ],+ if (_phase == _SyncPhase.ready &&+ widget.plan.shouldSyncBangumi) ...[+ const SizedBox(height: 16),+ Text(+ '冲突处理:${widget.priority.label}',+ style: theme.textTheme.bodySmall+ ?.copyWith(color: colors.onSurfaceVariant),+ ),+ ],+ ],+ ],+ ),+ ),+ actionsPadding: const EdgeInsets.fromLTRB(24, 0, 24, 24),+ actionsOverflowButtonSpacing: 8,+ actions: _running+ ? null+ : [+ if (!_finished || failed)+ TextButton(+ style: TextButton.styleFrom(+ minimumSize: const Size(64, 48),+ ),+ onPressed: () => Navigator.of(context).pop(),+ child:+ Text(widget.plan.canSync && !_finished ? '取消' : '关闭'),+ ),+ if (widget.plan.canSync)+ StateActionButton(+ onPressed: _finished && !failed+ ? () => Navigator.of(context).pop()+ : _start,+ icon: _finished+ ? (failed ? Icons.refresh_rounded : Icons.check_rounded)+ : Icons.sync_rounded,+ text: _finished ? (failed ? '重新同步' : '完成') : '开始同步',+ ),+ ],+ ),+ );+ }++ BorderRadius _rowRadius(int index, int length) => BorderRadius.vertical(+ top: Radius.circular(index == 0 ? 20 : 4),+ bottom: Radius.circular(index == length - 1 ? 20 : 4),+ );++ Widget _setupRow(CollectSyncDestination destination) {+ final theme = Theme.of(context);+ final colors = theme.colorScheme;+ final (title, description, icon) = switch (destination) {+ CollectSyncDestination.webDavSettings => (+ 'WebDAV',+ '设置服务器,开启收藏同步',+ Icons.cloud_sync_rounded+ ),+ CollectSyncDestination.bangumiSettings => (+ 'Bangumi',+ '连接账号,开启状态同步',+ Icons.bookmarks_rounded+ ),+ };+ return Material(+ color: colors.surfaceContainerLow,+ borderRadius:+ _rowRadius(destination.index, CollectSyncDestination.values.length),+ clipBehavior: Clip.antiAlias,+ child: ListTile(+ contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),+ leading: Icon(icon, color: colors.primary),+ title: Text(title, style: theme.textTheme.titleSmall),+ subtitle: Text(description),+ trailing: const Icon(Icons.chevron_right_rounded),+ onTap: () => Navigator.of(context).pop(destination),+ ),+ );+ }++ Widget _stepRow(_StepState state, int index) {+ final theme = Theme.of(context);+ final colors = theme.colorScheme;+ final active = state.status == _StepStatus.running;+ final failed = state.status == _StepStatus.failed;+ final detail = state.status == _StepStatus.waiting+ ? (_running ? null : state.step._description)+ : state.message;+ final foreground = failed+ ? colors.onErrorContainer+ : active+ ? colors.onSecondaryContainer+ : colors.onSurface;+ final statusLabel = switch (state.status) {+ _StepStatus.waiting => _running ? '等待中' : '第 ${index + 1} 步',+ _StepStatus.running => '同步中',+ _StepStatus.succeeded => '已完成',+ _StepStatus.failed => '未完成',+ _StepStatus.skipped => '已跳过',+ };+ final icon = switch (state.status) {+ _StepStatus.succeeded => Icons.check_circle_rounded,+ _StepStatus.failed => Icons.error_outline_rounded,+ _StepStatus.skipped => Icons.remove_circle_outline_rounded,+ _ => state.step._icon,+ };+ return Semantics(+ container: true,+ child: Material(+ color: failed+ ? colors.errorContainer+ : active+ ? colors.secondaryContainer+ : colors.surfaceContainerLow,+ borderRadius: _rowRadius(index, _steps.length),+ child: Padding(+ padding: const EdgeInsets.all(16),+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Padding(+ padding: const EdgeInsets.only(top: 2),+ child: Icon(icon, size: 24, color: foreground),+ ),+ const SizedBox(width: 12),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Wrap(+ spacing: 12,+ runSpacing: 4,+ crossAxisAlignment: WrapCrossAlignment.center,+ children: [+ Text(state.step._title,+ style: theme.textTheme.titleSmall+ ?.copyWith(color: foreground)),+ Text(statusLabel,+ style: theme.textTheme.labelMedium?.copyWith(+ color: active || failed+ ? foreground+ : colors.onSurfaceVariant)),+ ],+ ),+ if (detail != null) ...[+ const SizedBox(height: 4),+ Text(+ detail,+ style: theme.textTheme.bodySmall?.copyWith(+ color: active || failed+ ? foreground+ : colors.onSurfaceVariant,+ ),+ ),+ ],+ if (failed && _finished) ...[+ const SizedBox(height: 4),+ TextButton.icon(+ style: TextButton.styleFrom(+ foregroundColor: colors.onErrorContainer,+ minimumSize: const Size(48, 48),+ ),+ onPressed: () =>+ Navigator.of(context).pop(state.step._settings),+ icon: const Icon(Icons.settings_rounded, size: 18),+ label: const Text('检查设置'),+ ),+ ],+ if (active && state.progress != null) ...[+ const SizedBox(height: 12),+ LinearProgressIndicator(+ value: state.progress,+ color: colors.primary,+ backgroundColor:+ colors.onSecondaryContainer.withValues(alpha: 0.12),+ minHeight: 4,+ borderRadius: BorderRadius.circular(4),+ trackGap: 4,+ semanticsLabel: state.step._title,+ ),+ ],+ ],+ ),+ ),+ ],+ ),+ ),+ ),+ );+ }+}