mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 03:06:59 +08:00
52 lines
1.3 KiB
Dart
52 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_pref.dart';
|
|
|
|
class RcmdController extends CommonListController {
|
|
late bool enableSaveLastData = Pref.enableSaveLastData;
|
|
final bool appRcmd = Pref.appRcmd;
|
|
|
|
int? lastRefreshAt;
|
|
late bool savedRcmdTip = Pref.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) {
|
|
if (loadingState.value case Success(:final response)) {
|
|
if (response != null && response.isNotEmpty) {
|
|
if (savedRcmdTip) {
|
|
lastRefreshAt = dataList.length;
|
|
}
|
|
if (response.length > 200) {
|
|
dataList.addAll(response.take(50));
|
|
} else {
|
|
dataList.addAll(response);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> onRefresh() {
|
|
page = 0;
|
|
isEnd = false;
|
|
return queryData();
|
|
}
|
|
}
|