mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-18 08:06:21 +08:00
feat: like live room
Closes #963 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -24,6 +24,7 @@ import 'package:canvas_danmaku/canvas_danmaku.dart';
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class LiveRoomController extends GetxController {
|
||||
@@ -256,6 +257,7 @@ class LiveRoomController extends GetxController {
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
cancelLikeTimer();
|
||||
cancelLiveTimer();
|
||||
savedDanmaku?.clear();
|
||||
savedDanmaku = null;
|
||||
@@ -330,4 +332,43 @@ class LiveRoomController extends GetxController {
|
||||
})
|
||||
..init();
|
||||
}
|
||||
|
||||
final RxInt likeClickTime = 0.obs;
|
||||
Timer? likeClickTimer;
|
||||
|
||||
void cancelLikeTimer() {
|
||||
likeClickTimer?.cancel();
|
||||
likeClickTimer = null;
|
||||
}
|
||||
|
||||
void onLikeTapDown([_]) {
|
||||
cancelLikeTimer();
|
||||
likeClickTime.value++;
|
||||
}
|
||||
|
||||
void onLikeTapUp([_]) {
|
||||
likeClickTimer ??= Timer(
|
||||
const Duration(milliseconds: 800),
|
||||
onLike,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> onLike() async {
|
||||
if (!Accounts.heartbeat.isLogin) {
|
||||
likeClickTime.value = 0;
|
||||
return;
|
||||
}
|
||||
var res = await LiveHttp.liveLikeReport(
|
||||
clickTime: likeClickTime.value,
|
||||
roomId: roomId,
|
||||
uid: accountService.mid,
|
||||
anchorId: roomInfoH5.value?.roomInfo?.uid,
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast('点赞成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
likeClickTime.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user