Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

基本分集评论支持 #403

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bean/appbar/sys_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SysAppBar extends StatelessWidget implements PreferredSizeWidget {

void _handleCloseEvent() {
SmartDialog.show(
useAnimation: false,
animationTime: const Duration(milliseconds: 100),
builder: (context) {
return AlertDialog(
title: const Text('退出确认'),
Expand Down
78 changes: 78 additions & 0 deletions lib/bean/card/episode_comments_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
import 'package:kazumi/modules/comments/comment_item.dart';
import 'package:kazumi/utils/utils.dart';

class EpisodeCommentsCard extends StatelessWidget {
const EpisodeCommentsCard({
super.key,
required this.commentItem,
});

final EpisodeCommentItem 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),
Text(commentItem.comment.comment),
(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: [
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),
Text(commentItem.replies[index].comment),
]),
);
})
: Container()
]),
),
);
}
}
51 changes: 51 additions & 0 deletions lib/modules/bangumi/episode_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class EpisodeInfo {
int id;
num episode;
int type;
String name;
String nameCn;

EpisodeInfo({
required this.id,
required this.episode,
required this.type,
required this.name,
required this.nameCn,
});

factory EpisodeInfo.fromJson(Map<String, dynamic> json) {
return EpisodeInfo(
id: json['id'] ?? 0,
episode: json['sort'] ?? 0,
type: json['type'] ?? 0,
name: json['name'] ?? '',
nameCn: json['name_cn'] ?? '');
}

factory EpisodeInfo.fromTemplate() {
return EpisodeInfo(id: 0, episode: 0, type: 0, name: '', nameCn: '');
}

void reset() {
id = 0;
episode = 0;
type = 0;
name = '';
nameCn = '';
}

String readType() {
switch (type) {
case 0:
return 'ep';
case 1:
return 'sp';
case 2:
return 'op';
case 3:
return 'ed';
default:
return '';
}
}
}
57 changes: 57 additions & 0 deletions lib/modules/comments/comment_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,60 @@ class CommentItem {
};
}
}

