Skip to content

Commit

Permalink
feat(comment): finish CommentPage and update version
Browse files Browse the repository at this point in the history
  • Loading branch information
Aoi-hosizora committed Jan 3, 2021
1 parent 66cb89e commit 75ed87e
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 29 deletions.
7 changes: 5 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ android {
applicationId "com.aoihosizora.manhuagui"
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// versionCode flutterVersionCode.toInteger()
// versionName flutterVersionName

versionCode 3
versionName "1.0.2"
}

signingConfigs {
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:label="manhuagui"
android:label="Manhuagui"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">

Expand Down
4 changes: 4 additions & 0 deletions lib/model/comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Comment {
Map<String, dynamic> toJson() => _$CommentToJson(this);

static const fields = <String>['cid', 'uid', 'username', 'avatar', 'gender', 'content', 'like_count', 'reply_count', 'comment_time', 'reply_timeline'];

RepliedComment toRepliedComment() {
return RepliedComment(cid: cid, uid: uid, username: username, avatar: avatar, gender: gender, content: content, likeCount: likeCount, replyCount: replyCount, commentTime: commentTime);
}
}

@JsonSerializable(fieldRename: FieldRename.snake)
Expand Down
26 changes: 3 additions & 23 deletions lib/model/manga.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Manga {
List<Category> genres;
List<TinyAuthor> authors;
String alias;
String aliasTitle;
bool finished;
String newestChapter;
String newestDate;
Expand All @@ -30,34 +31,13 @@ class Manga {
bool copyright;
List<MangaChapterGroup> chapterGroups;

Manga(
{this.mid,
this.title,
this.cover,
this.url,
this.publishYear,
this.mangaZone,
this.genres,
this.authors,
this.alias,
this.finished,
this.newestChapter,
this.newestDate,
this.briefIntroduction,
this.introduction,
this.mangaRank,
this.averageScore,
this.scoreCount,
this.perScores,
this.banned,
this.copyright,
this.chapterGroups});
Manga({this.mid, this.title, this.cover, this.url, this.publishYear, this.mangaZone, this.genres, this.authors, this.alias, this.aliasTitle, this.finished, this.newestChapter, this.newestDate, this.briefIntroduction, this.introduction, this.mangaRank, this.averageScore, this.scoreCount, this.perScores, this.banned, this.copyright, this.chapterGroups});

factory Manga.fromJson(Map<String, dynamic> json) => _$MangaFromJson(json);

Map<String, dynamic> toJson() => _$MangaToJson(this);

static const fields = <String>['mid', 'title', 'cover', 'url', 'publish_year', 'manga_zone', 'genres', 'authors', 'alias', 'finished', 'newest_chapter', 'newest_date', 'brief_introduction', 'introduction', 'manga_rank', 'average_score', 'score_count', 'per_scores', 'banned', 'copyright', 'chapter_groups'];
static const fields = <String>['mid', 'title', 'cover', 'url', 'publish_year', 'manga_zone', 'genres', 'authors', 'alias', 'alias_title', 'finished', 'newest_chapter', 'newest_date', 'brief_introduction', 'introduction', 'manga_rank', 'average_score', 'score_count', 'per_scores', 'banned', 'copyright', 'chapter_groups'];
}

@JsonSerializable(fieldRename: FieldRename.snake)
Expand Down
210 changes: 210 additions & 0 deletions lib/page/comment.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import 'package:flutter/material.dart';
import 'package:manhuagui_flutter/model/comment.dart';
import 'package:manhuagui_flutter/page/view/network_image.dart';
import 'package:manhuagui_flutter/service/natives/clipboard.dart';

/// 评论详情页
class CommentPage extends StatefulWidget {
const CommentPage({
Key key,
@required this.comment,
}) : assert(comment != null),
super(key: key);

final Comment comment;

@override
_CommentPageState createState() => _CommentPageState();
}

class _CommentPageState extends State<CommentPage> {
Widget _buildLine({@required RepliedComment comment, @required int idx}) {
assert(comment != null);
assert(idx != null);
return Stack(
children: [
Container(
color: Colors.white,
padding: EdgeInsets.only(top: 15, bottom: 15, left: 15, right: 15),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipOval(
child: NetworkImageView(
url: comment.avatar,
height: 40,
width: 40,
fit: BoxFit.cover,
),
),
SizedBox(width: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// ****************************************************************
// 第一行
// ****************************************************************
Container(
width: MediaQuery.of(context).size.width - 3 * 15 - 40, // | ▢▢ ▢▢▢▢▢ |
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// ****************************************************************
// 用户名 性别
// ****************************************************************
Expanded(
child: Row(
children: [
Flexible(
child: Text(
comment.username == '-' ? '匿名用户' : comment.username,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.subtitle1,
),
),
SizedBox(width: 8),
Container(
decoration: BoxDecoration(
color: comment.gender == 1 ? Colors.blue[300] : Colors.red[400],
borderRadius: BorderRadius.all(Radius.circular(3)),
),
height: 18,
width: 18,
child: Center(
child: Text(
widget.comment.gender == 1 ? '♂' : '♀',
style: TextStyle(fontSize: 14, color: Colors.white),
),
),
),
],
),
),
// ****************************************************************
// 楼层
// ****************************************************************
Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.all(Radius.circular(3)),
),
height: 18,
width: 26,
child: Center(
child: Text(
'#$idx',
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
),
),
),
],
),
),
SizedBox(height: 15),
// ****************************************************************
// 评论内容
// ****************************************************************
Container(
width: MediaQuery.of(context).size.width - 3 * 15 - 40,
child: Text(
comment.content,
style: Theme.of(context).textTheme.subtitle1,
),
),
SizedBox(height: 15),
// ****************************************************************
// 评论数据
// ****************************************************************
Container(
width: MediaQuery.of(context).size.width - 3 * 15 - 40,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
comment.commentTime,
style: TextStyle(color: Colors.grey),
),
Row(
children: [
Icon(
Icons.thumb_up,
color: Colors.grey[400],
size: 16,
),
SizedBox(width: 4),
Text(comment.likeCount.toString()),
SizedBox(width: 10),
Icon(
Icons.chat_bubble,
color: Colors.grey[400],
size: 16,
),
SizedBox(width: 4),
Text(comment.replyCount.toString()),
],
),
],
),
),
],
),
],
),
),
Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () => copyText(comment.content),
),
),
),
],
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
toolbarHeight: 45,
title: Text('评论详情'),
),
body: Container(
width: MediaQuery.of(context).size.width,
child: ListView(
children: [
_buildLine(
comment: widget.comment.toRepliedComment(),
idx: widget.comment.replyTimeline.length + 1,
),
Container(height: 12),
if (widget.comment.replyTimeline.length > 0)
for (var i = 0; i < widget.comment.replyTimeline.length - 1; i++) ...[
_buildLine(
comment: widget.comment.replyTimeline[i],
idx: i + 1,
),
Container(
color: Colors.white,
padding: EdgeInsets.only(left: 2.0 * 15 + 40),
width: MediaQuery.of(context).size.width - 3 * 15 - 40,
child: Divider(height: 1, thickness: 1),
),
],
if (widget.comment.replyTimeline.length > 0)
_buildLine(
comment: widget.comment.replyTimeline.last,
idx: widget.comment.replyTimeline.length,
),
],
),
),
);
}
}
10 changes: 10 additions & 0 deletions lib/page/manga.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ class _MangaPageState extends State<MangaPage> {
chapterPage: 0,
),
).catchError((_) {});
} else {
updateHistory(
username: AuthState.instance.username,
history: MangaHistory(
mangaId: _data.mid,
mangaTitle: _data.title ?? '?',
mangaCover: _data.cover ?? '?',
mangaUrl: _data.url ?? '',
),
);
}
}).catchError((e) {
_data = null;
Expand Down
Loading

0 comments on commit 75ed87e

Please sign in to comment.