mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
48 lines
1.3 KiB
Dart
48 lines
1.3 KiB
Dart
import 'package:PiliPlus/http/loading_state.dart';
|
|
import 'package:PiliPlus/http/video.dart';
|
|
import 'package:PiliPlus/pages/common/common_controller.dart';
|
|
import 'package:PiliPlus/utils/storage.dart';
|
|
|
|
class RcmdController extends CommonController {
|
|
late bool enableSaveLastData = GStorage.setting
|
|
.get(SettingBoxKey.enableSaveLastData, defaultValue: false);
|
|
late bool appRcmd = true;
|
|
|
|
int? lastRefreshAt;
|
|
late bool savedRcmdTip = GStorage.savedRcmdTip;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
appRcmd = GStorage.appRcmd;
|
|
|
|
currentPage = 0;
|
|
queryData();
|
|
}
|
|
|
|
@override
|
|
Future<LoadingState> customGetData() {
|
|
return appRcmd
|
|
? VideoHttp.rcmdVideoListApp(freshIdx: currentPage)
|
|
: VideoHttp.rcmdVideoList(freshIdx: currentPage, ps: 20);
|
|
}
|
|
|
|
@override
|
|
List? handleListResponse(List currentList, List dataList) {
|
|
bool shouldSaveLast =
|
|
enableSaveLastData && currentPage == 0 && currentList.isNotEmpty;
|
|
if (shouldSaveLast && currentList.length > 500) {
|
|
currentList.removeRange(50, currentList.length);
|
|
}
|
|
lastRefreshAt = shouldSaveLast && savedRcmdTip ? dataList.length : null;
|
|
return shouldSaveLast ? (dataList..addAll(currentList)) : null;
|
|
}
|
|
|
|
@override
|
|
Future onRefresh() async {
|
|
currentPage = 0;
|
|
isEnd = false;
|
|
await queryData();
|
|
}
|
|
}
|