Skip to content

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

refactor(comments): unify episode and character comment cards

Predidit84eac28f90e6
diff --git a/lib/bean/card/character_comments_card.dart b/lib/bean/card/character_comments_card.dart
deleted file mode 100644
index 3dbc401d..00000000
--- a/lib/bean/card/character_comments_card.dart
+++ /dev/null
@@ -1,139 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:kazumi/bbcode/bbcode_widget.dart';
-import 'package:kazumi/bean/widget/bangumi_avatar.dart';
-import 'package:kazumi/modules/comments/comment_item.dart';
-import 'package:kazumi/utils/date_time.dart';
-
-class CharacterCommentsCard extends StatelessWidget {
- const CharacterCommentsCard({
- super.key,
- required this.commentItem,
- });
-
- final CharacterCommentItem commentItem;
-
- @override
- Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
-
- return Padding(
- padding: const EdgeInsets.only(bottom: 12),
- child: Material(
- color: colorScheme.surfaceContainerLow,
- borderRadius: BorderRadius.circular(24),
- clipBehavior: Clip.antiAlias,
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _CommentAuthor(
- comment: commentItem.comment,
- avatarRadius: 20,
- ),
- const SizedBox(height: 12),
- BBCodeWidget(bbcode: commentItem.comment.comment),
- if (commentItem.replies.isNotEmpty) ...[
- const SizedBox(height: 16),
- _RepliesContainer(replies: commentItem.replies),
- ],
- ],
- ),
- ),
- ),
- );
- }
-}
-
-class _RepliesContainer extends StatelessWidget {
- const _RepliesContainer({required this.replies});
-
- final List<CharacterComment> replies;
-
- @override
- Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
-
- return Container(
- width: double.infinity,
- padding: const EdgeInsets.fromLTRB(14, 4, 14, 12),
- decoration: BoxDecoration(
- color: colorScheme.surfaceContainer,
- borderRadius: BorderRadius.circular(18),
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- for (var index = 0; index < replies.length; index++) ...[
- if (index > 0)
- Divider(
- height: 25,
- color: colorScheme.outlineVariant,
- )
- else
- const SizedBox(height: 8),
- _CommentAuthor(
- comment: replies[index],
- avatarRadius: 16,
- ),
- const SizedBox(height: 8),
- Padding(
- padding: const EdgeInsets.only(left: 40),
- child: BBCodeWidget(bbcode: replies[index].comment),
- ),
- ],
- ],
- ),
- );
- }
-}
-
-class _CommentAuthor extends StatelessWidget {
- const _CommentAuthor({
- required this.comment,
- required this.avatarRadius,
- });
-
- final CharacterComment comment;
- final double avatarRadius;
-
- @override
- Widget build(BuildContext context) {
- final theme = Theme.of(context);
- final colorScheme = theme.colorScheme;
-
- return Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- BangumiAvatar(
- radius: avatarRadius,
- imageUrl: comment.user.avatar.large,
- ),
- const SizedBox(width: 12),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- comment.user.nickname,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: theme.textTheme.titleSmall?.copyWith(
- color: colorScheme.onSurface,
- fontWeight: FontWeight.w600,
- ),
- ),
- const SizedBox(height: 2),
- Text(
- dateFormat(comment.createdAt),
- style: theme.textTheme.labelSmall?.copyWith(
- color: colorScheme.onSurfaceVariant,
- ),
- ),
- ],
- ),
- ),
- ],
- );
- }
-}
diff --git a/lib/bean/card/episode_comments_card.dart b/lib/bean/card/episode_comments_card.dart
deleted file mode 100644
index 5e919429..00000000
--- a/lib/bean/card/episode_comments_card.dart
+++ /dev/null
@@ -1,93 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:kazumi/bbcode/bbcode_widget.dart';
-import 'package:kazumi/bean/widget/bangumi_avatar.dart';
-import 'package:kazumi/modules/comments/comment_item.dart';
-import 'package:kazumi/utils/date_time.dart';
-
-class EpisodeCommentsCard extends StatelessWidget {
- const EpisodeCommentsCard({
- super.key,
- required this.commentItem,
- });
-
- final EpisodeCommentItem commentItem;
-
- @override
- Widget build(BuildContext context) {
- String userComment = commentItem.comment.comment;
- if (userComment.isEmpty) {
- userComment = "<用户已删除>";
- }
-
- return Card(
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- BangumiAvatar(
- imageUrl: commentItem.comment.user.avatar.large,
- ),
- const SizedBox(width: 8),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(commentItem.comment.user.nickname),
- Text(dateFormat(commentItem.comment.createdAt)),
- ],
- ),
- ],
- ),
- const SizedBox(height: 8),
- BBCodeWidget(bbcode: userComment),
- if (commentItem.replies.isNotEmpty)
- ListView.builder(
- // Some OHOS builds inject bottom padding into nested lists.
- padding: const EdgeInsets.only(bottom: 0),
- physics: const NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- itemCount: commentItem.replies.length,
- itemBuilder: (context, index) {
- return Padding(
- padding: const EdgeInsets.only(left: 48),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Divider(
- color: Theme.of(context).dividerColor.withAlpha(60),
- ),
- Row(
- children: [
- BangumiAvatar(
- imageUrl:
- commentItem.replies[index].user.avatar.large,
- ),
- const SizedBox(width: 8),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(commentItem.replies[index].user.nickname),
- Text(
- dateFormat(
- commentItem.replies[index].createdAt),
- ),
- ],
- ),
- ],
- ),
- const SizedBox(height: 8),
- BBCodeWidget(
- bbcode: commentItem.replies[index].comment),
- ],
- ),
- );
- },
- ),
- ],
- ),
- ),
- );
- }
-}
diff --git a/lib/bean/card/user_comments_card.dart b/lib/bean/card/user_comments_card.dart
new file mode 100644
index 00000000..6293ef80
--- /dev/null
+++ b/lib/bean/card/user_comments_card.dart
@@ -0,0 +1,188 @@
+import 'package:flutter/material.dart';
+import 'package:kazumi/bbcode/bbcode_widget.dart';
+import 'package:kazumi/bean/widget/bangumi_avatar.dart';
+import 'package:kazumi/modules/comments/comment_item.dart';
+import 'package:kazumi/utils/date_time.dart';
+
+// 16 and 12 are M3 `large` and a 4dp-grid step; the replies block nested inside
+// takes the concentric radius `outer - padding` so both sets of corners stay
+// parallel.
+const double _cardRadius = 16;
+const double _cardPadding = 12;
+const double _repliesRadius = _cardRadius - _cardPadding;
+
+const double _avatarGap = 12;
+const double _replyAvatarRadius = 16;
+
+/// Renders one Bangumi comment and its replies. Episode and character comments
+/// are distinct models of the same shape, so each gets a constructor.
+class UserCommentsCard extends StatelessWidget {
+ UserCommentsCard.episode(EpisodeCommentItem item, {super.key})
+ : _comment = _fromEpisode(item.comment),
+ _replies = item.replies.map(_fromEpisode).toList();
+
+ UserCommentsCard.character(CharacterCommentItem item, {super.key})
+ : _comment = _fromCharacter(item.comment),
+ _replies = item.replies.map(_fromCharacter).toList();
+
+ final _CommentView _comment;
+ final List<_CommentView> _replies;
+
+ static _CommentView _fromEpisode(EpisodeComment comment) => _CommentView(
+ nickname: comment.user.nickname,
+ avatarUrl: comment.user.avatar.large,
+ createdAt: comment.createdAt,
+ content: comment.comment,
+ );
+
+ static _CommentView _fromCharacter(CharacterComment comment) => _CommentView(
+ nickname: comment.user.nickname,
+ avatarUrl: comment.user.avatar.large,
+ createdAt: comment.createdAt,
+ content: comment.comment,
+ );
+
+ @override
+ Widget build(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsets.only(bottom: 8),
+ child: Material(
+ color: Theme.of(context).colorScheme.surfaceContainerLow,
+ borderRadius: BorderRadius.circular(_cardRadius),
+ clipBehavior: Clip.antiAlias,
+ child: Padding(
+ padding: const EdgeInsets.all(_cardPadding),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _CommentAuthor(comment: _comment, avatarRadius: 20),
+ const SizedBox(height: 8),
+ _CommentBody(content: _comment.content),
+ if (_replies.isNotEmpty) ...[
+ const SizedBox(height: 12),
+ _RepliesContainer(replies: _replies),
+ ],
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _CommentView {
+ const _CommentView({
+ required this.nickname,
+ required this.avatarUrl,
+ required this.createdAt,
+ required this.content,
+ });
+
+ final String nickname;
+ final String avatarUrl;
+ final int createdAt;
+ final String content;
+}
+
+class _RepliesContainer extends StatelessWidget {
+ const _RepliesContainer({required this.replies});
+
+ final List<_CommentView> replies;
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ width: double.infinity,
+ padding: const EdgeInsets.all(_cardPadding),
+ decoration: BoxDecoration(
+ color: Theme.of(context).colorScheme.surfaceContainer,
+ borderRadius: BorderRadius.circular(_repliesRadius),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ for (var index = 0; index < replies.length; index++) ...[
+ if (index > 0) const SizedBox(height: 12),
+ _CommentAuthor(
+ comment: replies[index],
+ avatarRadius: _replyAvatarRadius,
+ ),
+ const SizedBox(height: 6),
+ Padding(
+ padding: const EdgeInsets.only(
+ left: _replyAvatarRadius * 2 + _avatarGap,
+ ),
+ child: _CommentBody(content: replies[index].content),
+ ),
+ ],
+ ],
+ ),
+ );
+ }
+}
+
+class _CommentBody extends StatelessWidget {
+ const _CommentBody({required this.content});
+
+ final String content;
+
+ @override
+ Widget build(BuildContext context) {
+ if (content.isEmpty) {
+ final theme = Theme.of(context);
+ return Text(
+ '该评论已被删除',
+ style: theme.textTheme.bodyMedium?.copyWith(
+ color: theme.colorScheme.onSurfaceVariant,
+ fontStyle: FontStyle.italic,
+ ),
+ );
+ }
+ return BBCodeWidget(bbcode: content);
+ }
+}
+
+class _CommentAuthor extends StatelessWidget {
+ const _CommentAuthor({
+ required this.comment,
+ required this.avatarRadius,
+ });
+
+ final _CommentView comment;
+ final double avatarRadius;
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = Theme.of(context);
+ final colorScheme = theme.colorScheme;
+
+ return Row(
+ children: [
+ BangumiAvatar(radius: avatarRadius, imageUrl: comment.avatarUrl),
+ const SizedBox(width: _avatarGap),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ comment.nickname,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: theme.textTheme.titleSmall?.copyWith(
+ color: colorScheme.onSurface,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ Text(
+ dateFormat(comment.createdAt),
+ style: theme.textTheme.labelSmall?.copyWith(
+ color: colorScheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/pages/info/character_page.dart b/lib/pages/info/character_page.dart
index e2447c23..27cc6b1c 100644
--- a/lib/pages/info/character_page.dart
+++ b/lib/pages/info/character_page.dart
@@ -4,7 +4,7 @@ import 'package:kazumi/modules/character/character_full_item.dart';
import 'package:kazumi/modules/comments/comment_item.dart';
import 'package:kazumi/request/apis/bangumi_api.dart';
import 'package:kazumi/bean/card/network_img_layer.dart';
-import 'package:kazumi/bean/card/character_comments_card.dart';
+import 'package:kazumi/bean/card/user_comments_card.dart';
import 'package:kazumi/bean/dialog/material_bottom_sheet.dart';
import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/bean/widget/image_preview.dart';
@@ -264,7 +264,7 @@ class _CharacterPageState extends State<CharacterPage> {
),
slivers: [
SliverPadding(
- padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
sliver: Builder(builder: (context) {
if (loadingComments) {
return const SliverFillRemaining(
@@ -304,9 +304,7 @@ class _CharacterPageState extends State<CharacterPage> {
keepAlive: true,
child: IndexedSemantics(
index: index,
- child: CharacterCommentsCard(
- commentItem: commentsList[index],
- ),
+ child: UserCommentsCard.character(commentsList[index]),
),
);
},
diff --git a/lib/pages/player/episode_comments_sheet.dart b/lib/pages/player/episode_comments_sheet.dart
index 90e05ab7..0aeeceff 100644
--- a/lib/pages/player/episode_comments_sheet.dart
+++ b/lib/pages/player/episode_comments_sheet.dart
@@ -2,7 +2,7 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
-import 'package:kazumi/bean/card/episode_comments_card.dart';
+import 'package:kazumi/bean/card/user_comments_card.dart';
import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/modules/bangumi/episode_item.dart';
import 'package:kazumi/pages/video/video_controller.dart';
@@ -108,7 +108,7 @@ class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {
),
slivers: [
SliverPadding(
- padding: const EdgeInsets.fromLTRB(4, 0, 4, 4),
+ padding: const EdgeInsets.fromLTRB(12, 8, 12, 8),
sliver: Observer(builder: (context) {
if (commentsQueryTimeout) {
return SliverFillRemaining(
@@ -141,9 +141,8 @@ class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {
keepAlive: true,
child: IndexedSemantics(
index: index,
- child: EpisodeCommentsCard(
- commentItem:
- videoPageController.episodeCommentsList[index],
+ child: UserCommentsCard.episode(
+ videoPageController.episodeCommentsList[index],
),
),
);