mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: query data
fix: webdav backup Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -39,9 +39,7 @@ abstract class CommonController extends GetxController
|
||||
|
||||
Future<LoadingState> customGetData();
|
||||
|
||||
List? handleListResponse(List currentList, List dataList) {
|
||||
return null;
|
||||
}
|
||||
void handleListResponse(List dataList) {}
|
||||
|
||||
bool customHandleResponse(Success response) {
|
||||
return false;
|
||||
@@ -51,28 +49,28 @@ abstract class CommonController extends GetxController
|
||||
return false;
|
||||
}
|
||||
|
||||
// void handleSuccess(List currentList, List dataList) {}
|
||||
|
||||
Future queryData([bool isRefresh = true]) async {
|
||||
if (isLoading || (isRefresh.not && isEnd)) return;
|
||||
isLoading = true;
|
||||
LoadingState response = await customGetData();
|
||||
if (response is Success) {
|
||||
if (!customHandleResponse(response)) {
|
||||
List dataList = (response.response as List?) ?? [];
|
||||
if (dataList.isEmpty) {
|
||||
List? dataList = response.response;
|
||||
if (dataList.isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
if (isRefresh) {
|
||||
loadingState.value = response;
|
||||
}
|
||||
return;
|
||||
}
|
||||
handleListResponse(dataList!);
|
||||
if (isRefresh) {
|
||||
loadingState.value = LoadingState.success(dataList);
|
||||
} else if (loadingState.value is Success) {
|
||||
List currentList = (loadingState.value as Success).response ?? [];
|
||||
currentList.addAll(dataList);
|
||||
loadingState.value = LoadingState.success(currentList);
|
||||
}
|
||||
List currentList = loadingState.value is Success
|
||||
? (loadingState.value as Success).response
|
||||
: [];
|
||||
List? handleList = handleListResponse(currentList, dataList);
|
||||
loadingState.value = isRefresh
|
||||
? handleList != null
|
||||
? LoadingState.success(handleList)
|
||||
: response
|
||||
: LoadingState.success(currentList + dataList);
|
||||
// handleSuccess(currentList, response.response);
|
||||
}
|
||||
currentPage++;
|
||||
} else {
|
||||
|
||||
@@ -15,15 +15,14 @@ class SysMsgController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
List? handleListResponse(List currentList, List dataList) {
|
||||
void handleListResponse(List dataList) {
|
||||
if (cursor == -1) {
|
||||
msgSysUpdateCursor(dataList.firstOrNull?.cursor);
|
||||
msgSysUpdateCursor(dataList.first?.cursor);
|
||||
}
|
||||
cursor = dataList.lastOrNull?.cursor ?? -1;
|
||||
cursor = dataList.last?.cursor ?? -1;
|
||||
if (isEnd.not && dataList.length + 1 < pageSize) {
|
||||
isEnd = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future msgSysUpdateCursor(int? cursor) async {
|
||||
|
||||
@@ -28,14 +28,21 @@ class RcmdController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
List? handleListResponse(List currentList, List dataList) {
|
||||
bool shouldSaveLast =
|
||||
enableSaveLastData && currentPage == 0 && currentList.isNotEmpty;
|
||||
if (shouldSaveLast && currentList.length > 500) {
|
||||
currentList.removeRange(50, currentList.length);
|
||||
void handleListResponse(List dataList) {
|
||||
if (enableSaveLastData &&
|
||||
currentPage == 0 &&
|
||||
loadingState.value is Success) {
|
||||
List? currentList = (loadingState.value as Success).response;
|
||||
if (currentList?.isNotEmpty == true) {
|
||||
if (savedRcmdTip) {
|
||||
lastRefreshAt = dataList.length;
|
||||
}
|
||||
if (currentList!.length > 500) {
|
||||
currentList.removeRange(50, currentList.length);
|
||||
}
|
||||
dataList.addAll(currentList);
|
||||
}
|
||||
}
|
||||
lastRefreshAt = shouldSaveLast && savedRcmdTip ? dataList.length : null;
|
||||
return shouldSaveLast ? (dataList..addAll(currentList)) : null;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
@@ -60,10 +59,9 @@ class WebDav {
|
||||
try {
|
||||
String data = await GStorage.exportAllSettings();
|
||||
final path = '$_webdavDirectory/piliplus_settings.json';
|
||||
final file = File(path);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
try {
|
||||
await _client!.remove(path);
|
||||
} catch (_) {}
|
||||
await _client!.write(path, utf8.encode(data));
|
||||
SmartDialog.showToast('备份成功');
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user