mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-03 15:50:18 +08:00
@@ -10,15 +10,14 @@ abstract class CommonDataController<R, T> extends CommonController<R, T> {
|
||||
Future<void> queryData([bool isRefresh = true]) async {
|
||||
if (isLoading) return;
|
||||
isLoading = true;
|
||||
LoadingState<R> response = await customGetData();
|
||||
if (response is Success<R>) {
|
||||
if (!customHandleResponse(isRefresh, response)) {
|
||||
loadingState.value = response as LoadingState<T>;
|
||||
final LoadingState<R> res = await customGetData();
|
||||
if (res is Success<R>) {
|
||||
if (!customHandleResponse(isRefresh, res)) {
|
||||
loadingState.value = res as LoadingState<T>;
|
||||
}
|
||||
} else {
|
||||
if (isRefresh &&
|
||||
!handleError(response is Error ? response.errMsg : null)) {
|
||||
loadingState.value = response as LoadingState<T>;
|
||||
if (isRefresh && !handleError(res is Error ? res.errMsg : null)) {
|
||||
loadingState.value = res as Error;
|
||||
}
|
||||
}
|
||||
isLoading = false;
|
||||
|
||||
@@ -168,19 +168,19 @@ mixin FavMixin on TripleMixin {
|
||||
Future<LoadingState<FavFolderData>> queryVideoInFolder() async {
|
||||
favIds = null;
|
||||
final (rid, type) = getFavRidType;
|
||||
final result = await FavHttp.videoInFolder(
|
||||
final res = await FavHttp.videoInFolder(
|
||||
mid: Accounts.main.mid,
|
||||
rid: rid,
|
||||
type: type,
|
||||
);
|
||||
if (result.isSuccess) {
|
||||
favFolderData.value = result.data;
|
||||
favIds = result.data.list
|
||||
if (res case Success(:final response)) {
|
||||
favFolderData.value = response;
|
||||
favIds = response.list
|
||||
?.where((item) => item.favState == 1)
|
||||
.map((item) => item.id)
|
||||
.toSet();
|
||||
}
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
|
||||
int get favFolderId {
|
||||
|
||||
@@ -23,10 +23,10 @@ abstract class CommonListController<R, T> extends CommonController<R, T> {
|
||||
Future<void> queryData([bool isRefresh = true]) async {
|
||||
if (isLoading || (!isRefresh && isEnd)) return;
|
||||
isLoading = true;
|
||||
LoadingState<R> response = await customGetData();
|
||||
if (response is Success<R>) {
|
||||
if (!customHandleResponse(isRefresh, response)) {
|
||||
final dataList = getDataList(response.response);
|
||||
final LoadingState<R> res = await customGetData();
|
||||
if (res case Success(:final response)) {
|
||||
if (!customHandleResponse(isRefresh, res)) {
|
||||
final dataList = getDataList(response);
|
||||
if (dataList == null || dataList.isEmpty) {
|
||||
isEnd = true;
|
||||
if (isRefresh) {
|
||||
@@ -41,17 +41,16 @@ abstract class CommonListController<R, T> extends CommonController<R, T> {
|
||||
if (isRefresh) {
|
||||
checkIsEnd(dataList.length);
|
||||
loadingState.value = Success(dataList);
|
||||
} else if (loadingState.value is Success) {
|
||||
final list = loadingState.value.data!..addAll(dataList);
|
||||
checkIsEnd(list.length);
|
||||
} else if (loadingState.value case Success(:final response)) {
|
||||
response!.addAll(dataList);
|
||||
checkIsEnd(response.length);
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
page++;
|
||||
} else {
|
||||
if (isRefresh &&
|
||||
!handleError(response is Error ? response.errMsg : null)) {
|
||||
loadingState.value = response as LoadingState<List<T>?>;
|
||||
if (isRefresh && !handleError(res is Error ? res.errMsg : null)) {
|
||||
loadingState.value = res as Error;
|
||||
}
|
||||
}
|
||||
isLoading = false;
|
||||
|
||||
@@ -65,10 +65,9 @@ abstract class CommonWhisperController<R>
|
||||
Future<void> onClearUnread() async {
|
||||
final res = await ImGrpc.clearUnread(pageType: sessionPageType);
|
||||
if (res.isSuccess) {
|
||||
if (loadingState.value.isSuccess) {
|
||||
List<Session>? list = loadingState.value.data;
|
||||
if (list != null && list.isNotEmpty) {
|
||||
for (final item in list) {
|
||||
if (loadingState.value case Success(:final response)) {
|
||||
if (response != null && response.isNotEmpty) {
|
||||
for (final item in response) {
|
||||
if (item.hasUnread()) {
|
||||
item.clearUnread();
|
||||
}
|
||||
|
||||
@@ -91,14 +91,13 @@ mixin CommonMultiSelectMixin<T extends MultiSelectData>
|
||||
|
||||
@override
|
||||
void handleSelect({bool checked = false, bool disableSelect = true}) {
|
||||
if (loadingState.value.isSuccess) {
|
||||
final list = loadingState.value.data;
|
||||
if (list != null && list.isNotEmpty) {
|
||||
for (final item in list) {
|
||||
if (loadingState.value case Success(:final response)) {
|
||||
if (response != null && response.isNotEmpty) {
|
||||
for (final item in response) {
|
||||
item.checked = checked;
|
||||
}
|
||||
loadingState.refresh();
|
||||
rxCount.value = checked ? list.length : 0;
|
||||
rxCount.value = checked ? response.length : 0;
|
||||
}
|
||||
}
|
||||
if (disableSelect && !checked) {
|
||||
|
||||
@@ -177,13 +177,12 @@ abstract class ReplyController<R> extends CommonListController<R, ReplyInfo> {
|
||||
if (res != null) {
|
||||
savedReplies.remove(key);
|
||||
ReplyInfo replyInfo = RequestUtils.replyCast(res);
|
||||
if (loadingState.value.isSuccess) {
|
||||
List<ReplyInfo>? list = loadingState.value.data;
|
||||
if (list == null) {
|
||||
if (loadingState.value case Success(:final response)) {
|
||||
if (response == null) {
|
||||
loadingState.value = Success([replyInfo]);
|
||||
} else {
|
||||
if (oid != null) {
|
||||
list.insert(hasUpTop ? 1 : 0, replyInfo);
|
||||
response.insert(hasUpTop ? 1 : 0, replyInfo);
|
||||
} else {
|
||||
replyItem!
|
||||
..count += 1
|
||||
@@ -206,9 +205,8 @@ abstract class ReplyController<R> extends CommonListController<R, ReplyInfo> {
|
||||
}
|
||||
|
||||
void onRemove(int index, ReplyInfo item, int? subIndex) {
|
||||
List<ReplyInfo> list = loadingState.value.data!;
|
||||
if (subIndex == null) {
|
||||
list.removeAt(index);
|
||||
loadingState.value.data!.removeAt(index);
|
||||
} else {
|
||||
item
|
||||
..count -= 1
|
||||
@@ -241,12 +239,12 @@ abstract class ReplyController<R> extends CommonListController<R, ReplyInfo> {
|
||||
isUpTop: isUpTop,
|
||||
);
|
||||
if (res.isSuccess) {
|
||||
List<ReplyInfo> list = loadingState.value.data!;
|
||||
item.replyControl.isUpTop = !isUpTop;
|
||||
if (!isUpTop && index != 0) {
|
||||
list[0].replyControl.isUpTop = false;
|
||||
final item = list.removeAt(index);
|
||||
list.insert(0, item);
|
||||
final list = loadingState.value.data!;
|
||||
list
|
||||
..first.replyControl.isUpTop = false
|
||||
..insert(0, list.removeAt(index));
|
||||
}
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('${isUpTop ? '取消' : ''}置顶成功');
|
||||
|
||||
Reference in New Issue
Block a user