Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

refactor: better history page

Predidit48b6227b2345
diff --git a/lib/bean/card/bangumi_history_card.dart b/lib/bean/card/bangumi_history_card.dart
index d2c59cd0..3d8b9292 100644
--- a/lib/bean/card/bangumi_history_card.dart
+++ b/lib/bean/card/bangumi_history_card.dart
@@ -16,15 +16,13 @@ class BangumiHistoryCardV extends StatefulWidget {
const BangumiHistoryCardV({
super.key,
required this.historyItem,
- this.showDelete = true,
- this.cardHeight = 120,
- this.cardWidth,
+ this.showDelete = false,
+ this.onDeleted,
});
final History historyItem;
final bool showDelete;
- final double cardHeight;
- final double? cardWidth;
+ final VoidCallback? onDeleted;
@override
State<BangumiHistoryCardV> createState() => _BangumiHistoryCardVState();
@@ -36,189 +34,226 @@ class _BangumiHistoryCardVState extends State<BangumiHistoryCardV> {
final PluginsController pluginsController = Modular.get<PluginsController>();
final HistoryController historyController = Modular.get<HistoryController>();
- Widget propertyChip({
- required String title,
- required String value,
- bool showTitle = false,
- }) {
- final message = '$title: $value';
- return Chip(
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(32)),
- backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
- materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
- padding: const EdgeInsets.symmetric(horizontal: 2),
- side: BorderSide.none,
- label: Text(
- showTitle ? message : value,
- style: Theme.of(context).textTheme.labelSmall,
- overflow: TextOverflow.ellipsis,
- maxLines: 1,
- ),
- );
- }
-
- Widget buildImage(
- BuildContext context, String imageUrl, double width, double height) {
- final borderRadius = BorderRadius.circular(16);
- Widget img = NetworkImgLayer(
- src: imageUrl,
- width: width,
- height: height,
+ Future<void> _onTap() async {
+ if (widget.showDelete) {
+ KazumiDialog.showToast(message: '编辑模式');
+ return;
+ }
+ KazumiDialog.showLoading(
+ msg: '获取中',
+ barrierDismissible: Utils.isDesktop(),
+ onDismiss: () {
+ videoPageController.cancelQueryRoads();
+ },
);
- img = ClipRRect(
- borderRadius: borderRadius,
- child: img,
- );
- return img;
+ bool flag = false;
+ for (Plugin plugin in pluginsController.pluginList) {
+ if (plugin.name == widget.historyItem.adapterName) {
+ videoPageController.currentPlugin = plugin;
+ flag = true;
+ break;
+ }
+ }
+ if (!flag) {
+ KazumiDialog.dismiss();
+ KazumiDialog.showToast(message: '未找到关联番剧源');
+ return;
+ }
+ videoPageController.bangumiItem = widget.historyItem.bangumiItem;
+ videoPageController.title =
+ widget.historyItem.bangumiItem.nameCn == ''
+ ? widget.historyItem.bangumiItem.name
+ : widget.historyItem.bangumiItem.nameCn;
+ videoPageController.src = widget.historyItem.lastSrc;
+ try {
+ await videoPageController.queryRoads(widget.historyItem.lastSrc,
+ videoPageController.currentPlugin.name);
+ KazumiDialog.dismiss();
+ Modular.to.pushNamed('/video/');
+ } catch (_) {
+ KazumiLogger().w("QueryManager: failed to query roads");
+ KazumiDialog.dismiss();
+ }
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
- final double borderRadius = 18;
- final double imageWidth = widget.cardHeight * 0.7;
+ final colorScheme = theme.colorScheme;
+ final double imageWidth = 80;
+ final double imageHeight = 108;
+ final String title = widget.historyItem.bangumiItem.nameCn == ''
+ ? widget.historyItem.bangumiItem.name
+ : widget.historyItem.bangumiItem.nameCn;
+ final String episodeText =
+ widget.historyItem.lastWatchEpisodeName.isEmpty
+ ? '第${widget.historyItem.lastWatchEpisode}话'
+ : widget.historyItem.lastWatchEpisodeName;
- return Card(
- elevation: 1,
- margin: const EdgeInsets.symmetric(vertical: 6, horizontal: 8),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(borderRadius),
+ return Dismissible(
+ key: ValueKey(widget.historyItem.key),
+ direction: DismissDirection.endToStart,
+ onDismissed: (_) {
+ widget.onDeleted?.call();
+ },
+ background: Container(
+ alignment: Alignment.centerRight,
+ padding: const EdgeInsets.only(right: 24),
+ margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
+ decoration: BoxDecoration(
+ color: colorScheme.errorContainer,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: Icon(
+ Icons.delete_outline,
+ color: colorScheme.onErrorContainer,
+ ),
),
- clipBehavior: Clip.antiAlias,
- color: theme.colorScheme.surface,
- child: InkWell(
- onTap: () async {
- if (widget.showDelete) {
- KazumiDialog.showToast(
- message: '编辑模式',
- );
- return;
- }
- KazumiDialog.showLoading(
- msg: '获取中',
- barrierDismissible: Utils.isDesktop(),
- onDismiss: () {
- videoPageController.cancelQueryRoads();
- },
- );
- bool flag = false;
- for (Plugin plugin in pluginsController.pluginList) {
- if (plugin.name == widget.historyItem.adapterName) {
- videoPageController.currentPlugin = plugin;
- flag = true;
- break;
- }
- }
- if (!flag) {
- KazumiDialog.dismiss();
- KazumiDialog.showToast(message: '未找到关联番剧源');
- return;
- }
- videoPageController.bangumiItem = widget.historyItem.bangumiItem;
- videoPageController.title =
- widget.historyItem.bangumiItem.nameCn == ''
- ? widget.historyItem.bangumiItem.name
- : widget.historyItem.bangumiItem.nameCn;
- videoPageController.src = widget.historyItem.lastSrc;
- try {
- await videoPageController.queryRoads(widget.historyItem.lastSrc,
- videoPageController.currentPlugin.name);
- KazumiDialog.dismiss();
- Modular.to.pushNamed('/video/');
- } catch (_) {
- KazumiLogger().w("QueryManager: failed to query roads");
- KazumiDialog.dismiss();
- }
- },
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- buildImage(
- context,
- widget.historyItem.bangumiItem.images['large'] ?? '',
- imageWidth,
- widget.cardHeight),
- const SizedBox(width: 12),
- Expanded(
- child: Padding(
- padding:
- const EdgeInsets.symmetric(vertical: 2, horizontal: 6),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 6),
- Text(
- widget.historyItem.bangumiItem.nameCn == ''
- ? widget.historyItem.bangumiItem.name
- : widget.historyItem.bangumiItem.nameCn,
- style: Theme.of(context).textTheme.titleSmall?.copyWith(
- color: Theme.of(context).colorScheme.onSurface,
- fontWeight: FontWeight.bold,
- ),
- overflow: TextOverflow.ellipsis,
- maxLines: 1,
- ),
- const SizedBox(height: 12),
- Wrap(
- spacing: 4,
- runSpacing: 4,
+ child: Card(
+ elevation: 0,
+ margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(16),
+ ),
+ clipBehavior: Clip.antiAlias,
+ color: colorScheme.surfaceContainerLow,
+ child: InkWell(
+ onTap: _onTap,
+ child: Padding(
+ padding: const EdgeInsets.all(12),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ClipRRect(
+ borderRadius: BorderRadius.circular(12),
+ child: NetworkImgLayer(
+ src: widget.historyItem.bangumiItem.images['large'] ?? '',
+ width: imageWidth,
+ height: imageHeight,
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: SizedBox(
+ height: imageHeight,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
children: [
- propertyChip(
- title: '来源',
- value: widget.historyItem.adapterName,
- showTitle: true,
+ Text(
+ title,
+ style: theme.textTheme.titleSmall?.copyWith(
+ color: colorScheme.onSurface,
+ fontWeight: FontWeight.w600,
+ ),
+ overflow: TextOverflow.ellipsis,
+ maxLines: 1,
),
- propertyChip(
- title: '看到',
- value: widget.historyItem.lastWatchEpisodeName.isEmpty
- ? '第${widget.historyItem.lastWatchEpisode}话'
- : widget.historyItem.lastWatchEpisodeName,
- showTitle: true,
+ const SizedBox(height: 6),
+ Row(
+ children: [
+ Icon(
+ Icons.play_circle_outline,
+ size: 14,
+ color: colorScheme.onSurfaceVariant,
+ ),
+ const SizedBox(width: 4),
+ Flexible(
+ child: Text(
+ episodeText,
+ style: theme.textTheme.bodySmall?.copyWith(
+ color: colorScheme.onSurfaceVariant,
+ ),
+ overflow: TextOverflow.ellipsis,
+ maxLines: 1,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 4),
+ Row(
+ children: [
+ Icon(
+ Icons.extension_outlined,
+ size: 14,
+ color: colorScheme.onSurfaceVariant,
+ ),
+ const SizedBox(width: 4),
+ Flexible(
+ child: Text(
+ widget.historyItem.adapterName,
+ style: theme.textTheme.bodySmall?.copyWith(
+ color: colorScheme.onSurfaceVariant,
+ ),
+ overflow: TextOverflow.ellipsis,
+ maxLines: 1,
+ ),
+ ),
+ ],
+ ),
+ const Spacer(),
+ Row(
+ children: [
+ Icon(
+ Icons.access_time,
+ size: 12,
+ color: colorScheme.outline,
+ ),
+ const SizedBox(width: 4),
+ Text(
+ Utils.formatTimestampToRelativeTime(
+ widget.historyItem.lastWatchTime.millisecondsSinceEpoch ~/ 1000),
+ style: theme.textTheme.labelSmall?.copyWith(
+ color: colorScheme.outline,
+ ),
+ ),
+ ],
),
],
- )
- ],
- ),
- ),
- ),
- Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- if (!widget.showDelete) ...[
- CollectButton(
- onClose: () {
- FocusScope.of(context).unfocus();
- },
- bangumiItem: widget.historyItem.bangumiItem,
- color: Theme.of(context).colorScheme.onSecondaryContainer,
- ),
- IconButton(
- icon: Icon(
- Icons.open_in_new,
- color: Theme.of(context).colorScheme.onSecondaryContainer,
),
- tooltip: '番剧详情',
- onPressed: () {
- Modular.to.pushNamed(
- '/info/',
- arguments: widget.historyItem.bangumiItem,
- );
- },
- ),
- ],
- if (widget.showDelete)
- IconButton(
- icon: Icon(
- Icons.delete,
- color: Theme.of(context).colorScheme.onSecondaryContainer,
- ),
- onPressed: () {
- historyController.deleteHistory(widget.historyItem);
- },
),
+ ),
+ Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (!widget.showDelete) ...[
+ CollectButton(
+ onClose: () {
+ FocusScope.of(context).unfocus();
+ },
+ bangumiItem: widget.historyItem.bangumiItem,
+ color: colorScheme.onSurfaceVariant,
+ ),
+ IconButton(
+ icon: Icon(
+ Icons.open_in_new,
+ size: 20,
+ color: colorScheme.onSurfaceVariant,
+ ),
+ tooltip: '番剧详情',
+ onPressed: () {
+ Modular.to.pushNamed(
+ '/info/',
+ arguments: widget.historyItem.bangumiItem,
+ );
+ },
+ ),
+ ],
+ if (widget.showDelete)
+ IconButton(
+ icon: Icon(
+ Icons.delete_outline,
+ color: colorScheme.error,
+ ),
+ tooltip: '删除记录',
+ onPressed: () {
+ widget.onDeleted?.call();
+ },
+ ),
+ ],
+ ),
],
),
- ],
+ ),
),
),
);
diff --git a/lib/pages/history/history_page.dart b/lib/pages/history/history_page.dart
index 4e33944d..6d46889d 100644
--- a/lib/pages/history/history_page.dart
+++ b/lib/pages/history/history_page.dart
@@ -14,11 +14,9 @@ class HistoryPage extends StatefulWidget {
State<HistoryPage> createState() => _HistoryPageState();
}
-class _HistoryPageState extends State<HistoryPage>
- with SingleTickerProviderStateMixin {
+class _HistoryPageState extends State<HistoryPage> {
final HistoryController historyController = Modular.get<HistoryController>();
- /// show delete button
bool showDelete = false;
@override
@@ -67,7 +65,6 @@ class _HistoryPageState extends State<HistoryPage>
@override
Widget build(BuildContext context) {
- WidgetsBinding.instance.addPostFrameCallback((_) {});
return Observer(builder: (context) {
return PopScope(
canPop: true,
@@ -78,24 +75,29 @@ class _HistoryPageState extends State<HistoryPage>
appBar: SysAppBar(
title: const Text('历史记录'),
actions: [
- IconButton(
+ if (historyController.histories.isNotEmpty) ...[
+ IconButton(
onPressed: () {
setState(() {
showDelete = !showDelete;
});
},
icon: showDelete
- ? const Icon(Icons.edit_outlined)
- : const Icon(Icons.edit))
+ ? const Icon(Icons.edit_off_outlined)
+ : const Icon(Icons.edit_outlined),
+ tooltip: showDelete ? '退出编辑' : '编辑',
+ ),
+ IconButton(
+ onPressed: () {
+ showHistoryClearDialog();
+ },
+ icon: const Icon(Icons.delete_sweep_outlined),
+ tooltip: '清除全部',
+ ),
+ ],
],
),
body: SafeArea(bottom: false, child: renderBody),
- floatingActionButton: FloatingActionButton(
- child: const Icon(Icons.clear_all),
- onPressed: () {
- showHistoryClearDialog();
- },
- ),
),
);
});
@@ -105,8 +107,24 @@ class _HistoryPageState extends State<HistoryPage>
if (historyController.histories.isNotEmpty) {
return contentGrid;
} else {
- return const Center(
- child: Text('没有找到历史记录 (´;ω;`)'),
+ return Center(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(
+ Icons.history_rounded,
+ size: 72,
+ color: Theme.of(context).colorScheme.outline.withValues(alpha: 0.5),
+ ),
+ const SizedBox(height: 16),
+ Text(
+ '没有找到历史记录',
+ style: Theme.of(context).textTheme.titleMedium?.copyWith(
+ color: Theme.of(context).colorScheme.outline,
+ ),
+ ),
+ ],
+ ),
);
}
}
@@ -119,31 +137,41 @@ class _HistoryPageState extends State<HistoryPage>
if (MediaQuery.sizeOf(context).width > LayoutBreakpoint.medium['width']!) {
crossCount = 3;
}
- double cardHeight = 120;
+
+ final double screenWidth = MediaQuery.sizeOf(context).width;
+ final double maxContentWidth = 1000;
+ final double horizontalPadding = screenWidth > maxContentWidth
+ ? (screenWidth - maxContentWidth) / 2
+ : 0;
return CustomScrollView(
slivers: [
- SliverGrid(
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- mainAxisSpacing: StyleString.cardSpace - 2,
- crossAxisSpacing: StyleString.cardSpace,
- crossAxisCount: crossCount,
- mainAxisExtent: cardHeight + 12,
- ),
- delegate: SliverChildBuilderDelegate(
- (BuildContext context, int index) {
- return historyController.histories.isNotEmpty
- ? BangumiHistoryCardV(
- showDelete: showDelete,
- cardHeight: cardHeight,
- historyItem: historyController.histories[index])
- : null;
- },
- childCount: historyController.histories.isNotEmpty
- ? historyController.histories.length
- : 10,
+ const SliverPadding(padding: EdgeInsets.only(top: 4)),
+ SliverPadding(
+ padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
+ sliver: SliverGrid(
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
+ mainAxisSpacing: 2,
+ crossAxisSpacing: StyleString.cardSpace,
+ crossAxisCount: crossCount,
+ mainAxisExtent: 136,
+ ),
+ delegate: SliverChildBuilderDelegate(
+ (BuildContext context, int index) {
+ return BangumiHistoryCardV(
+ historyItem: historyController.histories[index],
+ showDelete: showDelete,
+ onDeleted: () {
+ historyController
+ .deleteHistory(historyController.histories[index]);
+ },
+ );
+ },
+ childCount: historyController.histories.length,
+ ),
),
),
+ const SliverPadding(padding: EdgeInsets.only(bottom: 16)),
],
);
}