mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
58 lines
1.6 KiB
Dart
58 lines
1.6 KiB
Dart
import 'package:PiliPlus/common/widgets/pair.dart';
|
|
import 'package:PiliPlus/http/loading_state.dart';
|
|
import 'package:PiliPlus/pages/common/common_controller.dart';
|
|
import 'package:PiliPlus/http/msg.dart';
|
|
import 'package:PiliPlus/utils/extension.dart';
|
|
import '../../../models/msg/msgfeed_like_me.dart';
|
|
|
|
class LikeMeController extends CommonController {
|
|
int cursor = -1;
|
|
int cursorTime = -1;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
queryData();
|
|
}
|
|
|
|
@override
|
|
bool customHandleResponse(Success response) {
|
|
MsgFeedLikeMe data = response.response;
|
|
if (data.total?.cursor?.isEnd == true ||
|
|
data.total?.items.isNullOrEmpty == true) {
|
|
isEnd = true;
|
|
}
|
|
cursor = data.total?.cursor?.id ?? -1;
|
|
cursorTime = data.total?.cursor?.time ?? -1;
|
|
List<LikeMeItems> latest = <LikeMeItems>[];
|
|
List<LikeMeItems> total = <LikeMeItems>[];
|
|
if (data.latest?.items?.isNotEmpty == true) {
|
|
latest.addAll(data.latest!.items!);
|
|
}
|
|
if (data.total?.items?.isNotEmpty == true) {
|
|
total.addAll(data.total!.items!);
|
|
}
|
|
if (currentPage != 1 && loadingState.value is Success) {
|
|
Pair<List<LikeMeItems>, List<LikeMeItems>> pair =
|
|
(loadingState.value as Success).response;
|
|
latest.insertAll(0, pair.first);
|
|
total.insertAll(0, pair.second);
|
|
}
|
|
loadingState.value = LoadingState.success(
|
|
Pair(first: latest, second: total),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
Future onRefresh() {
|
|
cursor = -1;
|
|
cursorTime = -1;
|
|
return super.onRefresh();
|
|
}
|
|
|
|
@override
|
|
Future<LoadingState> customGetData() =>
|
|
MsgHttp.msgFeedLikeMe(cursor: cursor, cursorTime: cursorTime);
|
|
}
|