class EpisodeComment {
final User user;
final String comment;
final int createdAt;

EpisodeComment({
required this.user,
required this.comment,
required this.createdAt,
});


factory EpisodeComment.fromJson(Map<String, dynamic> json) {
return EpisodeComment(
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 EpisodeCommentItem {
final EpisodeComment comment;
final List<EpisodeComment> replies;

EpisodeCommentItem({
required this.comment,
required this.replies
});

factory EpisodeCommentItem.fromJson(Map<String, dynamic> json) {
var list = json['replies'] as List;
List<EpisodeComment> tempList =
list.map((i) => EpisodeComment.fromJson(i)).toList();
return EpisodeCommentItem(
comment: EpisodeComment.fromJson(json),
replies: tempList
);
}

Map<String, dynamic> toJson() {
return {
'comment': comment.toJson(),
'list': replies,
};
}
}
28 changes: 28 additions & 0 deletions lib/modules/comments/comment_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,31 @@ class CommentResponse {
};
}
}

class EpisodeCommentResponse {
List<EpisodeCommentItem> commentList;

EpisodeCommentResponse({
required this.commentList,
});

factory EpisodeCommentResponse.fromJson(List<dynamic> json) {
List<EpisodeCommentItem> resCommentList =
json.map((i) => EpisodeCommentItem.fromJson(i)).toList();
return EpisodeCommentResponse(
commentList: resCommentList,
);
}

factory EpisodeCommentResponse.fromTemplate() {
return EpisodeCommentResponse(
commentList: [],
);
}

Map<String, dynamic> toJson() {
return {
'list': commentList,
};
}
}
2 changes: 1 addition & 1 deletion lib/pages/about/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _AboutPageState extends State<AboutPage> {

void _showCacheDialog() {
SmartDialog.show(
useAnimation: false,
animationTime: const Duration(milliseconds: 100),
builder: (context) {
return AlertDialog(
title: const Text('缓存管理'),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/history/history_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _HistoryPageState extends State<HistoryPage>

void showHistoryClearDialog() {
SmartDialog.show(
useAnimation: false,
animationTime: const Duration(milliseconds: 100),
builder: (context) {
return AlertDialog(
title: const Text('记录管理'),
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/info/comments_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {

Widget get commentsListBody {
return Padding(
padding: const EdgeInsets.fromLTRB(4.0, 0, 4.0, 0),
padding: const EdgeInsets.all(4.0),
child: Observer(builder: (context) {
if (infoController.commentsList.isEmpty && !commentsQueryTimeout) {
return const Center(
Expand All @@ -115,7 +115,7 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {

Widget get charactersListBody {
return Padding(
padding: const EdgeInsets.fromLTRB(4.0, 0, 4.0, 0),
padding: const EdgeInsets.fromLTRB(4.0, 4.0, 4.0, 4.0),
child: Observer(builder: (context) {
if (infoController.characterList.isEmpty && !charactersQueryTimeout) {
return const Center(
Expand Down
14 changes: 14 additions & 0 deletions lib/pages/info/info_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import 'package:logger/logger.dart';
import 'package:kazumi/utils/logger.dart';
import 'package:kazumi/modules/comments/comment_item.dart';
import 'package:kazumi/modules/characters/character_item.dart';
import 'package:kazumi/modules/bangumi/episode_item.dart';

part 'info_controller.g.dart';

class InfoController = _InfoController with _$InfoController;

abstract class _InfoController with Store {
late BangumiItem bangumiItem;
EpisodeInfo episodeInfo = EpisodeInfo.fromTemplate();

@observable
var pluginSearchResponseList = ObservableList<PluginSearchResponse>();
Expand All @@ -27,6 +29,9 @@ abstract class _InfoController with Store {
@observable
var commentsList = ObservableList<CommentItem>();

@observable
var episodeCommentsList = ObservableList<EpisodeCommentItem>();

@observable
var characterList = ObservableList<CharacterItem>();

Expand Down Expand Up @@ -88,6 +93,15 @@ abstract class _InfoController with Store {
KazumiLogger().log(Level.info, '已加载评论列表长度 ${commentsList.length}');
}

queryBangumiEpisodeCommentsByID(int id, int episode) async {
episodeCommentsList.clear();
episodeInfo = await BangumiHTTP.getBangumiEpisodeByID(id, episode);
await BangumiHTTP.getBangumiCommentsByEpisodeID(episodeInfo.id).then((value) {
episodeCommentsList.addAll(value.commentList);
});
KazumiLogger().log(Level.info, '已加载评论列表长度 ${episodeCommentsList.length}');
}

queryBangumiCharactersByID(int id) async {
characterList.clear();
await BangumiHTTP.getCharatersByID(id).then((value) {
Expand Down
8 changes: 7 additions & 1 deletion lib/pages/info/info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:kazumi/pages/popular/popular_controller.dart';
import 'package:kazumi/bean/card/network_img_layer.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
import 'package:kazumi/request/query_manager.dart';
import 'package:kazumi/utils/utils.dart';
import 'package:logger/logger.dart';
import 'package:kazumi/utils/logger.dart';
import 'package:kazumi/pages/info/comments_sheet.dart';
Expand Down Expand Up @@ -190,7 +191,12 @@ class _InfoPageState extends State<InfoPage>
child: const Icon(Icons.comment),
onPressed: () async {
showModalBottomSheet(
// elevation: 10,
isScrollControlled: true,
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 3 / 4,
maxWidth: (Utils.isDesktop() || Utils.isTablet())
? MediaQuery.of(context).size.width * 9 / 16
: MediaQuery.of(context).size.width),
clipBehavior: Clip.antiAlias,
context: context,
builder: (context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/init_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class _InitPageState extends State<InitPage> {
} catch (_) {}
if (pluginsController.pluginList.isEmpty) {
SmartDialog.show(
useAnimation: false,
animationTime: const Duration(milliseconds: 100),
backType: SmartBackType.ignore,
clickMaskDismiss: false,
builder: (context) {
Expand Down
1 change: 1 addition & 0 deletions lib/pages/my/my_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MyController {
}
} else {
SmartDialog.show(
animationTime: const Duration(milliseconds: 100),
animationType: SmartAnimationType.centerFade_otherSlide,
builder: (context) {
return AlertDialog(
Expand Down
Loading