mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-16 07:06:14 +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']);
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:PiliPlus/common/widgets/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_at_me.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -35,20 +36,20 @@ class _AtMePageState extends State<AtMePage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<AtMeItems>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => loadingWidget,
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? ListView.separated(
|
||||
itemCount: loadingState.response.length,
|
||||
itemCount: loadingState.response!.length,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80),
|
||||
itemBuilder: (context, int index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_atMeController.onLoadMore();
|
||||
}
|
||||
final item = loadingState.response[index];
|
||||
final item = loadingState.response![index];
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
String? nativeUri = item.item?.nativeUri;
|
||||
@@ -103,10 +104,9 @@ class _AtMePageState extends State<AtMePage> {
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if ((item.item?.sourceContent as String?)?.isNotEmpty ==
|
||||
true) ...[
|
||||
if (item.item?.sourceContent?.isNotEmpty == true) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(item.item?.sourceContent,
|
||||
Text(item.item!.sourceContent!,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context)
|
||||
|
||||
Reference in New Issue
Block a user