mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-22 03:31:09 +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)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
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/pages/common/common_data_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_like_me.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
class LikeMeController extends CommonController {
|
||||
class LikeMeController extends CommonDataController<MsgFeedLikeMe, dynamic> {
|
||||
int cursor = -1;
|
||||
int cursorTime = -1;
|
||||
|
||||
@@ -17,7 +17,7 @@ class LikeMeController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
bool customHandleResponse(bool isRefresh, Success<MsgFeedLikeMe> response) {
|
||||
MsgFeedLikeMe data = response.response;
|
||||
if (data.total?.cursor?.isEnd == true ||
|
||||
data.total?.items.isNullOrEmpty == true) {
|
||||
@@ -46,7 +46,7 @@ class LikeMeController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
Future<LoadingState<MsgFeedLikeMe>> customGetData() =>
|
||||
MsgHttp.msgFeedLikeMe(cursor: cursor, cursorTime: cursorTime);
|
||||
|
||||
Future onRemove(dynamic id, int index, bool isLatest) async {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
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_reply_me.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
class ReplyMeController extends CommonController {
|
||||
class ReplyMeController
|
||||
extends CommonListController<MsgFeedReplyMe, ReplyMeItems> {
|
||||
int cursor = -1;
|
||||
int cursorTime = -1;
|
||||
|
||||
@@ -16,19 +16,19 @@ class ReplyMeController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
MsgFeedReplyMe data = response.response;
|
||||
if (data.cursor?.isEnd == true || data.items.isNullOrEmpty) {
|
||||
List<ReplyMeItems>? getDataList(MsgFeedReplyMe response) {
|
||||
return response.items;
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success<MsgFeedReplyMe> response) {
|
||||
final data = response.response;
|
||||
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 ??= <ReplyMeItems>[];
|
||||
data.items!.insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
loadingState.value = LoadingState.success(data.items);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -39,16 +39,16 @@ class ReplyMeController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
Future<LoadingState<MsgFeedReplyMe>> customGetData() =>
|
||||
MsgHttp.msgFeedReplyMe(cursor: cursor, cursorTime: cursorTime);
|
||||
|
||||
Future onRemove(dynamic id, int index) async {
|
||||
try {
|
||||
var res = await MsgHttp.delMsgfeed(1, id);
|
||||
if (res['status']) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
List<ReplyMeItems> list = (loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('删除成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
|
||||
@@ -34,21 +34,21 @@ class _ReplyMePageState extends State<ReplyMePage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<ReplyMeItems>?> 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) {
|
||||
_replyMeController.onLoadMore();
|
||||
}
|
||||
|
||||
ReplyMeItems item = loadingState.response[index];
|
||||
ReplyMeItems item = loadingState.response![index];
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
String? nativeUri = item.item?.nativeUri;
|
||||
@@ -121,12 +121,8 @@ class _ReplyMePageState extends State<ReplyMePage> {
|
||||
Text(item.item?.sourceContent ?? "",
|
||||
style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: 4),
|
||||
if (loadingState
|
||||
.response[index].item?.targetReplyContent !=
|
||||
null &&
|
||||
loadingState
|
||||
.response[index].item?.targetReplyContent !=
|
||||
"")
|
||||
if (item.item?.targetReplyContent != null &&
|
||||
item.item?.targetReplyContent != "")
|
||||
Text("| ${item.item?.targetReplyContent}",
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_sys_msg.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
|
||||
class SysMsgController extends CommonController {
|
||||
class SysMsgController
|
||||
extends CommonListController<List<SystemNotifyList>?, SystemNotifyList> {
|
||||
final pageSize = 20;
|
||||
int cursor = -1;
|
||||
|
||||
@@ -41,9 +43,9 @@ class SysMsgController extends CommonController {
|
||||
try {
|
||||
var res = await MsgHttp.delSysMsg(id);
|
||||
if (res['status']) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
List<SystemNotifyList> list = (loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('删除成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
@@ -52,6 +54,6 @@ class SysMsgController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
Future<LoadingState<List<SystemNotifyList>?>> customGetData() =>
|
||||
MsgHttp.msgFeedNotify(cursor: cursor, pageSize: pageSize);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:PiliPlus/common/widgets/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_sys_msg.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
@@ -39,21 +40,21 @@ class _SysMsgPageState extends State<SysMsgPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<SystemNotifyList>?> 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) {
|
||||
_sysMsgController.onLoadMore();
|
||||
}
|
||||
|
||||
final item = loadingState.response[index];
|
||||
final item = loadingState.response![index];
|
||||
String? content = item.content;
|
||||
if (content != null) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user