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:
@@ -9,7 +9,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
|
||||
class LaterController extends MultiSelectController {
|
||||
class LaterController extends MultiSelectController<Map, HotVideoItemModel> {
|
||||
RxInt count = (-1).obs;
|
||||
|
||||
dynamic mid;
|
||||
@@ -22,25 +22,24 @@ class LaterController extends MultiSelectController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
count.value = response.response['count'];
|
||||
if (response.response['list'].isEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
if (currentPage != 1 && loadingState.value is Success) {
|
||||
response.response['list'].insertAll(
|
||||
0,
|
||||
List<HotVideoItemModel>.from((loadingState.value as Success).response),
|
||||
);
|
||||
}
|
||||
if (response.response['list'].length >= count.value) {
|
||||
isEnd = true;
|
||||
}
|
||||
loadingState.value = LoadingState.success(response.response['list']);
|
||||
return true;
|
||||
List<HotVideoItemModel>? getDataList(response) {
|
||||
return response['list'];
|
||||
}
|
||||
|
||||
Future toViewDel(BuildContext context, {int? aid}) async {
|
||||
@override
|
||||
void checkIsEnd(int length) {
|
||||
if (length >= count.value) {
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
count.value = response.response['count'];
|
||||
return false;
|
||||
}
|
||||
|
||||
Future toViewDel(BuildContext context, {index, aid}) async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
@@ -50,7 +49,7 @@ class LaterController extends MultiSelectController {
|
||||
aid != null ? '即将移除该视频,确定是否移除' : '即将删除所有已观看视频,此操作不可恢复。确定是否删除?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
onPressed: Get.back,
|
||||
child: Text(
|
||||
'取消',
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.outline),
|
||||
@@ -62,10 +61,11 @@ class LaterController extends MultiSelectController {
|
||||
await UserHttp.toViewDel(aids: aid != null ? [aid] : null);
|
||||
if (res['status']) {
|
||||
if (aid != null) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
list.removeWhere((e) => e.aid == aid);
|
||||
List<HotVideoItemModel> list =
|
||||
(loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
count.value -= 1;
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
} else {
|
||||
onReload();
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class LaterController extends MultiSelectController {
|
||||
onConfirm: () async {
|
||||
var res = await UserHttp.toViewClear();
|
||||
if (res['status']) {
|
||||
loadingState.value = LoadingState.success([]);
|
||||
loadingState.value = LoadingState.success(null);
|
||||
}
|
||||
SmartDialog.showToast(res['msg']);
|
||||
},
|
||||
@@ -98,7 +98,7 @@ class LaterController extends MultiSelectController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => UserHttp.seeYouLater();
|
||||
Future<LoadingState<Map>> customGetData() => UserHttp.seeYouLater();
|
||||
|
||||
onDelChecked(BuildContext context) {
|
||||
showDialog(
|
||||
@@ -137,9 +137,10 @@ class LaterController extends MultiSelectController {
|
||||
List aids = result.map((item) => item.aid).toList();
|
||||
dynamic res = await UserHttp.toViewDel(aids: aids);
|
||||
if (res['status']) {
|
||||
Set remainList = ((loadingState.value as Success).response as List)
|
||||
.toSet()
|
||||
.difference(result.toSet());
|
||||
Set<HotVideoItemModel> remainList =
|
||||
((loadingState.value as Success).response as List<HotVideoItemModel>)
|
||||
.toSet()
|
||||
.difference(result.toSet());
|
||||
count.value -= aids.length;
|
||||
loadingState.value = LoadingState.success(remainList.toList());
|
||||
if (enableMultiSelect.value) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/model_hot_video_item.dart';
|
||||
import 'package:PiliPlus/pages/history/view.dart' show AppBarWidget;
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
@@ -93,7 +94,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
style: TextButton.styleFrom(
|
||||
visualDensity: VisualDensity(horizontal: -2, vertical: -2),
|
||||
),
|
||||
onPressed: () => Utils.onCopyOrMove(
|
||||
onPressed: () => Utils.onCopyOrMove<HotVideoItemModel>(
|
||||
context: context,
|
||||
isCopy: true,
|
||||
ctr: _laterController,
|
||||
@@ -110,7 +111,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
style: TextButton.styleFrom(
|
||||
visualDensity: VisualDensity(horizontal: -2, vertical: -2),
|
||||
),
|
||||
onPressed: () => Utils.onCopyOrMove(
|
||||
onPressed: () => Utils.onCopyOrMove<HotVideoItemModel>(
|
||||
context: context,
|
||||
isCopy: false,
|
||||
ctr: _laterController,
|
||||
@@ -171,7 +172,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<HotVideoItemModel>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
@@ -186,7 +187,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: 2,
|
||||
@@ -195,7 +196,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
var videoItem = loadingState.response[index];
|
||||
var videoItem = loadingState.response![index];
|
||||
return Stack(
|
||||
children: [
|
||||
VideoCardH(
|
||||
@@ -209,7 +210,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
'oid': videoItem.aid,
|
||||
'heroTag': Utils.makeHeroTag(videoItem.bvid),
|
||||
'sourceType': 'watchLater',
|
||||
'count': loadingState.response.length,
|
||||
'count': loadingState.response!.length,
|
||||
'favTitle': '稍后再看',
|
||||
'mediaId': _laterController.mid,
|
||||
'desc': false,
|
||||
@@ -293,6 +294,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
onPressed: () {
|
||||
_laterController.toViewDel(
|
||||
context,
|
||||
index: index,
|
||||
aid: videoItem.aid,
|
||||
);
|
||||
},
|
||||
@@ -305,7 +307,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
],
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
|
||||
Reference in New Issue
Block a user