mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: query data (#659)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_at_me.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
class AtMeController extends CommonController {
|
||||
class AtMeController extends CommonListController<MsgFeedAtMe, AtMeItems> {
|
||||
int cursor = -1;
|
||||
int cursorTime = -1;
|
||||
|
||||
@@ -16,19 +15,19 @@ class AtMeController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
List<AtMeItems>? getDataList(MsgFeedAtMe response) {
|
||||
return response.items;
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success<MsgFeedAtMe> response) {
|
||||
MsgFeedAtMe data = response.response;
|
||||
if (data.cursor?.isEnd == true || data.items.isNullOrEmpty) {
|
||||
if (data.cursor?.isEnd == true) {
|
||||
isEnd = true;
|
||||
}
|
||||
cursor = data.cursor?.id ?? -1;
|
||||
cursorTime = data.cursor?.time ?? -1;
|
||||
if (currentPage != 1 && loadingState.value is Success) {
|
||||
data.items ??= <AtMeItems>[];
|
||||
data.items!.insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
loadingState.value = LoadingState.success(data.items);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -39,16 +38,16 @@ class AtMeController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
Future<LoadingState<MsgFeedAtMe>> customGetData() =>
|
||||
MsgHttp.msgFeedAtMe(cursor: cursor, cursorTime: cursorTime);
|
||||
|
||||
Future onRemove(dynamic id, int index) async {
|
||||
try {
|
||||
var res = await MsgHttp.delMsgfeed(2, id);
|
||||
if (res['status']) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
List<AtMeItems> list = (loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('删除成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
|
||||
Reference in New Issue
Block a user