Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
feat: 添加评论点赞
Browse files Browse the repository at this point in the history
  • Loading branch information
lucinhu committed Mar 24, 2023
1 parent 0a3ff50 commit 4eeb459
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 205 deletions.
18 changes: 18 additions & 0 deletions lib/common/api/api_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,22 @@ class ApiConstants {

///判断视频是否已经点赞
static const String hasLike = "$apiBase/x/web-interface/archive/has/like";

///投币
static const String addCoin = "$apiBase/x/web-interface/coin/add";

///判断是否被投币
static const String hasAddCoin = "$apiBase/x/web-interface/archive/coins";

///收藏
static const String addFavourite = "$apiBase/x/v3/fav/resource/deal";

///判断是否已收藏
static const String hasFavourite = "$apiBase/x/v2/fav/video/favoured";

///分享视频
static const String share = "$apiBase/x/web-interface/share/add";

///评论点赞
static const String replyAddLike = "$apiBase/x/v2/reply/action";
}
2 changes: 1 addition & 1 deletion lib/common/api/reply_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ReplyApi {
replyTime: raw.ctime ?? 0,
preReplies: preReplies,
likeCount: raw.like ?? 0,
isLike: raw.action == 1 ? true : false,
hasLike: raw.action == 1 ? true : false,
location: raw.replyControl?.location ?? "",
content: ReplyContent(
message: raw.content?.message ?? "",
Expand Down
25 changes: 25 additions & 0 deletions lib/common/api/reply_operation_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:bili_you/common/api/index.dart';
import 'package:bili_you/common/models/local/reply/reply_add_like_result.dart';
import 'package:bili_you/common/models/local/reply/reply_item.dart';
import 'package:bili_you/common/utils/cookie_util.dart';
import 'package:bili_you/common/utils/index.dart';

class ReplyOperationApi {
static Future<ReplyAddLikeResult> addLike(
{required ReplyType type,
required int oid,
required int rpid,
required bool likeOrUnlike}) async {
var response =
await MyDio.dio.post(ApiConstants.replyAddLike, queryParameters: {
'type': type.code,
'oid': oid,
'rpid': rpid,
'action': likeOrUnlike ? 1 : 0,
'csrf': await CookieUtils.getCsrf()
});
return ReplyAddLikeResult(
isSuccess: response.data?['code'] == 0,
error: response.data?['message'] ?? '');
}
}
7 changes: 7 additions & 0 deletions lib/common/models/local/reply/reply_add_like_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ReplyAddLikeResult {
ReplyAddLikeResult({required this.isSuccess, required this.error});
static ReplyAddLikeResult get zero =>
ReplyAddLikeResult(isSuccess: false, error: '');
bool isSuccess;
String error;
}
6 changes: 3 additions & 3 deletions lib/common/models/local/reply/reply_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReplyItem {
required this.replyTime,
required this.preReplies,
required this.likeCount,
required this.isLike,
required this.hasLike,
required this.location,
required this.content,
required this.tags});
Expand All @@ -31,7 +31,7 @@ class ReplyItem {
replyTime: 0,
preReplies: [],
likeCount: 0,
isLike: false,
hasLike: false,
location: "",
content: ReplyContent.zero,
tags: []);
Expand Down Expand Up @@ -78,7 +78,7 @@ class ReplyItem {
int likeCount;

///是否已点赞
bool isLike;
bool hasLike;

///评论内容
ReplyContent content;
Expand Down
65 changes: 3 additions & 62 deletions lib/pages/bili_video/widgets/reply/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import 'package:bili_you/common/models/local/reply/reply_info.dart';
import 'package:bili_you/common/models/local/reply/reply_item.dart';
import 'package:bili_you/common/utils/string_format_utils.dart';
import 'package:bili_you/common/values/cache_keys.dart';
import 'package:bili_you/pages/user_space/view.dart';
import 'package:easy_refresh/easy_refresh.dart';

import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:get/get.dart';
import 'package:bili_you/pages/bili_video/widgets/reply/widgets/reply_item.dart';
import 'package:bili_you/pages/bili_video/widgets/reply/widgets/reply_reply_page.dart';

class ReplyController extends GetxController {
ReplyController({required this.bvid, required this.pauseVideoCallback});
Expand Down Expand Up @@ -46,76 +44,19 @@ class ReplyController extends GetxController {
//添加评论条目到控件列表
addReplyItemWidget(List<Widget> list, ReplyInfo replyInfo, ReplyItem i,
{bool frontDivider = true, bool isTop = false}) {
Widget? subReplies;
if (frontDivider) {
list.add(Divider(
color: Theme.of(Get.context!).colorScheme.secondaryContainer,
thickness: 1,
));
}
if (i.preReplies.isNotEmpty) {
List<Widget> preSubReplies = []; //预显示在外的楼中楼
for (var j in i.preReplies) {
//添加预显示在外楼中楼评论条目
preSubReplies.add(Padding(
padding: const EdgeInsets.only(top: 8),
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: "${j.member.name}: ",
),
ReplyItemWidget.buildReplyItemContent(j.content)
],
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
)));
}
//预显示在外楼中楼控件
subReplies = Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Theme.of(Get.context!).colorScheme.surfaceVariant),
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
child: GestureDetector(
child: ListView(
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: preSubReplies,
),
onTap: () {
//楼中楼点击后弹出详细楼中楼
Get.bottomSheet(
ReplyReplyPage(
bvid: i.oid.toString(),
rootId: i.rpid,
pauseVideoCallback: pauseVideoCallback,
),
backgroundColor: Theme.of(Get.context!).cardColor,
clipBehavior: Clip.antiAlias);
},
));
}

//添加评论条目
list.add(ReplyItemWidget(
face: i.member.avatarUrl,
name: i.member.name,
content: i.content,
like: i.likeCount,
timeStamp: i.replyTime,
bottomWidget: subReplies,
location: i.location,
reply: i,
isTop: isTop,
tags: i.tags,
isUp: i.member.mid == replyInfo.upperMid,
onTapUser: (context) {
pauseVideoCallback();
Get.to(
() => UserSpacePage(mid: i.member.mid),
);
},
pauseVideoPlayer: pauseVideoCallback,
));
}

Expand Down
Loading

0 comments on commit 4eeb459

Please sign in to comment.