mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
53 lines
1.4 KiB
Dart
53 lines
1.4 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();
|
|
currentPage = 0;
|
|
queryData();
|
|
}
|
|
|
|
@override
|
|
Future<LoadingState> customGetData() {
|
|
return appRcmd
|
|
? VideoHttp.rcmdVideoListApp(freshIdx: currentPage)
|
|
: VideoHttp.rcmdVideoList(freshIdx: currentPage, ps: 20);
|
|
}
|
|
|
|
@override
|
|
void handleListResponse(List dataList) {
|
|
if (enableSaveLastData &&
|
|
currentPage == 0 &&
|
|
loadingState.value is Success) {
|
|
List? currentList = (loadingState.value as Success).response;
|
|
if (currentList?.isNotEmpty == true) {
|
|
if (savedRcmdTip) {
|
|
lastRefreshAt = dataList.length;
|
|
}
|
|
if (currentList!.length > 500) {
|
|
currentList.removeRange(50, currentList.length);
|
|
}
|
|
dataList.addAll(currentList);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future onRefresh() async {
|
|
currentPage = 0;
|
|
isEnd = false;
|
|
await queryData();
|
|
}
|
|
}
|