mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-25 03:26:22 +08:00
refa: query data (#659)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -9,7 +9,7 @@ import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/models/user/history.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
|
||||
class HistoryController extends MultiSelectController
|
||||
class HistoryController extends MultiSelectController<HistoryData, HisListItem>
|
||||
with GetTickerProviderStateMixin {
|
||||
HistoryController(this.type);
|
||||
|
||||
@@ -37,25 +37,27 @@ class HistoryController extends MultiSelectController
|
||||
}
|
||||
|
||||
@override
|
||||
onSelect(int index) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
list[index].checked = !(list[index]?.checked ?? false);
|
||||
onSelect(int index, [bool disableSelect = true]) {
|
||||
List<HisListItem> list = (loadingState.value as Success).response;
|
||||
list[index].checked = !(list[index].checked ?? false);
|
||||
baseCtr.checkedCount.value =
|
||||
list.where((item) => item.checked == true).length;
|
||||
loadingState.value = LoadingState.success(list);
|
||||
loadingState.refresh();
|
||||
if (baseCtr.checkedCount.value == 0) {
|
||||
baseCtr.enableMultiSelect.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSelect([bool checked = false]) {
|
||||
void handleSelect([bool checked = false, bool disableSelect = true]) {
|
||||
if (loadingState.value is Success) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
if (list.isNotEmpty) {
|
||||
loadingState.value = LoadingState.success(
|
||||
list.map((item) => item..checked = checked).toList());
|
||||
List<HisListItem>? list = (loadingState.value as Success).response;
|
||||
if (list?.isNotEmpty == true) {
|
||||
for (HisListItem item in list!) {
|
||||
item.checked = checked;
|
||||
}
|
||||
baseCtr.checkedCount.value = checked ? list.length : 0;
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
if (checked.not) {
|
||||
@@ -64,26 +66,28 @@ class HistoryController extends MultiSelectController
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
List<HisListItem>? getDataList(HistoryData response) {
|
||||
return response.list;
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success<HistoryData> response) {
|
||||
HistoryData data = response.response;
|
||||
isEnd = data.list.isNullOrEmpty;
|
||||
max = data.list?.lastOrNull?.history.oid;
|
||||
viewAt = data.list?.lastOrNull?.viewAt;
|
||||
if (currentPage == 1) {
|
||||
if (type == null && tabs.isEmpty && data.tab?.isNotEmpty == true) {
|
||||
|
||||
if (isRefresh && type == null) {
|
||||
if (tabs.isEmpty && data.tab?.isNotEmpty == true) {
|
||||
tabs.value = data.tab!;
|
||||
tabController =
|
||||
TabController(length: data.tab!.length + 1, vsync: this);
|
||||
tabController = TabController(
|
||||
length: data.tab!.length + 1,
|
||||
vsync: this,
|
||||
);
|
||||
}
|
||||
} else if (loadingState.value is Success) {
|
||||
data.list ??= <HisListItem>[];
|
||||
data.list!.insertAll(
|
||||
0,
|
||||
List<HisListItem>.from((loadingState.value as Success).response),
|
||||
);
|
||||
}
|
||||
loadingState.value = LoadingState.success(data.list);
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 观看历史暂停状态
|
||||
@@ -125,10 +129,11 @@ class HistoryController extends MultiSelectController
|
||||
}).toList();
|
||||
dynamic response = await UserHttp.delHistory(kidList);
|
||||
if (response['status']) {
|
||||
List remainList = ((loadingState.value as Success).response as List)
|
||||
.toSet()
|
||||
.difference(result.toSet())
|
||||
.toList();
|
||||
List<HisListItem> remainList =
|
||||
((loadingState.value as Success).response as List<HisListItem>)
|
||||
.toSet()
|
||||
.difference(result.toSet())
|
||||
.toList();
|
||||
if (remainList.isNotEmpty) {
|
||||
loadingState.value = LoadingState.success(remainList);
|
||||
} else {
|
||||
@@ -179,7 +184,7 @@ class HistoryController extends MultiSelectController
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
Future<LoadingState<HistoryData>> customGetData() =>
|
||||
UserHttp.historyList(type: type ?? 'all', max: max, viewAt: viewAt);
|
||||
|
||||
@override
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/user/history.dart';
|
||||
import 'package:PiliPlus/pages/fav_search/view.dart' show SearchType;
|
||||
import 'package:PiliPlus/pages/history/base_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
@@ -261,7 +262,7 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<HisListItem>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
@@ -276,7 +277,7 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: StyleString.safeSpace - 5,
|
||||
@@ -290,18 +291,18 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_historyController.onLoadMore();
|
||||
}
|
||||
return HistoryItem(
|
||||
videoItem: loadingState.response[index],
|
||||
videoItem: loadingState.response![index],
|
||||
ctr: _historyController.baseCtr,
|
||||
onChoose: () => _historyController.onSelect(index),
|
||||
onDelete: (kid, business) =>
|
||||
_historyController.delHistory(kid, business),
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -24,14 +24,14 @@ class HistoryItem extends StatelessWidget {
|
||||
final HisListItem videoItem;
|
||||
final dynamic ctr;
|
||||
final Function? onChoose;
|
||||
final Function? onDelete;
|
||||
final Function(dynamic kid, dynamic business) onDelete;
|
||||
|
||||
const HistoryItem({
|
||||
super.key,
|
||||
required this.videoItem,
|
||||
this.ctr,
|
||||
this.onChoose,
|
||||
this.onDelete,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -380,10 +380,8 @@ class HistoryItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
onTap: () => onDelete != null
|
||||
? onDelete!(videoItem.kid, videoItem.history.business)
|
||||
: ctr.delHistory(
|
||||
videoItem.kid, videoItem.history.business),
|
||||
onTap: () =>
|
||||
onDelete(videoItem.kid, videoItem.history.business),
|
||||
height: 35,
|
||||
child: const Row(
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user