mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refactor: history page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -166,7 +166,10 @@ class UserHttp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 观看历史
|
// 观看历史
|
||||||
static Future historyList(int? max, int? viewAt) async {
|
static Future<LoadingState> historyList({
|
||||||
|
int? max,
|
||||||
|
int? viewAt,
|
||||||
|
}) async {
|
||||||
var res = await Request().get(Api.historyList, data: {
|
var res = await Request().get(Api.historyList, data: {
|
||||||
'type': 'all',
|
'type': 'all',
|
||||||
'ps': 20,
|
'ps': 20,
|
||||||
@@ -174,9 +177,9 @@ class UserHttp {
|
|||||||
'view_at': viewAt ?? 0,
|
'view_at': viewAt ?? 0,
|
||||||
});
|
});
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return {'status': true, 'data': HistoryData.fromJson(res.data['data'])};
|
return LoadingState.success(HistoryData.fromJson(res.data['data']));
|
||||||
} else {
|
} else {
|
||||||
return {'status': false, 'data': [], 'msg': res.data['message']};
|
return LoadingState.error(res.data['message']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class HisListItem {
|
|||||||
this.kid,
|
this.kid,
|
||||||
this.tagName,
|
this.tagName,
|
||||||
this.liveStatus,
|
this.liveStatus,
|
||||||
this.checked,
|
required this.checked,
|
||||||
});
|
});
|
||||||
|
|
||||||
String? title;
|
String? title;
|
||||||
@@ -112,7 +112,7 @@ class HisListItem {
|
|||||||
int? kid;
|
int? kid;
|
||||||
String? tagName;
|
String? tagName;
|
||||||
int? liveStatus;
|
int? liveStatus;
|
||||||
bool? checked;
|
late bool checked;
|
||||||
void isFullScreen;
|
void isFullScreen;
|
||||||
|
|
||||||
HisListItem.fromJson(Map<String, dynamic> json) {
|
HisListItem.fromJson(Map<String, dynamic> json) {
|
||||||
|
|||||||
@@ -125,13 +125,11 @@ class BlackListController extends CommonController {
|
|||||||
@override
|
@override
|
||||||
bool customHandleResponse(Success response) {
|
bool customHandleResponse(Success response) {
|
||||||
total.value = response.response.total;
|
total.value = response.response.total;
|
||||||
List currentList = loadingState.value is Success
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
? (loadingState.value as Success).response
|
response.response.list
|
||||||
: [];
|
?.insertAll(0, (loadingState.value as Success).response);
|
||||||
List dataList = currentPage == 1
|
}
|
||||||
? response.response.list
|
loadingState.value = LoadingState.success(response.response.list);
|
||||||
: currentList + response.response.list;
|
|
||||||
loadingState.value = LoadingState.success(dataList);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,11 +64,9 @@ abstract class ReplyController extends CommonController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor = replies.cursor;
|
cursor = replies.cursor;
|
||||||
if (currentPage != 1) {
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
List<ReplyInfo> list = loadingState.value is Success
|
replies.replies
|
||||||
? (loadingState.value as Success).response.replies
|
.insertAll(0, (loadingState.value as Success).response.replies);
|
||||||
: <ReplyInfo>[];
|
|
||||||
replies.replies.insertAll(0, list);
|
|
||||||
}
|
}
|
||||||
isEnd = replies.replies.isEmpty ||
|
isEnd = replies.replies.isEmpty ||
|
||||||
replies.cursor.isEnd ||
|
replies.cursor.isEnd ||
|
||||||
|
|||||||
@@ -31,13 +31,12 @@ class DynamicsTabController extends CommonController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool customHandleResponse(Success response) {
|
bool customHandleResponse(Success response) {
|
||||||
List currentList = loadingState.value is Success
|
|
||||||
? (loadingState.value as Success).response
|
|
||||||
: [];
|
|
||||||
loadingState.value = offset == ''
|
|
||||||
? LoadingState.success(response.response.items)
|
|
||||||
: LoadingState.success(currentList + response.response.items);
|
|
||||||
offset = response.response.offset;
|
offset = response.response.offset;
|
||||||
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
|
response.response.items
|
||||||
|
.insertAll(0, (loadingState.value as Success).response);
|
||||||
|
}
|
||||||
|
loadingState.value = LoadingState.success(response.response.items);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,12 +33,11 @@ class FansController extends CommonController {
|
|||||||
response.response.list.isEmpty) {
|
response.response.list.isEmpty) {
|
||||||
isEnd = true;
|
isEnd = true;
|
||||||
}
|
}
|
||||||
List currentList = loadingState.value is Success
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
? (loadingState.value as Success).response
|
response.response.list
|
||||||
: [];
|
.insertAll(0, (loadingState.value as Success).response);
|
||||||
loadingState.value = currentPage == 1
|
}
|
||||||
? LoadingState.success(response.response.list)
|
loadingState.value = LoadingState.success(response.response.list);
|
||||||
: LoadingState.success(currentList + response.response.list);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,12 +33,11 @@ class FavController extends CommonController {
|
|||||||
@override
|
@override
|
||||||
bool customHandleResponse(Success response) {
|
bool customHandleResponse(Success response) {
|
||||||
hasMore = response.response.hasMore;
|
hasMore = response.response.hasMore;
|
||||||
List currentList = loadingState.value is Success
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
? (loadingState.value as Success).response
|
response.response.list
|
||||||
: [];
|
.insertAll(0, (loadingState.value as Success).response);
|
||||||
loadingState.value = currentPage == 1
|
}
|
||||||
? LoadingState.success(response.response.list)
|
loadingState.value = LoadingState.success(response.response.list);
|
||||||
: LoadingState.success(currentList + response.response.list);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,14 +48,12 @@ class FavDetailController extends CommonController {
|
|||||||
isOwner.value = response.response.info.mid ==
|
isOwner.value = response.response.info.mid ==
|
||||||
GStorage.userInfo.get('userInfoCache')?.mid;
|
GStorage.userInfo.get('userInfoCache')?.mid;
|
||||||
}
|
}
|
||||||
List currentList = loadingState.value is Success
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
? (loadingState.value as Success).response
|
response.response.medias
|
||||||
: [];
|
.insertAll(0, (loadingState.value as Success).response);
|
||||||
List dataList = currentPage == 1
|
}
|
||||||
? response.response.medias
|
loadingState.value = LoadingState.success(response.response.medias);
|
||||||
: currentList + response.response.medias;
|
if (response.response.medias.length >= response.response.info.mediaCount) {
|
||||||
loadingState.value = LoadingState.success(dataList);
|
|
||||||
if (dataList.length >= response.response.info.mediaCount) {
|
|
||||||
loadingText.value = '没有更多了';
|
loadingText.value = '没有更多了';
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -140,7 +140,6 @@ class _FavSearchPageState extends State<FavSearchPage> {
|
|||||||
videoItem: loadingState.response[index],
|
videoItem: loadingState.response[index],
|
||||||
ctr: _favSearchCtr,
|
ctr: _favSearchCtr,
|
||||||
onChoose: null,
|
onChoose: null,
|
||||||
onUpdateMultiple: () => null,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
childCount: loadingState.response.length,
|
childCount: loadingState.response.length,
|
||||||
|
|||||||
@@ -1,53 +1,47 @@
|
|||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
|
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||||
|
import 'package:PiliPalaX/utils/extension.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:PiliPalaX/http/user.dart';
|
import 'package:PiliPalaX/http/user.dart';
|
||||||
import 'package:PiliPalaX/models/user/history.dart';
|
import 'package:PiliPalaX/models/user/history.dart';
|
||||||
import 'package:PiliPalaX/utils/storage.dart';
|
import 'package:PiliPalaX/utils/storage.dart';
|
||||||
|
|
||||||
class HistoryController extends GetxController {
|
class HistoryController extends CommonController {
|
||||||
final ScrollController scrollController = ScrollController();
|
|
||||||
RxList<HisListItem> historyList = <HisListItem>[].obs;
|
|
||||||
RxBool isLoadingMore = false.obs;
|
|
||||||
RxBool pauseStatus = false.obs;
|
RxBool pauseStatus = false.obs;
|
||||||
Box localCache = GStorage.localCache;
|
|
||||||
RxBool isLoading = false.obs;
|
|
||||||
RxBool enableMultiple = false.obs;
|
RxBool enableMultiple = false.obs;
|
||||||
RxInt checkedCount = 0.obs;
|
RxInt checkedCount = 0.obs;
|
||||||
|
|
||||||
|
int? max;
|
||||||
|
int? viewAt;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
historyStatus();
|
historyStatus();
|
||||||
|
queryData();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future queryHistoryList({type = 'init'}) async {
|
@override
|
||||||
int max = 0;
|
Future onRefresh() {
|
||||||
int viewAt = 0;
|
max = null;
|
||||||
if (type == 'onload' && historyList.isNotEmpty) {
|
viewAt = null;
|
||||||
max = historyList.last.history!.oid!;
|
return super.onRefresh();
|
||||||
viewAt = historyList.last.viewAt!;
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool customHandleResponse(Success response) {
|
||||||
|
HistoryData data = response.response;
|
||||||
|
isEnd = data.list.isNullOrEmpty || data.list!.length < 20;
|
||||||
|
max = data.list?.lastOrNull?.history?.oid;
|
||||||
|
viewAt = data.list?.lastOrNull?.viewAt;
|
||||||
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
|
data.list?.insertAll(0, (loadingState.value as Success).response);
|
||||||
}
|
}
|
||||||
isLoadingMore.value = true;
|
loadingState.value = LoadingState.success(data.list);
|
||||||
var res = await UserHttp.historyList(max, viewAt);
|
return true;
|
||||||
isLoadingMore.value = false;
|
|
||||||
if (res['status']) {
|
|
||||||
if (type == 'onload') {
|
|
||||||
historyList.addAll(res['data'].list);
|
|
||||||
} else {
|
|
||||||
historyList.value = res['data'].list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future onLoad() async {
|
|
||||||
queryHistoryList(type: 'onload');
|
|
||||||
}
|
|
||||||
|
|
||||||
Future onRefresh() async {
|
|
||||||
queryHistoryList(type: 'onRefresh');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暂停观看历史
|
// 暂停观看历史
|
||||||
@@ -60,7 +54,7 @@ class HistoryController extends GetxController {
|
|||||||
content:
|
content:
|
||||||
Text(!pauseStatus.value ? '啊叻?你要暂停历史记录功能吗?' : '啊叻?要恢复历史记录功能吗?'),
|
Text(!pauseStatus.value ? '啊叻?你要暂停历史记录功能吗?' : '啊叻?要恢复历史记录功能吗?'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(onPressed: () => Get.back(), child: const Text('取消')),
|
TextButton(onPressed: Get.back, child: const Text('取消')),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
SmartDialog.showLoading(msg: '请求中');
|
SmartDialog.showLoading(msg: '请求中');
|
||||||
@@ -70,7 +64,8 @@ class HistoryController extends GetxController {
|
|||||||
SmartDialog.showToast(
|
SmartDialog.showToast(
|
||||||
!pauseStatus.value ? '暂停观看历史' : '恢复观看历史');
|
!pauseStatus.value ? '暂停观看历史' : '恢复观看历史');
|
||||||
pauseStatus.value = !pauseStatus.value;
|
pauseStatus.value = !pauseStatus.value;
|
||||||
localCache.put(LocalCacheKey.historyPause, pauseStatus.value);
|
GStorage.localCache
|
||||||
|
.put(LocalCacheKey.historyPause, pauseStatus.value);
|
||||||
}
|
}
|
||||||
Get.back();
|
Get.back();
|
||||||
},
|
},
|
||||||
@@ -87,7 +82,7 @@ class HistoryController extends GetxController {
|
|||||||
var res = await UserHttp.historyStatus();
|
var res = await UserHttp.historyStatus();
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
pauseStatus.value = res['data'];
|
pauseStatus.value = res['data'];
|
||||||
localCache.put(LocalCacheKey.historyPause, res['data']);
|
GStorage.localCache.put(LocalCacheKey.historyPause, res['data']);
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast(res['msg']);
|
SmartDialog.showToast(res['msg']);
|
||||||
}
|
}
|
||||||
@@ -102,7 +97,7 @@ class HistoryController extends GetxController {
|
|||||||
title: const Text('提示'),
|
title: const Text('提示'),
|
||||||
content: const Text('啊叻?你要清空历史记录功能吗?'),
|
content: const Text('啊叻?你要清空历史记录功能吗?'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(onPressed: () => Get.back(), child: const Text('取消')),
|
TextButton(onPressed: Get.back, child: const Text('取消')),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
SmartDialog.showLoading(msg: '请求中');
|
SmartDialog.showLoading(msg: '请求中');
|
||||||
@@ -112,7 +107,7 @@ class HistoryController extends GetxController {
|
|||||||
SmartDialog.showToast('清空观看历史');
|
SmartDialog.showToast('清空观看历史');
|
||||||
}
|
}
|
||||||
Get.back();
|
Get.back();
|
||||||
historyList.clear();
|
loadingState.value = LoadingState.success(<HisListItem>[]);
|
||||||
},
|
},
|
||||||
child: const Text('确认清空'),
|
child: const Text('确认清空'),
|
||||||
)
|
)
|
||||||
@@ -124,48 +119,38 @@ class HistoryController extends GetxController {
|
|||||||
|
|
||||||
// 删除某条历史记录
|
// 删除某条历史记录
|
||||||
Future delHistory(kid, business) async {
|
Future delHistory(kid, business) async {
|
||||||
// String resKid = 'archive_$kid';
|
_onDelete(((loadingState.value as Success).response as List<HisListItem>)
|
||||||
// if (business == 'live') {
|
.where((e) => e.kid == kid)
|
||||||
// resKid = 'live_$kid';
|
.toList());
|
||||||
// } else if (business.contains('article')) {
|
|
||||||
// resKid = 'article_$kid';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var res = await UserHttp.delHistory(resKid);
|
|
||||||
// if (res['status']) {
|
|
||||||
// historyList.removeWhere((e) => e.kid == kid);
|
|
||||||
// SmartDialog.showToast(res['msg']);
|
|
||||||
// }
|
|
||||||
_onDelete(historyList.where((e) => e.kid == kid).toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除已看历史记录
|
// 删除已看历史记录
|
||||||
void onDelHistory() {
|
void onDelHistory() {
|
||||||
List<HisListItem> list =
|
if (loadingState.value is Success) {
|
||||||
historyList.where((e) => e.progress == -1).toList();
|
List<HisListItem> list =
|
||||||
if (list.isNotEmpty) {
|
((loadingState.value as Success).response as List<HisListItem>)
|
||||||
_onDelete(list);
|
.where((e) => e.progress == -1)
|
||||||
} else {
|
.toList();
|
||||||
SmartDialog.showToast('无已看记录');
|
if (list.isNotEmpty) {
|
||||||
|
_onDelete(list);
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast('无已看记录');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onDelete(List<HisListItem> result) async {
|
void _onDelete(List<HisListItem> result) async {
|
||||||
SmartDialog.showLoading(msg: '请求中');
|
SmartDialog.showLoading(msg: '请求中');
|
||||||
List kidList = result.map((item) {
|
List kidList = result.map((item) {
|
||||||
// String tag = 'archive';
|
|
||||||
// if (item.history?.business == 'live') {
|
|
||||||
// tag = 'live';
|
|
||||||
// } else if (item.history?.business?.contains('article') == true) {
|
|
||||||
// tag = 'article-list';
|
|
||||||
// }
|
|
||||||
return '${item.history?.business}_${item.kid}';
|
return '${item.history?.business}_${item.kid}';
|
||||||
}).toList();
|
}).toList();
|
||||||
dynamic response = await UserHttp.delHistory(kidList);
|
dynamic response = await UserHttp.delHistory(kidList);
|
||||||
if (response['status']) {
|
if (response['status']) {
|
||||||
Set<HisListItem> remainList =
|
Set<HisListItem> remainList =
|
||||||
historyList.toSet().difference(result.toSet());
|
((loadingState.value as Success).response as List<HisListItem>)
|
||||||
historyList.value = remainList.toList();
|
.toSet()
|
||||||
|
.difference(result.toSet());
|
||||||
|
loadingState.value = LoadingState.success(remainList.toList());
|
||||||
if (enableMultiple.value) {
|
if (enableMultiple.value) {
|
||||||
checkedCount.value = 0;
|
checkedCount.value = 0;
|
||||||
enableMultiple.value = false;
|
enableMultiple.value = false;
|
||||||
@@ -185,7 +170,7 @@ class HistoryController extends GetxController {
|
|||||||
content: const Text('确认删除所选历史记录吗?'),
|
content: const Text('确认删除所选历史记录吗?'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Get.back(),
|
onPressed: Get.back,
|
||||||
child: Text(
|
child: Text(
|
||||||
'取消',
|
'取消',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -196,7 +181,10 @@ class HistoryController extends GetxController {
|
|||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Get.back();
|
Get.back();
|
||||||
_onDelete(historyList.where((e) => e.checked!).toList());
|
_onDelete(((loadingState.value as Success).response
|
||||||
|
as List<HisListItem>)
|
||||||
|
.where((e) => e.checked)
|
||||||
|
.toList());
|
||||||
},
|
},
|
||||||
child: const Text('确认'),
|
child: const Text('确认'),
|
||||||
)
|
)
|
||||||
@@ -207,8 +195,6 @@ class HistoryController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
Future<LoadingState> customGetData() =>
|
||||||
scrollController.dispose();
|
UserHttp.historyList(max: max, viewAt: viewAt);
|
||||||
super.onClose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||||
import 'package:PiliPalaX/common/widgets/refresh_indicator.dart';
|
import 'package:PiliPalaX/common/widgets/refresh_indicator.dart';
|
||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
|
import 'package:PiliPalaX/models/user/history.dart';
|
||||||
import 'package:PiliPalaX/pages/fav_search/view.dart' show SearchType;
|
import 'package:PiliPalaX/pages/fav_search/view.dart' show SearchType;
|
||||||
|
import 'package:PiliPalaX/utils/extension.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@@ -19,43 +22,35 @@ class HistoryPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HistoryPageState extends State<HistoryPage> {
|
class _HistoryPageState extends State<HistoryPage> {
|
||||||
final HistoryController _historyController = Get.put(HistoryController());
|
final _historyController = Get.put(HistoryController());
|
||||||
Future? _futureBuilderFuture;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_futureBuilderFuture = _historyController.queryHistoryList();
|
|
||||||
_historyController.scrollController.addListener(
|
_historyController.scrollController.addListener(
|
||||||
() {
|
() {
|
||||||
if (_historyController.scrollController.position.pixels >=
|
if (_historyController.scrollController.position.pixels >=
|
||||||
_historyController.scrollController.position.maxScrollExtent -
|
_historyController.scrollController.position.maxScrollExtent -
|
||||||
300) {
|
300) {
|
||||||
if (!_historyController.isLoadingMore.value) {
|
EasyThrottle.throttle('history', const Duration(seconds: 1), () {
|
||||||
EasyThrottle.throttle('history', const Duration(seconds: 1), () {
|
_historyController.onLoadMore();
|
||||||
_historyController.onLoad();
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
_historyController.enableMultiple.listen((p0) {
|
|
||||||
setState(() {});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选中
|
// 选中
|
||||||
onChoose(index) {
|
onChoose(index) {
|
||||||
_historyController.historyList[index].checked =
|
List<HisListItem> list =
|
||||||
!_historyController.historyList[index].checked!;
|
(_historyController.loadingState.value as Success).response;
|
||||||
|
list[index].checked = list[index].checked.not;
|
||||||
_historyController.checkedCount.value =
|
_historyController.checkedCount.value =
|
||||||
_historyController.historyList.where((item) => item.checked!).length;
|
list.where((item) => item.checked).length;
|
||||||
_historyController.historyList.refresh();
|
_historyController.loadingState.value = LoadingState.success(list);
|
||||||
}
|
if (_historyController.checkedCount.value == 0) {
|
||||||
|
_historyController.enableMultiple.value = false;
|
||||||
// 更新多选状态
|
}
|
||||||
onUpdateMultiple() {
|
|
||||||
setState(() {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -66,194 +61,187 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Obx(
|
||||||
appBar: AppBarWidget(
|
() => PopScope(
|
||||||
visible: _historyController.enableMultiple.value,
|
canPop: _historyController.enableMultiple.value.not,
|
||||||
child1: AppBar(
|
onPopInvokedWithResult: (didPop, result) {
|
||||||
title: Text('观看记录'),
|
if (_historyController.enableMultiple.value) {
|
||||||
actions: [
|
_handleSelect();
|
||||||
IconButton(
|
}
|
||||||
tooltip: '搜索',
|
},
|
||||||
onPressed: () => Get.toNamed('/favSearch', arguments: {
|
child: Scaffold(
|
||||||
'searchType': SearchType.history,
|
appBar: AppBarWidget(
|
||||||
}),
|
visible: _historyController.enableMultiple.value,
|
||||||
icon: const Icon(Icons.search_outlined),
|
child1: AppBar(
|
||||||
|
title: Text('观看记录'),
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
tooltip: '搜索',
|
||||||
|
onPressed: () => Get.toNamed(
|
||||||
|
'/favSearch',
|
||||||
|
arguments: {
|
||||||
|
'searchType': SearchType.history,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.search_outlined),
|
||||||
|
),
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
onSelected: (String type) {
|
||||||
|
// 处理菜单项选择的逻辑
|
||||||
|
switch (type) {
|
||||||
|
case 'pause':
|
||||||
|
_historyController.onPauseHistory(context);
|
||||||
|
break;
|
||||||
|
case 'clear':
|
||||||
|
_historyController.onClearHistory(context);
|
||||||
|
break;
|
||||||
|
case 'del':
|
||||||
|
_historyController.onDelHistory();
|
||||||
|
break;
|
||||||
|
case 'multiple':
|
||||||
|
_historyController.enableMultiple.value = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
itemBuilder: (BuildContext context) =>
|
||||||
|
<PopupMenuEntry<String>>[
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'pause',
|
||||||
|
child: Obx(
|
||||||
|
() => Text(
|
||||||
|
!_historyController.pauseStatus.value
|
||||||
|
? '暂停观看记录'
|
||||||
|
: '恢复观看记录',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const PopupMenuItem<String>(
|
||||||
|
value: 'clear',
|
||||||
|
child: Text('清空观看记录'),
|
||||||
|
),
|
||||||
|
const PopupMenuItem<String>(
|
||||||
|
value: 'del',
|
||||||
|
child: Text('删除已看记录'),
|
||||||
|
),
|
||||||
|
const PopupMenuItem<String>(
|
||||||
|
value: 'multiple',
|
||||||
|
child: Text('多选删除'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
PopupMenuButton<String>(
|
child2: AppBar(
|
||||||
onSelected: (String type) {
|
leading: IconButton(
|
||||||
// 处理菜单项选择的逻辑
|
tooltip: '取消',
|
||||||
switch (type) {
|
onPressed: _handleSelect,
|
||||||
case 'pause':
|
icon: const Icon(Icons.close_outlined),
|
||||||
_historyController.onPauseHistory(context);
|
),
|
||||||
break;
|
title: Obx(
|
||||||
case 'clear':
|
() => Text(
|
||||||
_historyController.onClearHistory(context);
|
'已选择${_historyController.checkedCount.value}项',
|
||||||
break;
|
),
|
||||||
case 'del':
|
),
|
||||||
_historyController.onDelHistory();
|
actions: [
|
||||||
break;
|
TextButton(
|
||||||
case 'multiple':
|
onPressed: () => _handleSelect(true),
|
||||||
_historyController.enableMultiple.value = true;
|
child: const Text('全选'),
|
||||||
setState(() {});
|
),
|
||||||
break;
|
TextButton(
|
||||||
default:
|
onPressed: () =>
|
||||||
}
|
_historyController.onDelCheckedHistory(context),
|
||||||
},
|
child: Text(
|
||||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
'删除',
|
||||||
PopupMenuItem<String>(
|
style:
|
||||||
value: 'pause',
|
TextStyle(color: Theme.of(context).colorScheme.error),
|
||||||
child: Obx(
|
|
||||||
() => Text(!_historyController.pauseStatus.value
|
|
||||||
? '暂停观看记录'
|
|
||||||
: '恢复观看记录'),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const PopupMenuItem<String>(
|
const SizedBox(width: 6),
|
||||||
value: 'clear',
|
],
|
||||||
child: Text('清空观看记录'),
|
),
|
||||||
),
|
),
|
||||||
const PopupMenuItem<String>(
|
body: refreshIndicator(
|
||||||
value: 'del',
|
onRefresh: () async {
|
||||||
child: Text('删除已看记录'),
|
await _historyController.onRefresh();
|
||||||
),
|
},
|
||||||
const PopupMenuItem<String>(
|
child: CustomScrollView(
|
||||||
value: 'multiple',
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
child: Text('多选删除'),
|
controller: _historyController.scrollController,
|
||||||
|
slivers: [
|
||||||
|
Obx(() => _buildBody(_historyController.loadingState.value)),
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: SizedBox(
|
||||||
|
height: MediaQuery.of(context).padding.bottom + 10,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(width: 6),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child2: AppBar(
|
|
||||||
leading: IconButton(
|
|
||||||
tooltip: '取消',
|
|
||||||
onPressed: () {
|
|
||||||
_historyController.enableMultiple.value = false;
|
|
||||||
for (var item in _historyController.historyList) {
|
|
||||||
item.checked = false;
|
|
||||||
}
|
|
||||||
_historyController.checkedCount.value = 0;
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.close_outlined),
|
|
||||||
),
|
),
|
||||||
title: Obx(
|
|
||||||
() => Text(
|
|
||||||
'已选择${_historyController.checkedCount.value}项',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
for (var item in _historyController.historyList) {
|
|
||||||
item.checked = true;
|
|
||||||
}
|
|
||||||
_historyController.checkedCount.value =
|
|
||||||
_historyController.historyList.length;
|
|
||||||
_historyController.historyList.refresh();
|
|
||||||
},
|
|
||||||
child: const Text('全选'),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => _historyController.onDelCheckedHistory(context),
|
|
||||||
child: Text(
|
|
||||||
'删除',
|
|
||||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: refreshIndicator(
|
);
|
||||||
onRefresh: () async {
|
}
|
||||||
await _historyController.onRefresh();
|
|
||||||
return;
|
Widget _buildBody(LoadingState loadingState) {
|
||||||
},
|
return switch (loadingState) {
|
||||||
child: CustomScrollView(
|
Loading() => SliverGrid(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||||
controller: _historyController.scrollController,
|
mainAxisSpacing: StyleString.cardSpace,
|
||||||
slivers: [
|
crossAxisSpacing: StyleString.safeSpace,
|
||||||
FutureBuilder(
|
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
||||||
future: _futureBuilderFuture,
|
childAspectRatio: StyleString.aspectRatio * 2.4,
|
||||||
builder: (context, snapshot) {
|
mainAxisExtent: 0,
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
),
|
||||||
if (snapshot.data == null) {
|
delegate: SliverChildBuilderDelegate(
|
||||||
return const SliverToBoxAdapter(child: SizedBox());
|
(context, index) {
|
||||||
}
|
return const VideoCardHSkeleton();
|
||||||
Map data = snapshot.data;
|
},
|
||||||
if (data['status']) {
|
childCount: 10,
|
||||||
return Obx(
|
),
|
||||||
() => _historyController.historyList.isNotEmpty
|
),
|
||||||
? SliverGrid(
|
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||||
gridDelegate:
|
? SliverGrid(
|
||||||
SliverGridDelegateWithExtentAndRatio(
|
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||||
mainAxisSpacing: StyleString.cardSpace,
|
mainAxisSpacing: StyleString.cardSpace,
|
||||||
crossAxisSpacing: StyleString.safeSpace,
|
crossAxisSpacing: StyleString.safeSpace,
|
||||||
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
||||||
childAspectRatio:
|
childAspectRatio: StyleString.aspectRatio * 2.4,
|
||||||
StyleString.aspectRatio * 2.4,
|
mainAxisExtent: 0,
|
||||||
mainAxisExtent: 0),
|
),
|
||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(context, index) {
|
(context, index) {
|
||||||
return HistoryItem(
|
return HistoryItem(
|
||||||
videoItem:
|
videoItem: loadingState.response[index],
|
||||||
_historyController.historyList[index],
|
ctr: _historyController,
|
||||||
ctr: _historyController,
|
onChoose: () => onChoose(index),
|
||||||
onChoose: () => onChoose(index),
|
|
||||||
onUpdateMultiple: () => onUpdateMultiple(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
childCount:
|
|
||||||
_historyController.historyList.length),
|
|
||||||
)
|
|
||||||
: _historyController.isLoadingMore.value
|
|
||||||
? const SliverToBoxAdapter(
|
|
||||||
child: Center(child: Text('加载中')),
|
|
||||||
)
|
|
||||||
: HttpError(
|
|
||||||
callback: () => setState(() {
|
|
||||||
_futureBuilderFuture =
|
|
||||||
_historyController.queryHistoryList();
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return HttpError(
|
|
||||||
errMsg: data['msg'],
|
|
||||||
callback: () => setState(() {
|
|
||||||
_futureBuilderFuture =
|
|
||||||
_historyController.queryHistoryList();
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 骨架屏
|
|
||||||
return SliverGrid(
|
|
||||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
|
||||||
mainAxisSpacing: StyleString.cardSpace,
|
|
||||||
crossAxisSpacing: StyleString.safeSpace,
|
|
||||||
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
|
||||||
childAspectRatio: StyleString.aspectRatio * 2.4,
|
|
||||||
mainAxisExtent: 0),
|
|
||||||
delegate: SliverChildBuilderDelegate((context, index) {
|
|
||||||
return const VideoCardHSkeleton();
|
|
||||||
}, childCount: 10),
|
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
},
|
childCount: loadingState.response.length,
|
||||||
),
|
|
||||||
SliverToBoxAdapter(
|
|
||||||
child: SizedBox(
|
|
||||||
height: MediaQuery.of(context).padding.bottom + 10,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
: HttpError(
|
||||||
|
callback: _historyController.onReload,
|
||||||
|
),
|
||||||
|
Error() => HttpError(
|
||||||
|
errMsg: loadingState.errMsg,
|
||||||
|
callback: _historyController.onReload,
|
||||||
),
|
),
|
||||||
),
|
LoadingState() => throw UnimplementedError(),
|
||||||
// bottomNavigationBar: BottomAppBar(),
|
};
|
||||||
);
|
}
|
||||||
|
|
||||||
|
void _handleSelect([bool checked = false]) {
|
||||||
|
List<HisListItem>? list =
|
||||||
|
(_historyController.loadingState.value as Success?)?.response;
|
||||||
|
if (list.isNullOrEmpty.not) {
|
||||||
|
_historyController.loadingState.value = LoadingState.success(
|
||||||
|
list!.map((item) => item..checked = checked).toList());
|
||||||
|
_historyController.checkedCount.value = checked ? list.length : 0;
|
||||||
|
}
|
||||||
|
if (checked.not) {
|
||||||
|
_historyController.enableMultiple.value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,11 @@ class HistoryItem extends StatelessWidget {
|
|||||||
final dynamic videoItem;
|
final dynamic videoItem;
|
||||||
final dynamic ctr;
|
final dynamic ctr;
|
||||||
final Function? onChoose;
|
final Function? onChoose;
|
||||||
final Function? onUpdateMultiple;
|
|
||||||
const HistoryItem({
|
const HistoryItem({
|
||||||
super.key,
|
super.key,
|
||||||
required this.videoItem,
|
required this.videoItem,
|
||||||
this.ctr,
|
this.ctr,
|
||||||
this.onChoose,
|
this.onChoose,
|
||||||
this.onUpdateMultiple,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -159,7 +157,6 @@ class HistoryItem extends StatelessWidget {
|
|||||||
feedBack();
|
feedBack();
|
||||||
ctr!.enableMultiple.value = true;
|
ctr!.enableMultiple.value = true;
|
||||||
onChoose?.call();
|
onChoose?.call();
|
||||||
onUpdateMultiple?.call();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -190,6 +187,7 @@ class HistoryItem extends StatelessWidget {
|
|||||||
Hero(
|
Hero(
|
||||||
tag: heroTag,
|
tag: heroTag,
|
||||||
child: NetworkImgLayer(
|
child: NetworkImgLayer(
|
||||||
|
radius: 12,
|
||||||
src: (videoItem.cover != ''
|
src: (videoItem.cover != ''
|
||||||
? videoItem.cover
|
? videoItem.cover
|
||||||
: videoItem.covers.first),
|
: videoItem.covers.first),
|
||||||
@@ -226,51 +224,47 @@ class HistoryItem extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Obx(
|
Positioned.fill(
|
||||||
() => Positioned.fill(
|
child: AnimatedOpacity(
|
||||||
child: AnimatedOpacity(
|
opacity: videoItem.checked ? 1 : 0,
|
||||||
opacity: ctr!.enableMultiple.value ? 1 : 0,
|
duration: const Duration(milliseconds: 200),
|
||||||
duration: const Duration(milliseconds: 200),
|
child: Container(
|
||||||
child: Container(
|
decoration: BoxDecoration(
|
||||||
decoration: BoxDecoration(
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderRadius: BorderRadius.circular(12),
|
color: Colors.black.withOpacity(0.6),
|
||||||
color: Colors.black.withOpacity(
|
),
|
||||||
ctr!.enableMultiple.value &&
|
child: Center(
|
||||||
videoItem.checked
|
child: SizedBox(
|
||||||
? 0.6
|
width: 34,
|
||||||
: 0),
|
height: 34,
|
||||||
),
|
child: AnimatedScale(
|
||||||
child: Center(
|
scale: videoItem.checked ? 1 : 0,
|
||||||
child: SizedBox(
|
duration:
|
||||||
width: 34,
|
const Duration(milliseconds: 250),
|
||||||
height: 34,
|
curve: Curves.easeInOut,
|
||||||
child: AnimatedScale(
|
child: IconButton(
|
||||||
scale: videoItem.checked ? 1 : 0,
|
tooltip: '取消选择',
|
||||||
duration:
|
style: ButtonStyle(
|
||||||
const Duration(milliseconds: 250),
|
padding: WidgetStateProperty.all(
|
||||||
curve: Curves.easeInOut,
|
EdgeInsets.zero),
|
||||||
child: IconButton(
|
backgroundColor:
|
||||||
tooltip: '取消选择',
|
WidgetStateProperty.resolveWith(
|
||||||
style: ButtonStyle(
|
(states) {
|
||||||
padding: WidgetStateProperty.all(
|
return Theme.of(context)
|
||||||
EdgeInsets.zero),
|
|
||||||
backgroundColor:
|
|
||||||
WidgetStateProperty.resolveWith(
|
|
||||||
(states) {
|
|
||||||
return Colors.white
|
|
||||||
.withOpacity(0.8);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
feedBack();
|
|
||||||
onChoose?.call();
|
|
||||||
},
|
|
||||||
icon: Icon(Icons.done_all_outlined,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.primary),
|
.surface
|
||||||
|
.withOpacity(0.8);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
onPressed: () {
|
||||||
|
feedBack();
|
||||||
|
onChoose?.call();
|
||||||
|
},
|
||||||
|
icon: Icon(Icons.done_all_outlined,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.primary),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -19,12 +19,11 @@ class LaterController extends CommonController {
|
|||||||
if (currentPage == 1) {
|
if (currentPage == 1) {
|
||||||
count.value = response.response['count'];
|
count.value = response.response['count'];
|
||||||
}
|
}
|
||||||
List currentList = loadingState.value is Success
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
? (loadingState.value as Success).response
|
response.response['list']
|
||||||
: [];
|
.insertAll(0, (loadingState.value as Success).response);
|
||||||
loadingState.value = currentPage == 1
|
}
|
||||||
? LoadingState.success(response.response['list'])
|
loadingState.value = LoadingState.success(response.response['list']);
|
||||||
: LoadingState.success(currentList + response.response['list']);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ class MemberDynamicCtr extends CommonController {
|
|||||||
bool customHandleResponse(Success response) {
|
bool customHandleResponse(Success response) {
|
||||||
DynSpaceRsp res = response.response;
|
DynSpaceRsp res = response.response;
|
||||||
isEnd = !res.hasMore;
|
isEnd = !res.hasMore;
|
||||||
if (currentPage != 1) {
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
res.list.insertAll(
|
res.list.insertAll(0, (loadingState.value as Success).response);
|
||||||
0, (loadingState.value as Success?)?.response ?? <DynamicItem>[]);
|
|
||||||
}
|
}
|
||||||
loadingState.value = LoadingState.success(res.list);
|
loadingState.value = LoadingState.success(res.list);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -36,17 +36,11 @@ class SearchPanelController extends CommonController {
|
|||||||
searchResultController.count[SearchType.values.indexOf(searchType!)] =
|
searchResultController.count[SearchType.values.indexOf(searchType!)] =
|
||||||
response.response.numResults;
|
response.response.numResults;
|
||||||
if (response.response.list != null) {
|
if (response.response.list != null) {
|
||||||
List currentList = currentPage != 1 && loadingState.value is Success
|
if (currentPage != 1 && loadingState.value is Success) {
|
||||||
? (loadingState.value as Success).response
|
response.response.list
|
||||||
: [];
|
?.insertAll(0, (loadingState.value as Success).response);
|
||||||
List dataList = currentPage == 1
|
|
||||||
? response.response.list
|
|
||||||
: currentList + response.response.list;
|
|
||||||
if (dataList.isNotEmpty) {
|
|
||||||
loadingState.value = LoadingState.success(dataList);
|
|
||||||
} else {
|
|
||||||
loadingState.value = LoadingState.success([]);
|
|
||||||
}
|
}
|
||||||
|
loadingState.value = LoadingState.success(response.response.list);
|
||||||
if (currentPage == 1) {
|
if (currentPage == 1) {
|
||||||
onPushDetail(response.response.list);
|
onPushDetail(response.response.list);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user