Files
PiliPlus/lib/pages/rcmd/controller.dart
bggRGjQaUbCoE 924d51d41b opt handle res
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
2025-05-29 17:17:42 +08:00

51 lines
1.3 KiB
Dart

import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/video.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:PiliPlus/utils/storage.dart';
class RcmdController extends CommonListController {
late bool enableSaveLastData = GStorage.setting
.get(SettingBoxKey.enableSaveLastData, defaultValue: false);
final bool appRcmd = GStorage.appRcmd;
int? lastRefreshAt;
late bool savedRcmdTip = GStorage.savedRcmdTip;
@override
void onInit() {
super.onInit();
page = 0;
queryData();
}
@override
Future<LoadingState> customGetData() {
return appRcmd
? VideoHttp.rcmdVideoListApp(freshIdx: page)
: VideoHttp.rcmdVideoList(freshIdx: page, ps: 20);
}
@override
void handleListResponse(List dataList) {
if (enableSaveLastData && page == 0 && loadingState.value.isSuccess) {
List? currentList = loadingState.value.data;
if (currentList?.isNotEmpty == true) {
if (savedRcmdTip) {
lastRefreshAt = dataList.length;
}
if (currentList!.length > 500) {
currentList.removeRange(50, currentList.length);
}
dataList.addAll(currentList);
}
}
}
@override
Future<void> onRefresh() {
page = 0;
isEnd = false;
return queryData();
}
}