基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat(my): redesign the my tab
Predidit1c42520718c7
diff --git a/lib/modules/my/recent_watch_item.dart b/lib/modules/my/recent_watch_item.dartdeleted file mode 100644index 35348f98..00000000--- a/lib/modules/my/recent_watch_item.dart+++ /dev/null@@ -1,70 +0,0 @@-import 'package:kazumi/modules/history/history_module.dart';--/// Display snapshot for a continue-watching card.-///-/// Cards read these fields only, so the sole way the list changes is-/// "history changed -> re-derive".-class RecentWatchItem {- const RecentWatchItem({- required this.id,- required this.title,- required this.coverUrl,- required this.episodeLabel,- required this.sourceLabel,- required this.adapterName,- required this.lastWatchTime,- required this.history,- });-- final String id;- final String title;- final String coverUrl;- final String episodeLabel;- final String sourceLabel;- final String adapterName;- final DateTime lastWatchTime;-- /// Handed back to the playback service; cards never read its fields.- final History history;-- factory RecentWatchItem.from(History history) {- final bangumiItem = history.bangumiItem;- final isOffline = HistoryEntryKind.normalize(history.entryKind) ==- HistoryEntryKind.offline;- return RecentWatchItem(- id: history.key,- title: bangumiItem.nameCn.isEmpty ? bangumiItem.name : bangumiItem.nameCn,- coverUrl: bangumiItem.images['large'] ?? '',- episodeLabel: history.lastWatchEpisodeName.isEmpty- ? '第${history.lastWatchEpisode}话'- : history.lastWatchEpisodeName,- sourceLabel: isOffline ? '缓存' : '在线',- adapterName: history.adapterName,- lastWatchTime: history.lastWatchTime,- history: history,- );- }-- @override- bool operator ==(Object other) {- return other is RecentWatchItem &&- other.id == id &&- other.title == title &&- other.coverUrl == coverUrl &&- other.episodeLabel == episodeLabel &&- other.sourceLabel == sourceLabel &&- other.adapterName == adapterName &&- other.lastWatchTime == lastWatchTime;- }-- @override- int get hashCode => Object.hash(- id,- title,- coverUrl,- episodeLabel,- sourceLabel,- adapterName,- lastWatchTime,- );-}diff --git a/lib/modules/my/watch_stats.dart b/lib/modules/my/watch_stats.dartindex 7b288e96..85af300a 100644--- a/lib/modules/my/watch_stats.dart+++ b/lib/modules/my/watch_stats.dart@@ -1,115 +1,55 @@-import 'package:flutter/foundation.dart' show mapEquals;-import 'package:kazumi/modules/bangumi/bangumi_item.dart';-import 'package:kazumi/modules/collect/collect_module.dart';-import 'package:kazumi/modules/collect/collect_type.dart';import 'package:kazumi/modules/download/download_module.dart';import 'package:kazumi/modules/history/history_module.dart';-/// Device-local viewing stats, derived from history, collect and download data.-class WatchStats {+final class WatchStats {const WatchStats({- this.collectedCount = 0,- this.collectCounts = const {},this.watchedEpisodeCount = 0,this.watchedBangumiCount = 0,this.downloadTaskCount = 0,- this.lastWatchTime,- this.lastWatchName,});- final int collectedCount;- final Map<CollectType, int> collectCounts;final int watchedEpisodeCount;final int watchedBangumiCount;final int downloadTaskCount;- final DateTime? lastWatchTime;- final String? lastWatchName;- /// Playback rewrites history every second, so equality lets the observable- /// stay quiet unless a number actually moved.@override- bool operator ==(Object other) {- return other is WatchStats &&- other.collectedCount == collectedCount &&- mapEquals(other.collectCounts, collectCounts) &&- other.watchedEpisodeCount == watchedEpisodeCount &&- other.watchedBangumiCount == watchedBangumiCount &&- other.downloadTaskCount == downloadTaskCount &&- other.lastWatchTime == lastWatchTime &&- other.lastWatchName == lastWatchName;- }+ bool operator ==(Object other) =>+ other is WatchStats &&+ other.watchedEpisodeCount == watchedEpisodeCount &&+ other.watchedBangumiCount == watchedBangumiCount &&+ other.downloadTaskCount == downloadTaskCount;- // collectCounts is covered by ==; leaving it out only widens buckets.@overrideint get hashCode => Object.hash(- collectedCount,watchedEpisodeCount,watchedBangumiCount,downloadTaskCount,- lastWatchTime,- lastWatchName,);- /// Episodes are keyed by bangumi and number, so watching one through several- /// rules or both online and offline still counts once.factory WatchStats.from({required List<History> histories,- required List<CollectedBangumi> collectibles,required List<DownloadRecord> downloadRecords,}) {- final watchedEpisodeKeys = <String>{};+ // Deduplicate episodes across rules and online/offline histories.+ final watchedEpisodes = <(int, int)>{};final watchedBangumiIds = <int>{};- History? lastWatched;-for (final history in histories) {- if (history.progresses.isEmpty) {- continue;- }+ if (history.progresses.isEmpty) continue;final bangumiId = history.bangumiItem.id;watchedBangumiIds.add(bangumiId);- if (lastWatched == null ||- lastWatched.lastWatchTime.isBefore(history.lastWatchTime)) {- lastWatched = history;- }for (final episode in history.progresses.keys) {- watchedEpisodeKeys.add('$bangumiId::$episode');- }- }-- var collectedCount = 0;- final collectCounts = <CollectType, int>{};- for (final collectible in collectibles) {- final type = CollectType.fromValue(collectible.type);- if (!type.isCollected) {- continue;+ watchedEpisodes.add((bangumiId, episode));}- collectedCount++;- collectCounts[type] = (collectCounts[type] ?? 0) + 1;- }-- // Every task counts, in flight or finished.- var downloadTaskCount = 0;- for (final record in downloadRecords) {- downloadTaskCount += record.episodes.length;}return WatchStats(- collectedCount: collectedCount,- collectCounts: collectCounts,- watchedEpisodeCount: watchedEpisodeKeys.length,+ watchedEpisodeCount: watchedEpisodes.length,watchedBangumiCount: watchedBangumiIds.length,- downloadTaskCount: downloadTaskCount,- lastWatchTime: lastWatched?.lastWatchTime,- lastWatchName: lastWatched == null- ? null- : _displayName(lastWatched.bangumiItem),+ // Count every download task, regardless of status.+ downloadTaskCount: downloadRecords.fold(+ 0,+ (count, record) => count + record.episodes.length,+ ),);}-- static String? _displayName(BangumiItem item) {- if (item.nameCn.isNotEmpty) {- return item.nameCn;- }- return item.name.isEmpty ? null : item.name;- }}diff --git a/lib/pages/my/my_controller.dart b/lib/pages/my/my_controller.dartindex 0e2ce591..9d4cfb13 100644--- a/lib/pages/my/my_controller.dart+++ b/lib/pages/my/my_controller.dart@@ -1,16 +1,13 @@import 'dart:async';-import 'package:flutter/foundation.dart' show listEquals;import 'package:kazumi/bean/dialog/dialog_helper.dart';-import 'package:kazumi/modules/my/recent_watch_item.dart';import 'package:kazumi/modules/my/watch_stats.dart';-import 'package:kazumi/repositories/collect_crud_repository.dart';import 'package:kazumi/repositories/download_repository.dart';import 'package:kazumi/repositories/history_repository.dart';import 'package:kazumi/services/logging/logger.dart';-import 'package:mobx/mobx.dart';import 'package:kazumi/services/storage/storage.dart';import 'package:kazumi/services/update/auto_updater.dart';+import 'package:mobx/mobx.dart';part 'my_controller.g.dart';@@ -19,37 +16,27 @@ class MyController = _MyController with _$MyController;abstract class _MyController with Store {_MyController(this._historyRepository,- this._collectCrudRepository,this._downloadRepository,);final IHistoryRepository _historyRepository;- final ICollectCrudRepository _collectCrudRepository;final IDownloadRepository _downloadRepository;@observableWatchStats watchStats = const WatchStats();- final ObservableList<RecentWatchItem> recentWatches =- ObservableList<RecentWatchItem>();-- static const int _recentWatchLimit = 6;static const Duration _refreshDebounce = Duration(milliseconds: 300);int _viewerCount = 0;final List<StreamSubscription<void>> _subscriptions = [];Timer? _refreshDebounceTimer;- /// Follows every source the stats are derived from while a viewer is on- /// screen, and derives once more to catch up on what changed while there was- /// none. The count survives a route swap that attaches the next page before- /// detaching the last.+ // Route swaps can briefly attach two page instances.void attach() {_viewerCount++;if (_subscriptions.isEmpty) {for (final changes in [_historyRepository.changes,- _collectCrudRepository.changes,_downloadRepository.changes,]) {_subscriptions.add(changes.listen((_) => _scheduleRefresh()));@@ -71,30 +58,17 @@ abstract class _MyController with Store {}void _scheduleRefresh() {- // Playback rewrites history every second and a sync restore rewrites- // collectibles one by one; coalesce those into one pass.+ // Coalesce frequent playback history writes._refreshDebounceTimer?.cancel();_refreshDebounceTimer = Timer(_refreshDebounce, _refresh);}@actionvoid _refresh() {- final histories = _historyRepository.getAllHistories();watchStats = WatchStats.from(- histories: histories,- collectibles: _collectCrudRepository.getAllCollectibles(),+ histories: _historyRepository.getAllHistories(),downloadRecords: _downloadRepository.getAllRecords(),);- // getAllHistories is already sorted by most recent watch time.- final recents = histories- .take(_recentWatchLimit)- .map(RecentWatchItem.from)- .toList(growable: false);- if (!listEquals(recents, recentWatches)) {- recentWatches- ..clear()- ..addAll(recents);- }}@observablediff --git a/lib/pages/my/my_page.dart b/lib/pages/my/my_page.dartindex 08d0e64e..4ef6bade 100644--- a/lib/pages/my/my_page.dart+++ b/lib/pages/my/my_page.dart@@ -3,17 +3,9 @@ import 'package:flutter_mobx/flutter_mobx.dart';import 'package:flutter_modular/flutter_modular.dart';import 'package:kazumi/bean/appbar/sys_app_bar.dart';-import 'package:kazumi/bean/settings/settings_list.dart';-import 'package:kazumi/bean/widget/split_list_row.dart';-import 'package:kazumi/modules/collect/collect_type.dart';-import 'package:kazumi/modules/my/watch_stats.dart';import 'package:kazumi/pages/menu/route_visibility.dart';import 'package:kazumi/pages/my/my_controller.dart';-import 'package:kazumi/pages/my/recent_watch_card.dart';-import 'package:kazumi/utils/constants.dart';-import 'package:kazumi/utils/date_time.dart';--const double _cardRadius = 16;+import 'package:kazumi/pages/my/my_space_view.dart';class MyPage extends StatefulWidget {const MyPage({super.key, required this.controller});@@ -25,17 +17,23 @@ class MyPage extends StatefulWidget {}class _MyPageState extends State<MyPage> {- MyController get myController => widget.controller;-bool _attached = false;@overridevoid didChangeDependencies() {super.didChangeDependencies();- // Pause history updates while the mounted page is covered by the player._setAttached(!RouteVisibility.isCoveredOf(context));}+ @override+ void didUpdateWidget(covariant MyPage oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (_attached && oldWidget.controller != widget.controller) {+ oldWidget.controller.detach();+ widget.controller.attach();+ }+ }+@overridevoid dispose() {_setAttached(false);@@ -43,32 +41,30 @@ class _MyPageState extends State<MyPage> {}void _setAttached(bool value) {- if (_attached == value) {- return;- }+ if (_attached == value) return;_attached = value;if (value) {- myController.attach();+ widget.controller.attach();} else {- myController.detach();+ widget.controller.detach();}}- int _recentCrossCount() {- final width = MediaQuery.sizeOf(context).width;- if (width > LayoutBreakpoint.medium['width']!) {- return 3;- }- if (width > LayoutBreakpoint.compact['width']!) {- return 2;- }- return 1;- }+ void _open(MyDestination destination) =>+ context.pushNamed(switch (destination) {+ MyDestination.theme => '/settings/theme',+ MyDestination.player => '/settings/player',+ MyDestination.danmaku => '/settings/danmaku/',+ MyDestination.rules => '/settings/plugin/',+ MyDestination.history => '/settings/history/',+ MyDestination.downloads => '/settings/download/',+ MyDestination.sync => '/settings/webdav/',+ MyDestination.storage => '/settings/storage',+ MyDestination.about => '/settings/about/',+ });@overrideWidget build(BuildContext context) {- final bool wide =- MediaQuery.sizeOf(context).width > LayoutBreakpoint.compact['width']!;return Scaffold(appBar: SysAppBar(toolbarHeight: 72,@@ -80,354 +76,24 @@ class _MyPageState extends State<MyPage> {?.copyWith(fontWeight: FontWeight.w700),),needTopOffset: false,+ actions: [+ Padding(+ padding: const EdgeInsets.only(right: 8),+ child: MySettingsButton(+ onTap: () => context.pushNamed('/settings/'),+ ),+ ),+ ],),body: SafeArea(top: false,bottom: false,child: Observer(- builder: (context) {- final stats = myController.watchStats;- return SingleChildScrollView(- padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),- child: Center(- child: ConstrainedBox(- constraints: BoxConstraints(maxWidth: wide ? 1400 : 1100),- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- if (wide) _wideHeader(stats) else ..._narrowHeader(stats),- ..._recentSection(),- ],- ),- ),- ),- );- },- ),- ),- );- }-- List<Widget> _narrowHeader(WatchStats stats) {- return [- _CollectHero(stats: stats),- const SizedBox(height: 12),- _statTiles(stats),- const SizedBox(height: 12),- _entryGroup(stats),- ];- }-- Widget _wideHeader(WatchStats stats) {- return Row(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Expanded(- flex: 3,- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- _CollectHero(stats: stats),- const SizedBox(height: 12),- _statTiles(stats),- ],+ builder: (context) => MySpaceView(+ stats: widget.controller.watchStats,+ onOpen: _open,),),- const SizedBox(width: 16),- Expanded(flex: 2, child: _entryGroup(stats)),- ],- );- }-- List<Widget> _recentSection() {- final crossCount = _recentCrossCount();- final int maxCount = crossCount == 1 ? 3 : crossCount * 2;- final int count = myController.recentWatches.length < maxCount- ? myController.recentWatches.length- : maxCount;- if (count == 0) {- return const [];- }- return [- const SizedBox(height: 24),- _sectionLabel('继续观看'),- const SizedBox(height: 12),- GridView.builder(- shrinkWrap: true,- padding: EdgeInsets.zero,- physics: const NeverScrollableScrollPhysics(),- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(- crossAxisCount: crossCount,- crossAxisSpacing: StyleString.cardSpace,- mainAxisSpacing: StyleString.cardSpace,- mainAxisExtent: 128,- ),- itemCount: count,- itemBuilder: (context, index) {- final item = myController.recentWatches[index];- return RecentWatchCard(key: ValueKey(item.id), item: item);- },- ),- ];- }-- Widget _sectionLabel(String text) {- final theme = Theme.of(context);- return Padding(- padding: const EdgeInsets.only(left: 4),- child: Text(- text,- style: theme.textTheme.titleSmall?.copyWith(- color: theme.colorScheme.onSurfaceVariant,- ),- ),- );- }-- Widget _statTiles(WatchStats stats) {- final tiles = <Widget>[- _StatTile(- value: '${stats.watchedBangumiCount}',- unit: '部',- label: '看过番剧',- ),- _StatTile(- value: '${stats.watchedEpisodeCount}',- unit: '集',- label: '观看集数',- ),- _StatTile(- value: '${stats.downloadTaskCount}',- unit: '集',- label: '离线缓存',- ),- ];-- return IntrinsicHeight(- child: Row(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- for (var i = 0; i < tiles.length; i++) ...[- if (i > 0) const SizedBox(width: 12),- Expanded(child: tiles[i]),- ],- ],- ),- );- }-- Widget _entryGroup(WatchStats stats) {- return SplitListGroup(- outerRadius: _cardRadius,- children: [- SettingsCategoryTile(- icon: Icons.history_rounded,- title: '历史记录',- description: stats.lastWatchName != null- ? '最近看到 ${stats.lastWatchName}'- : '还没有观看记录',- onTap: () => context.pushNamed('/settings/history/'),- ),- SettingsCategoryTile(- icon: Icons.download_rounded,- title: '离线下载',- description: '缓存任务与本地文件',- onTap: () => context.pushNamed('/settings/download/'),- ),- SettingsCategoryTile(- icon: Icons.settings_rounded,- title: '设置',- description: '播放、弹幕、外观与规则',- onTap: () => context.pushNamed('/settings/'),- ),- ],- );- }-}--class _CollectHero extends StatelessWidget {- const _CollectHero({required this.stats});-- final WatchStats stats;-- static const List<CollectType> _order = [- CollectType.watching,- CollectType.planToWatch,- CollectType.onHold,- CollectType.watched,- CollectType.abandoned,- ];-- @override- Widget build(BuildContext context) {- final colorScheme = Theme.of(context).colorScheme;- final textTheme = Theme.of(context).textTheme;- final lastWatchTime = stats.lastWatchTime;- final String caption = lastWatchTime == null- ? '收藏番剧后会在这里汇总'- : '最近观看 ${formatTimestampToRelativeTime(lastWatchTime.millisecondsSinceEpoch ~/ 1000)}';-- return Container(- padding: const EdgeInsets.all(20),- decoration: BoxDecoration(- color: colorScheme.surfaceContainerLow,- borderRadius: BorderRadius.circular(_cardRadius),- ),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Row(- children: [- Container(- width: 36,- height: 36,- decoration: BoxDecoration(- color: colorScheme.primaryContainer,- shape: BoxShape.circle,- ),- child: Icon(- Icons.favorite_rounded,- size: 18,- color: colorScheme.onPrimaryContainer,- ),- ),- const SizedBox(width: 12),- Text(- '我的追番',- style: textTheme.titleMedium?.copyWith(- color: colorScheme.onSurface,- ),- ),- ],- ),- const SizedBox(height: 16),- Text.rich(- TextSpan(- children: [- TextSpan(- text: '${stats.collectedCount}',- style: textTheme.displaySmall?.copyWith(- color: colorScheme.primary,- fontWeight: FontWeight.w500,- ),- ),- TextSpan(- text: ' 部',- style: textTheme.titleMedium?.copyWith(- color: colorScheme.onSurfaceVariant,- ),- ),- ],- ),- ),- const SizedBox(height: 12),- if (stats.collectedCount > 0)- Wrap(- spacing: 8,- runSpacing: 8,- children: [- for (final type in _order)- if ((stats.collectCounts[type] ?? 0) > 0)- _CollectChip(- label: type.label,- count: stats.collectCounts[type]!,- ),- ],- ),- if (stats.collectedCount > 0) const SizedBox(height: 12),- Text(- caption,- style: textTheme.bodyMedium?.copyWith(- color: colorScheme.onSurfaceVariant,- ),- ),- ],- ),- );- }-}--class _CollectChip extends StatelessWidget {- const _CollectChip({required this.label, required this.count});-- final String label;- final int count;-- @override- Widget build(BuildContext context) {- final colorScheme = Theme.of(context).colorScheme;- final textTheme = Theme.of(context).textTheme;- return Container(- padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),- decoration: BoxDecoration(- color: colorScheme.secondaryContainer,- borderRadius: BorderRadius.circular(8),- ),- child: Text(- '$label $count',- style: textTheme.labelMedium?.copyWith(- color: colorScheme.onSecondaryContainer,- ),- ),- );- }-}--class _StatTile extends StatelessWidget {- const _StatTile({- required this.value,- required this.unit,- required this.label,- });-- final String value;- final String unit;- final String label;-- @override- Widget build(BuildContext context) {- final colorScheme = Theme.of(context).colorScheme;- final textTheme = Theme.of(context).textTheme;- return Container(- padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 16),- decoration: BoxDecoration(- color: colorScheme.surfaceContainerLow,- borderRadius: BorderRadius.circular(_cardRadius),- ),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text.rich(- TextSpan(- children: [- TextSpan(- text: value,- style: textTheme.headlineSmall?.copyWith(- color: colorScheme.onSurface,- fontWeight: FontWeight.w500,- ),- ),- TextSpan(- text: ' $unit',- style: textTheme.bodyMedium?.copyWith(- color: colorScheme.onSurfaceVariant,- ),- ),- ],- ),- maxLines: 1,- overflow: TextOverflow.ellipsis,- ),- const SizedBox(height: 2),- Text(- label,- style: textTheme.bodyMedium?.copyWith(- color: colorScheme.onSurfaceVariant,- ),- maxLines: 2,- overflow: TextOverflow.ellipsis,- ),- ],),);}diff --git a/lib/pages/my/my_space_view.dart b/lib/pages/my/my_space_view.dartnew file mode 100644index 00000000..89f0edc2--- /dev/null+++ b/lib/pages/my/my_space_view.dart@@ -0,0 +1,676 @@+import 'package:flutter/material.dart';+import 'package:kazumi/modules/my/watch_stats.dart';+import 'package:material_new_shapes/material_new_shapes.dart';++enum MyDestination {+ theme,+ player,+ danmaku,+ rules,+ history,+ downloads,+ sync,+ storage,+ about,+}++const _tileRadius = BorderRadius.all(Radius.circular(28));++class MySpaceView extends StatelessWidget {+ const MySpaceView({+ super.key,+ required this.stats,+ required this.onOpen,+ });++ final WatchStats stats;+ final ValueChanged<MyDestination> onOpen;++ @override+ Widget build(BuildContext context) {+ final colors = Theme.of(context).colorScheme;+ return LayoutBuilder(builder: (context, constraints) {+ final inset = constraints.maxWidth < 600 ? 16.0 : 32.0;+ final width = (constraints.maxWidth - inset * 2).clamp(0.0, 1120.0);+ final largeText = MediaQuery.textScalerOf(context).scale(16) > 24;+ final wide = width >= 840 && !largeText;+ final columnWidth = wide ? (width - 12) / 2 : width;+ final stackTools = columnWidth < 300 || largeText;+ return SingleChildScrollView(+ key: const PageStorageKey('my-space'),+ padding: EdgeInsets.fromLTRB(inset, 12, inset, 32),+ child: Center(+ child: ConstrainedBox(+ constraints: const BoxConstraints(maxWidth: 1120),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ _AdaptivePair(+ stack: !wide,+ gap: 20,+ first: const _SpaceHeading(),+ second: _WatchStatsPanel(+ bangumiCount: stats.watchedBangumiCount,+ episodeCount: stats.watchedEpisodeCount,+ ),+ ),+ const SizedBox(height: 28),+ _AdaptivePair(+ stack: !wide,+ gap: 12,+ first: _RulesTile(onTap: () => onOpen(MyDestination.rules)),+ second: _AdaptivePair(+ stack: stackTools,+ gap: 12,+ first: _ToolTile(+ icon: Icons.history_rounded,+ title: '历史记录',+ caption:+ stats.watchedBangumiCount == 0 ? '暂无观看记录' : '查看观看记录',+ color: colors.secondaryContainer,+ foreground: colors.onSecondaryContainer,+ onTap: () => onOpen(MyDestination.history),+ ),+ second: _ToolTile(+ icon: Icons.download_rounded,+ title: '离线下载',+ caption: stats.downloadTaskCount == 0+ ? '管理离线内容'+ : '${stats.downloadTaskCount} 集下载任务',+ color: colors.tertiaryContainer,+ foreground: colors.onTertiaryContainer,+ onTap: () => onOpen(MyDestination.downloads),+ ),+ ),+ ),+ const SizedBox(height: 12),+ _AdaptivePair(+ stack: !wide,+ gap: 12,+ first: _PreferencesPanel(+ onOpen: onOpen,+ stack: columnWidth < 280 || largeText,+ ),+ second: _AdaptivePair(+ stack: stackTools,+ gap: 12,+ first: _ToolTile(+ icon: Icons.cloud_sync_rounded,+ title: '同步备份',+ caption: '跨设备同步数据',+ color: colors.surfaceContainer,+ foreground: colors.onSurface,+ onTap: () => onOpen(MyDestination.sync),+ ),+ second: _ToolTile(+ icon: Icons.cleaning_services_rounded,+ title: '存储管理',+ caption: '缓存与日志',+ color: colors.surfaceContainer,+ foreground: colors.onSurface,+ onTap: () => onOpen(MyDestination.storage),+ ),+ ),+ ),+ const SizedBox(height: 24),+ Align(+ alignment: Alignment.center,+ child: _ExpressiveAction(+ color: colors.surfaceContainerLow,+ foreground: colors.onSurfaceVariant,+ onTap: () => onOpen(MyDestination.about),+ child: const Padding(+ padding:+ EdgeInsets.symmetric(horizontal: 20, vertical: 14),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Icon(Icons.info_outline_rounded, size: 20),+ SizedBox(width: 8),+ Flexible(child: Text('关于 Kazumi')),+ ],+ ),+ ),+ ),+ ),+ ],+ ),+ ),+ ),+ );+ });+ }+}++class _WatchStatsPanel extends StatelessWidget {+ const _WatchStatsPanel({+ required this.bangumiCount,+ required this.episodeCount,+ });++ final int bangumiCount;+ final int episodeCount;++ @override+ Widget build(BuildContext context) {+ final colors = Theme.of(context).colorScheme;+ return Material(+ color: colors.surfaceContainerHigh,+ borderRadius: BorderRadius.circular(48),+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ Text('观看统计',+ style: Theme.of(context)+ .textTheme+ .labelMedium+ ?.copyWith(color: colors.onSurfaceVariant)),+ const SizedBox(height: 8),+ Row(+ children: [+ Expanded(child: _StatCount(value: bangumiCount, label: '看过番剧')),+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 12),+ child: Icon(Icons.auto_awesome_rounded,+ color: colors.primary, size: 20),+ ),+ Expanded(child: _StatCount(value: episodeCount, label: '观看集数')),+ ],+ ),+ ],+ ),+ ),+ );+ }+}++class _StatCount extends StatelessWidget {+ const _StatCount({required this.value, required this.label});++ final int value;+ final String label;++ @override+ Widget build(BuildContext context) {+ final theme = Theme.of(context);+ return Column(+ children: [+ // Scale large totals without shrinking their labels.+ FittedBox(+ fit: BoxFit.scaleDown,+ child: Text('$value',+ style: theme.textTheme.displaySmall?.copyWith(+ color: theme.colorScheme.onSurface,+ fontWeight: FontWeight.w800,+ fontFeatures: const [FontFeature.tabularFigures()])),+ ),+ const SizedBox(height: 2),+ Text(label,+ textAlign: TextAlign.center,+ style: theme.textTheme.labelMedium+ ?.copyWith(color: theme.colorScheme.onSurfaceVariant)),+ ],+ );+ }+}++class _SpaceHeading extends StatelessWidget {+ const _SpaceHeading();++ @override+ Widget build(BuildContext context) {+ final colors = Theme.of(context).colorScheme;+ return Row(+ children: [+ Expanded(+ child: Text(+ '个人中心',+ style: Theme.of(context).textTheme.displaySmall?.copyWith(+ fontWeight: FontWeight.w800,+ color: colors.onSurface,+ height: 1.2,+ ),+ ),+ ),+ const SizedBox(width: 12),+ _ShapeIcon(+ shape: _SpaceShape.sun,+ icon: Icons.sentiment_satisfied_alt_rounded,+ size: 64,+ color: colors.tertiaryContainer,+ foreground: colors.onTertiaryContainer,+ ),+ ],+ );+ }+}++class _RulesTile extends StatelessWidget {+ const _RulesTile({required this.onTap});++ final VoidCallback onTap;++ @override+ Widget build(BuildContext context) {+ final colors = Theme.of(context).colorScheme;+ final text = Theme.of(context).textTheme;+ return _ExpressiveAction(+ color: colors.primary,+ foreground: colors.onPrimary,+ radius: const BorderRadius.only(+ topLeft: Radius.circular(28),+ topRight: Radius.circular(64),+ bottomLeft: Radius.circular(28),+ bottomRight: Radius.circular(28),+ ),+ onTap: onTap,+ child: Padding(+ padding: const EdgeInsets.all(24),+ child: Row(+ children: [+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ Text('规则设置',+ style: text.headlineSmall?.copyWith(+ fontWeight: FontWeight.w700,+ color: colors.onPrimary)),+ const SizedBox(height: 6),+ Text('管理番剧来源',+ style:+ text.bodyMedium?.copyWith(color: colors.onPrimary)),+ const SizedBox(height: 20),+ _ArrowCue(+ color: colors.onPrimary, foreground: colors.primary),+ ],+ ),+ ),+ const SizedBox(width: 12),+ _ShapeIcon(+ shape: _SpaceShape.clover,+ icon: Icons.extension_rounded,+ size: 80,+ color: colors.primaryContainer,+ foreground: colors.onPrimaryContainer,+ ),+ ],+ ),+ ),+ );+ }+}++class _ToolTile extends StatelessWidget {+ const _ToolTile({+ required this.icon,+ required this.title,+ required this.caption,+ required this.color,+ required this.foreground,+ required this.onTap,+ });++ final IconData icon;+ final String title;+ final String caption;+ final Color color;+ final Color foreground;+ final VoidCallback onTap;++ @override+ Widget build(BuildContext context) {+ final text = Theme.of(context).textTheme;+ return _ExpressiveAction(+ color: color,+ foreground: foreground,+ onTap: onTap,+ child: Padding(+ padding: const EdgeInsets.all(20),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ Row(+ children: [+ Icon(icon, size: 30),+ const Spacer(),+ const Icon(Icons.arrow_forward_rounded, size: 20),+ ],+ ),+ const SizedBox(height: 26),+ Text(title,+ style: text.titleMedium+ ?.copyWith(fontWeight: FontWeight.w700, color: foreground)),+ const SizedBox(height: 6),+ Text(caption,+ style:+ text.bodySmall?.copyWith(color: foreground, height: 1.4)),+ ],+ ),+ ),+ );+ }+}++class _PreferencesPanel extends StatelessWidget {+ const _PreferencesPanel({required this.onOpen, required this.stack});++ final ValueChanged<MyDestination> onOpen;+ final bool stack;++ static const _entries = [+ ('外观', Icons.palette_rounded, MyDestination.theme),+ ('播放', Icons.play_circle_rounded, MyDestination.player),+ ('弹幕', Icons.subtitles_rounded, MyDestination.danmaku),+ ];++ @override+ Widget build(BuildContext context) {+ final colors = Theme.of(context).colorScheme;+ final buttons = Flex(+ direction: stack ? Axis.vertical : Axis.horizontal,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ for (var i = 0; i < _entries.length; i++) ...[+ if (i > 0) const SizedBox(width: 4, height: 4),+ if (stack) _button(i) else Expanded(child: _button(i)),+ ],+ ],+ );+ return Material(+ color: colors.surfaceContainerLow,+ borderRadius: _tileRadius,+ child: Padding(+ padding: const EdgeInsets.all(20),+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Semantics(+ header: true,+ child: Text('偏好设置',+ style: Theme.of(context).textTheme.titleMedium?.copyWith(+ fontWeight: FontWeight.w700, color: colors.onSurface)),+ ),+ const SizedBox(height: 16),+ if (stack) buttons else IntrinsicHeight(child: buttons),+ ],+ ),+ ),+ );+ }++ Widget _button(int index) {+ final (label, icon, destination) = _entries[index];+ return _PreferenceAction(+ icon: icon,+ label: label,+ stack: stack,+ first: index == 0,+ last: index == _entries.length - 1,+ onTap: () => onOpen(destination),+ );+ }+}++class _PreferenceAction extends StatelessWidget {+ const _PreferenceAction({+ required this.icon,+ required this.label,+ required this.stack,+ required this.first,+ required this.last,+ required this.onTap,+ });++ final IconData icon;+ final String label;+ final bool stack;+ final bool first;+ final bool last;+ final VoidCallback onTap;++ @override+ Widget build(BuildContext context) {+ final colors = Theme.of(context).colorScheme;+ final radius = stack+ ? BorderRadius.vertical(+ top: Radius.circular(first ? 24 : 8),+ bottom: Radius.circular(last ? 24 : 8))+ : BorderRadius.horizontal(+ left: Radius.circular(first ? 24 : 8),+ right: Radius.circular(last ? 24 : 8));+ return _ExpressiveAction(+ color: colors.secondaryContainer,+ foreground: colors.onSecondaryContainer,+ radius: radius,+ onTap: onTap,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 18),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Icon(icon, size: 28),+ const SizedBox(height: 10),+ Text(label,+ textAlign: TextAlign.center,+ style: Theme.of(context).textTheme.labelLarge?.copyWith(+ fontWeight: FontWeight.w700,+ color: colors.onSecondaryContainer)),+ ],+ ),+ ),+ );+ }+}++class MySettingsButton extends StatelessWidget {+ const MySettingsButton({super.key, required this.onTap});++ final VoidCallback onTap;++ @override+ Widget build(BuildContext context) {+ final colors = Theme.of(context).colorScheme;+ return Tooltip(+ message: '全部设置',+ child: _ExpressiveAction(+ color: colors.surfaceContainerHigh,+ foreground: colors.onSurface,+ onTap: onTap,+ child: const Padding(+ padding: EdgeInsets.symmetric(horizontal: 18, vertical: 14),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Icon(Icons.tune_rounded, size: 20),+ SizedBox(width: 8),+ Text('设置'),+ ],+ ),+ ),+ ),+ );+ }+}++class _ArrowCue extends StatelessWidget {+ const _ArrowCue({required this.color, required this.foreground});++ final Color color;+ final Color foreground;++ @override+ Widget build(BuildContext context) => ExcludeSemantics(+ child: Container(+ width: 52,+ height: 32,+ decoration: BoxDecoration(+ color: color, borderRadius: BorderRadius.circular(20)),+ child: Icon(Icons.arrow_forward_rounded, color: foreground, size: 20),+ ),+ );+}++enum _SpaceShape { sun, clover }++class _ShapeIcon extends StatelessWidget {+ const _ShapeIcon({+ required this.shape,+ required this.icon,+ required this.size,+ required this.color,+ required this.foreground,+ });++ final _SpaceShape shape;+ final IconData icon;+ final double size;+ final Color color;+ final Color foreground;++ @override+ Widget build(BuildContext context) => ExcludeSemantics(+ child: ClipPath(+ clipper: _SpaceShapeClipper(shape),+ child: ColoredBox(+ color: color,+ child: SizedBox.square(+ dimension: size,+ child: Icon(icon, color: foreground, size: size * .44),+ ),+ ),+ ),+ );+}++class _SpaceShapeClipper extends CustomClipper<Path> {+ const _SpaceShapeClipper(this.shape);++ final _SpaceShape shape;+ static final _paths = {+ _SpaceShape.sun: MaterialShapes.sunny.toPath(),+ _SpaceShape.clover: MaterialShapes.clover4Leaf.toPath(),+ };++ @override+ Path getClip(Size size) => _paths[shape]!+ .transform(Matrix4.diagonal3Values(size.width, size.height, 1).storage);++ @override+ bool shouldReclip(_SpaceShapeClipper oldClipper) => oldClipper.shape != shape;+}++class _ExpressiveAction extends StatefulWidget {+ const _ExpressiveAction({+ required this.color,+ required this.foreground,+ required this.onTap,+ required this.child,+ this.radius = _tileRadius,+ });++ final Color color;+ final Color foreground;+ final VoidCallback onTap;+ final Widget child;+ final BorderRadius radius;++ @override+ State<_ExpressiveAction> createState() => _ExpressiveActionState();+}++class _ExpressiveActionState extends State<_ExpressiveAction> {+ bool _pressed = false;++ @override+ Widget build(BuildContext context) {+ final reducedMotion = MediaQuery.disableAnimationsOf(context);+ final duration = reducedMotion+ ? Duration.zero+ : Duration(milliseconds: _pressed ? 150 : 300);+ return Semantics(+ button: true,+ child: AnimatedScale(+ scale: _pressed && !reducedMotion ? .97 : 1,+ duration: duration,+ curve: _pressed ? Curves.easeOutCubic : Curves.easeOutBack,+ child: AnimatedContainer(+ duration: duration,+ curve: Curves.easeOutCubic,+ clipBehavior: Clip.antiAlias,+ decoration: BoxDecoration(+ color: widget.color,+ borderRadius: _pressed ? BorderRadius.circular(16) : widget.radius,+ ),+ child: Material(+ type: MaterialType.transparency,+ child: InkWell(+ onTap: widget.onTap,+ onHighlightChanged: (value) => setState(() => _pressed = value),+ overlayColor: WidgetStateProperty.resolveWith((states) {+ if (states.contains(WidgetState.pressed)) {+ return widget.foreground.withValues(alpha: .10);+ }+ if (states.contains(WidgetState.focused)) {+ return widget.foreground.withValues(alpha: .12);+ }+ if (states.contains(WidgetState.hovered)) {+ return widget.foreground.withValues(alpha: .08);+ }+ return null;+ }),+ child: IconTheme.merge(+ data: IconThemeData(color: widget.foreground),+ child: DefaultTextStyle.merge(+ style: Theme.of(context).textTheme.labelLarge?.copyWith(+ color: widget.foreground,+ ),+ child: widget.child,+ ),+ ),+ ),+ ),+ ),+ ),+ );+ }+}++class _AdaptivePair extends StatelessWidget {+ const _AdaptivePair({+ required this.first,+ required this.second,+ required this.stack,+ required this.gap,+ });++ final Widget first;+ final Widget second;+ final bool stack;+ final double gap;++ @override+ Widget build(BuildContext context) {+ if (stack) {+ return Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [first, SizedBox(height: gap), second],+ );+ }+ return IntrinsicHeight(+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Expanded(child: first),+ SizedBox(width: gap),+ Expanded(child: second),+ ],+ ),+ );+ }+}diff --git a/lib/pages/my/recent_watch_card.dart b/lib/pages/my/recent_watch_card.dartdeleted file mode 100644index eaf6f8bd..00000000--- a/lib/pages/my/recent_watch_card.dart+++ /dev/null@@ -1,179 +0,0 @@-import 'package:flutter/material.dart';-import 'package:flutter_modular/flutter_modular.dart';-import 'package:kazumi/bean/card/network_img_layer.dart';-import 'package:kazumi/bean/dialog/dialog_helper.dart';-import 'package:kazumi/modules/my/recent_watch_item.dart';-import 'package:kazumi/services/player/history_playback_service.dart';-import 'package:kazumi/services/plugin/rule_engine_models.dart'- show RuleCancelToken;-import 'package:kazumi/utils/date_time.dart';-import 'package:kazumi/utils/device.dart';--class RecentWatchCard extends StatefulWidget {- const RecentWatchCard({super.key, required this.item});-- final RecentWatchItem item;-- @override- State<RecentWatchCard> createState() => _RecentWatchCardState();-}--class _RecentWatchCardState extends State<RecentWatchCard>- with KazumiDialogOwner {- static const double _coverWidth = 78;- static const double _coverHeight = 104;-- final HistoryPlaybackService _playbackService =- inject<HistoryPlaybackService>();-- Future<void> _play() => dialogs.run((task) async {- final cancelToken = RuleCancelToken();- final result = await task.loading(- message: '获取中',- barrierDismissible: isDesktop(),- onCancel: cancelToken.cancel,- action: () => _playbackService.open(widget.item.history,- cancelToken: cancelToken),- );- switch (result) {- case HistoryPlaybackReady(:final args):- task.withContext(- (context) => context.pushNamed('/video/', arguments: args));- case HistoryPlaybackUnavailable(:final reason):- KazumiDialog.showToast(message: reason);- }- }, errorMessage: '暂时无法继续播放,请稍后重试');-- @override- Widget build(BuildContext context) {- final theme = Theme.of(context);- final colorScheme = theme.colorScheme;- final item = widget.item;-- return Material(- color: colorScheme.surfaceContainerLow,- borderRadius: BorderRadius.circular(16),- clipBehavior: Clip.antiAlias,- child: InkWell(- onTap: _play,- child: Padding(- padding: const EdgeInsets.all(12),- child: Row(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- _cover(colorScheme),- const SizedBox(width: 14),- Expanded(- child: SizedBox(- height: _coverHeight,- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Text(- item.title,- style: theme.textTheme.titleSmall?.copyWith(- color: colorScheme.onSurface,- fontWeight: FontWeight.w600,- height: 1.25,- ),- maxLines: 2,- overflow: TextOverflow.ellipsis,- ),- Text(- '看到 ${item.episodeLabel}',- style: theme.textTheme.bodyMedium?.copyWith(- color: colorScheme.onSurfaceVariant,- ),- maxLines: 1,- overflow: TextOverflow.ellipsis,- ),- Row(- children: [- _pill(- label: item.sourceLabel,- background: colorScheme.secondaryContainer,- foreground: colorScheme.onSecondaryContainer,- ),- const SizedBox(width: 6),- Flexible(- child: _pill(- label: item.adapterName,- background: colorScheme.surfaceContainerHighest,- foreground: colorScheme.onSurfaceVariant,- ),- ),- const SizedBox(width: 8),- Text(- formatTimestampToRelativeTime(- item.lastWatchTime.millisecondsSinceEpoch ~/ 1000,- ),- style: theme.textTheme.labelSmall?.copyWith(- color: colorScheme.outline,- ),- maxLines: 1,- ),- ],- ),- ],- ),- ),- ),- ],- ),- ),- ),- );- }-- Widget _cover(ColorScheme colorScheme) {- return SizedBox(- width: _coverWidth,- height: _coverHeight,- child: Stack(- alignment: Alignment.center,- children: [- NetworkImgLayer(- src: widget.item.coverUrl,- width: _coverWidth,- height: _coverHeight,- ),- Container(- width: 34,- height: 34,- decoration: BoxDecoration(- color: colorScheme.primary.withValues(alpha: 0.92),- shape: BoxShape.circle,- ),- child: Icon(- Icons.play_arrow_rounded,- size: 22,- color: colorScheme.onPrimary,- ),- ),- ],- ),- );- }-- Widget _pill({- required String label,- required Color background,- required Color foreground,- }) {- return Container(- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),- decoration: BoxDecoration(- color: background,- borderRadius: BorderRadius.circular(8),- ),- child: Text(- label,- style:- Theme.of(context).textTheme.labelSmall?.copyWith(color: foreground),- maxLines: 1,- overflow: TextOverflow.ellipsis,- ),- );- }-}