mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refactor: rcmd hot
This commit is contained in:
@@ -1,55 +1,21 @@
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPalaX/http/video.dart';
|
||||
import 'package:PiliPalaX/models/model_hot_video_item.dart';
|
||||
|
||||
class HotController extends GetxController {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
class HotController extends CommonController {
|
||||
final int _count = 20;
|
||||
int _currentPage = 1;
|
||||
RxList<HotVideoItemModel> videoList = <HotVideoItemModel>[].obs;
|
||||
bool isLoadingMore = false;
|
||||
bool flag = false;
|
||||
List<OverlayEntry?> popupDialog = <OverlayEntry?>[];
|
||||
|
||||
// 获取推荐
|
||||
Future queryHotFeed(type) async {
|
||||
if (type != 'onLoad') {
|
||||
_currentPage = 1;
|
||||
}
|
||||
var res = await VideoHttp.hotVideoList(
|
||||
pn: _currentPage,
|
||||
ps: _count,
|
||||
);
|
||||
if (res['status']) {
|
||||
if (type == 'init') {
|
||||
videoList.value = res['data'];
|
||||
} else if (type == 'onRefresh') {
|
||||
// videoList.insertAll(0, res['data']);
|
||||
videoList.value = res['data'];
|
||||
} else if (type == 'onLoad') {
|
||||
videoList.addAll(res['data']);
|
||||
}
|
||||
_currentPage += 1;
|
||||
if (_currentPage == 2) queryHotFeed('onLoad');
|
||||
}
|
||||
isLoadingMore = false;
|
||||
return res;
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
// 下拉刷新
|
||||
Future onRefresh() async {
|
||||
await queryHotFeed('onRefresh');
|
||||
}
|
||||
|
||||
// 上拉加载
|
||||
Future onLoad() async {
|
||||
await queryHotFeed('onLoad');
|
||||
}
|
||||
|
||||
// 返回顶部
|
||||
void animateToTop() {
|
||||
scrollController.animToTop();
|
||||
}
|
||||
@override
|
||||
Future<LoadingState> customGetData() => VideoHttp.hotVideoList(
|
||||
pn: currentPage,
|
||||
ps: _count,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user