mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refactor: popular [wip]
mod: grpc request
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/grpc/app/card/v1/card.pb.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/popup_controller.dart';
|
||||
import 'package:PiliPalaX/http/video.dart';
|
||||
@@ -5,6 +6,8 @@ import 'package:PiliPalaX/http/video.dart';
|
||||
class HotController extends PopupController {
|
||||
final int _count = 20;
|
||||
|
||||
int idx = 0;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -12,8 +15,22 @@ class HotController extends PopupController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => VideoHttp.hotVideoList(
|
||||
pn: currentPage,
|
||||
ps: _count,
|
||||
);
|
||||
Future onRefresh() {
|
||||
idx = 0;
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
// @override
|
||||
// Future<LoadingState> customGetData() => VideoHttp.hotVideoList(
|
||||
// pn: currentPage,
|
||||
// ps: _count,
|
||||
// );
|
||||
|
||||
@override
|
||||
void handleSuccess(List currentList, List dataList) {
|
||||
idx = (dataList.last as Card?)?.smallCoverV5.base.idx.toInt() ?? 0;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => VideoHttp.hotVideoListGrpc(idx: idx);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPalaX/common/widgets/video_card_h_grpc.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -136,7 +137,7 @@ class _HotPageState extends State<HotPage> with AutomaticKeepAliveClientMixin {
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return VideoCardH(
|
||||
return VideoCardHGrpc(
|
||||
videoItem: loadingState.response[index],
|
||||
showPubdate: true,
|
||||
longPress: () {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPalaX/grpc/grpc_client.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
@@ -93,6 +94,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
|
||||
@override
|
||||
void dispose() async {
|
||||
await GrpcClient.instance.shutdown();
|
||||
await GStorage.close();
|
||||
EventBus().off(EventName.loginEvent);
|
||||
super.dispose();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPalaX/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/http/member.dart';
|
||||
import 'package:PiliPalaX/utils/utils.dart';
|
||||
@@ -117,10 +118,7 @@ class VideoIntroController extends GetxController
|
||||
lastPlayCid.value = int.parse(Get.parameters['cid']!);
|
||||
isShowOnlineTotal =
|
||||
setting.get(SettingBoxKey.enableOnlineTotal, defaultValue: true);
|
||||
if (isShowOnlineTotal) {
|
||||
queryOnlineTotal();
|
||||
startTimer(); // 在页面加载时启动定时器
|
||||
}
|
||||
startTimer();
|
||||
queryVideoIntro();
|
||||
}
|
||||
|
||||
@@ -678,23 +676,35 @@ class VideoIntroController extends GetxController
|
||||
}
|
||||
|
||||
void startTimer() {
|
||||
const duration = Duration(seconds: 10); // 设置定时器间隔为10秒
|
||||
timer = Timer.periodic(duration, (Timer timer) {
|
||||
if (!isPaused) {
|
||||
queryOnlineTotal(); // 定时器回调函数,发起请求
|
||||
}
|
||||
});
|
||||
if (isShowOnlineTotal) {
|
||||
queryOnlineTotal();
|
||||
const duration = Duration(seconds: 10); // 设置定时器间隔为10秒
|
||||
timer ??= Timer.periodic(duration, (Timer timer) {
|
||||
if (!isPaused) {
|
||||
queryOnlineTotal(); // 定时器回调函数,发起请求
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void canelTimer() {
|
||||
timer?.cancel();
|
||||
timer = null;
|
||||
}
|
||||
|
||||
// 查看同时在看人数
|
||||
Future queryOnlineTotal() async {
|
||||
var result = await VideoHttp.onlineTotal(
|
||||
// var result = await VideoHttp.onlineTotal(
|
||||
// aid: IdUtils.bv2av(bvid),
|
||||
// bvid: bvid,
|
||||
// cid: lastPlayCid.value,
|
||||
// );
|
||||
dynamic result = await GrpcRepo.playerOnline(
|
||||
aid: IdUtils.bv2av(bvid),
|
||||
bvid: bvid,
|
||||
cid: lastPlayCid.value,
|
||||
);
|
||||
if (result['status']) {
|
||||
total.value = result['data']['total'];
|
||||
total.value = result['data'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:math';
|
||||
|
||||
import 'package:PiliPalaX/common/constants.dart';
|
||||
import 'package:PiliPalaX/common/widgets/list_sheet.dart';
|
||||
import 'package:PiliPalaX/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/models/bangumi/info.dart';
|
||||
import 'package:PiliPalaX/models/common/reply_type.dart';
|
||||
@@ -13,7 +14,6 @@ import 'package:PiliPalaX/pages/video/detail/introduction/widgets/intro_detail.d
|
||||
as video;
|
||||
import 'package:PiliPalaX/pages/video/detail/reply_reply/view.dart';
|
||||
import 'package:PiliPalaX/pages/video/detail/widgets/ai_detail.dart';
|
||||
import 'package:PiliPalaX/grpc/app/playeronline/v1/playeronline.dart';
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:PiliPalaX/utils/id_utils.dart';
|
||||
import 'package:auto_orientation/auto_orientation.dart';
|
||||
@@ -88,8 +88,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
final onlineClient = OnlineClient();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -100,11 +98,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
}
|
||||
videoDetailController = Get.put(VideoDetailController(), tag: heroTag);
|
||||
|
||||
onlineClient.playerOnline(
|
||||
aid: IdUtils.bv2av(videoDetailController.bvid),
|
||||
cid: videoDetailController.cid.value,
|
||||
);
|
||||
|
||||
_videoReplyController = Get.put(
|
||||
VideoReplyController(videoDetailController.oid.value, '0', '1'),
|
||||
tag: heroTag);
|
||||
@@ -288,6 +281,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
PlPlayerController.setPlayCallBack(null);
|
||||
}
|
||||
videoDetailController.positionSubscription?.cancel();
|
||||
videoIntroController.canelTimer();
|
||||
appbarStream.close();
|
||||
floating.dispose();
|
||||
videoDetailController.floating?.dispose();
|
||||
@@ -320,6 +314,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
ScreenBrightness().resetScreenBrightness();
|
||||
|
||||
videoDetailController.positionSubscription?.cancel();
|
||||
videoIntroController.canelTimer();
|
||||
|
||||
videoDetailController.playerStatus =
|
||||
plPlayerController?.playerStatus.status.value;
|
||||
@@ -344,6 +339,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
void didPopNext() async {
|
||||
isShowing = true;
|
||||
PlPlayerController.setPlayCallBack(playCallBack);
|
||||
videoIntroController.startTimer();
|
||||
if (mounted) {
|
||||
if (videoDetailController.brightness != null) {
|
||||
plPlayerController
|
||||
|
||||
Reference in New Issue
Block a user