基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
add character comments
Predidit5151eb324911
diff --git a/lib/bean/card/character_comments_card.dart b/lib/bean/card/character_comments_card.dartnew file mode 100644index 00000000..fa1872f2--- /dev/null+++ b/lib/bean/card/character_comments_card.dart@@ -0,0 +1,87 @@+import 'package:flutter/material.dart';+import 'package:kazumi/bbcode/bbcode_widget.dart';+import 'package:kazumi/modules/comments/comment_item.dart';+import 'package:kazumi/utils/utils.dart';++class CharacterCommentsCard extends StatelessWidget {+ const CharacterCommentsCard({+ super.key,+ required this.commentItem,+ });++ final CharacterCommentItem commentItem;++ @override+ Widget build(BuildContext context) {+ return Card(+ color: Theme.of(context).colorScheme.secondaryContainer,+ child: Padding(+ padding: const EdgeInsets.all(8.0),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Row(+ children: [+ CircleAvatar(+ backgroundImage:+ NetworkImage(commentItem.comment.user.avatar.large),+ ),+ const SizedBox(width: 8),+ Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(commentItem.comment.user.nickname),+ Text(Utils.dateFormat(commentItem.comment.createdAt)),+ ],+ ),+ ],+ ),+ const SizedBox(height: 8),+ BBCodeWidget(bbcode: commentItem.comment.comment),+ if (commentItem.replies.isNotEmpty)+ ListView.builder(+ 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: [+ CircleAvatar(+ backgroundImage: NetworkImage(+ commentItem.replies[index].user.avatar.large),+ ),+ const SizedBox(width: 8),+ Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(commentItem.replies[index].user.nickname),+ Text(+ Utils.dateFormat(+ commentItem.replies[index].createdAt),+ ),+ ],+ ),+ ],+ ),+ const SizedBox(height: 8),+ BBCodeWidget(+ bbcode: commentItem.replies[index].comment),+ ],+ ),+ );+ },+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/lib/modules/comments/comment_item.dart b/lib/modules/comments/comment_item.dartindex 0fd787b7..90665496 100644--- a/lib/modules/comments/comment_item.dart+++ b/lib/modules/comments/comment_item.dart@@ -176,3 +176,60 @@ class EpisodeCommentItem {};}}++class CharacterComment {+ final User user;+ final String comment;+ final int createdAt;++ CharacterComment({+ required this.user,+ required this.comment,+ required this.createdAt,+ });+++ factory CharacterComment.fromJson(Map<String, dynamic> json) {+ return CharacterComment(+ user: User.fromJson(json['user']),+ comment: json['content'] ?? '',+ createdAt: json['createdAt'] ?? 0,+ );+ }+++ Map<String, dynamic> toJson() {+ return {+ 'user': user.toJson(),+ 'content': comment,+ 'createdAt': createdAt,+ };+ }+}++class CharacterCommentItem {+ final CharacterComment comment;+ final List<CharacterComment> replies;++ CharacterCommentItem({+ required this.comment,+ required this.replies+ });++ factory CharacterCommentItem.fromJson(Map<String, dynamic> json) {+ var list = json['replies'] as List;+ List<CharacterComment> tempList =+ list.map((i) => CharacterComment.fromJson(i)).toList();+ return CharacterCommentItem(+ comment: CharacterComment.fromJson(json),+ replies: tempList+ );+ }++ Map<String, dynamic> toJson() {+ return {+ 'comment': comment.toJson(),+ 'list': replies,+ };+ }+}diff --git a/lib/modules/comments/comment_response.dart b/lib/modules/comments/comment_response.dartindex 5decc678..54fdb48e 100644--- a/lib/modules/comments/comment_response.dart+++ b/lib/modules/comments/comment_response.dart@@ -61,3 +61,31 @@ class EpisodeCommentResponse {};}}++class CharacterCommentResponse {+ List<CharacterCommentItem> commentList;++ CharacterCommentResponse({+ required this.commentList,+ });++ factory CharacterCommentResponse.fromJson(List<dynamic> json) {+ List<CharacterCommentItem>? resCommentList =+ (json as List?)?.map((i) => CharacterCommentItem.fromJson(i)).toList();+ return CharacterCommentResponse(+ commentList: resCommentList ?? <CharacterCommentItem>[],+ );+ }++ factory CharacterCommentResponse.fromTemplate() {+ return CharacterCommentResponse(+ commentList: [],+ );+ }++ Map<String, dynamic> toJson() {+ return {+ 'list': commentList,+ };+ }+}diff --git a/lib/pages/info/character_page.dart b/lib/pages/info/character_page.dartindex 4f537237..d0f025ad 100644--- a/lib/pages/info/character_page.dart+++ b/lib/pages/info/character_page.dart@@ -1,7 +1,10 @@+import 'dart:ui';import 'package:flutter/material.dart';import 'package:kazumi/modules/character/character_full_item.dart';+import 'package:kazumi/modules/comments/comment_item.dart';import 'package:kazumi/request/bangumi.dart';import 'package:kazumi/bean/card/network_img_layer.dart';+import 'package:kazumi/bean/card/character_comments_card.dart';class CharacterPage extends StatefulWidget {const CharacterPage({super.key, required this.characterID});@@ -15,6 +18,8 @@ class CharacterPage extends StatefulWidget {class _CharacterPageState extends State<CharacterPage> {late CharacterFullItem characterFullItem;bool loadingCharacter = true;+ List<CharacterCommentItem> commentsList = [];+ bool loadingComments = true;Future<void> loadCharacter() async {setState(() {@@ -29,11 +34,25 @@ class _CharacterPageState extends State<CharacterPage> {});}+ Future<void> loadComments() async {+ setState(() {+ loadingComments = true;+ });+ await BangumiHTTP.getCharacterCommentsByCharacterID(widget.characterID)+ .then((value) {+ commentsList = value.commentList;+ });+ setState(() {+ loadingComments = false;+ });+ }+@overridevoid initState() {super.initState();WidgetsBinding.instance.addPostFrameCallback((_) {loadCharacter();+ loadComments();});}@@ -181,8 +200,60 @@ class _CharacterPageState extends State<CharacterPage> {}Widget get characterCommentsBody {- return const Center(- child: Text('施工中'),+ return CustomScrollView(+ scrollBehavior: const ScrollBehavior().copyWith(+ // Scrollbars' movement is not linear so hide it.+ scrollbars: false,+ // Enable mouse drag to refresh+ dragDevices: {+ PointerDeviceKind.mouse,+ PointerDeviceKind.touch,+ },+ ),+ slivers: [+ SliverPadding(+ padding: const EdgeInsets.fromLTRB(4, 0, 4, 4),+ sliver: Builder(builder: (context) {+ if (loadingComments) {+ return const SliverFillRemaining(+ child: Center(+ child: CircularProgressIndicator(),+ ),+ );+ }+ if (commentsList.isEmpty) {+ return const SliverFillRemaining(+ child: Center(+ child: Text('空空如也'),+ ),+ );+ }+ return SliverList(+ delegate: SliverChildBuilderDelegate(+ (context, index) {+ // Fix scroll issue caused by height change of network images+ // by keeping loaded cards alive.+ return KeepAlive(+ keepAlive: true,+ child: IndexedSemantics(+ index: index,+ child: SelectionArea(+ child: CharacterCommentsCard(+ commentItem: commentsList[index],+ ),+ ),+ ),+ );+ },+ childCount: commentsList.length,+ addAutomaticKeepAlives: false,+ addRepaintBoundaries: false,+ addSemanticIndexes: false,+ ),+ );+ }),+ ),+ ],);}}diff --git a/lib/pages/info/comments_sheet.dart b/lib/pages/info/comments_sheet.dartindex 973f0565..a0c2b406 100644--- a/lib/pages/info/comments_sheet.dart+++ b/lib/pages/info/comments_sheet.dart@@ -126,7 +126,7 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {Widget get commentsListBody {return SelectionArea(child: Padding(- padding: const EdgeInsets.all(4.0),+ padding: const EdgeInsets.fromLTRB(4.0, 4.0, 4.0, 0.0),child: Observer(builder: (context) {if (infoController.commentsList.isEmpty && !commentsQueryTimeout) {return const Center(diff --git a/lib/request/api.dart b/lib/request/api.dartindex 83817533..9154b0eb 100644--- a/lib/request/api.dart+++ b/lib/request/api.dart@@ -31,6 +31,7 @@ class Api {static const String bangumiInfoByIDNext = 'https://next.bgm.tv/p1/subjects/';static const String characterInfoByCharacterIDNext = 'https://next.bgm.tv/p1/characters/{0}';static const String bangumiEpisodeByIDNext = 'https://next.bgm.tv/p1/episodes/';+ static const String bangumiCharacterByIDNext = 'https://next.bgm.tv/p1/characters/';// 弹弹Playstatic const String dandanIndex = 'https://www.dandanplay.com/';static const String dandanAPIDomain = 'https://api.dandanplay.net';diff --git a/lib/request/bangumi.dart b/lib/request/bangumi.dartindex 2d2463b0..3908ba70 100644--- a/lib/request/bangumi.dart+++ b/lib/request/bangumi.dart@@ -268,6 +268,23 @@ class BangumiHTTP {return commentResponse;}+ static Future<CharacterCommentResponse> getCharacterCommentsByCharacterID(+ int id) async {+ CharacterCommentResponse commentResponse =+ CharacterCommentResponse.fromTemplate();+ try {+ final res = await Request().get(+ '${Api.bangumiCharacterByIDNext}$id/comments',+ options: Options(headers: bangumiHTTPHeader));+ final jsonData = res.data;+ commentResponse = CharacterCommentResponse.fromJson(jsonData);+ } catch (e) {+ KazumiLogger().log(Level.error,+ 'Resolve bangumi character comments failed ${e.toString()}');+ }+ return commentResponse;+ }+static Future<CharactersResponse> getCharatersByBangumiID(int id) async {CharactersResponse charactersResponse = CharactersResponse.fromTemplate();try {