mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-26 05:16:01 +08:00
@@ -11,7 +11,7 @@ class HistoryBaseController extends GetxController {
|
||||
RxBool enableMultiSelect = false.obs;
|
||||
RxInt checkedCount = 0.obs;
|
||||
|
||||
// 清空观看历史
|
||||
// 清空观看历史
|
||||
void onClearHistory(BuildContext context, VoidCallback onSuccess) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -71,8 +71,10 @@ class HistoryBaseController extends GetxController {
|
||||
if (res.data['code'] == 0) {
|
||||
SmartDialog.showToast(pauseStatus ? '暂停观看历史' : '恢复观看历史');
|
||||
this.pauseStatus.value = pauseStatus;
|
||||
GStorage.localCache
|
||||
.put(LocalCacheKey.historyPause, pauseStatus);
|
||||
GStorage.localCache.put(
|
||||
LocalCacheKey.historyPause,
|
||||
pauseStatus,
|
||||
);
|
||||
}
|
||||
Get.back();
|
||||
},
|
||||
|
||||
@@ -44,8 +44,9 @@ class HistoryController
|
||||
void onSelect(HistoryItemModel item, [bool disableSelect = true]) {
|
||||
List<HistoryItemModel> list = loadingState.value.data!;
|
||||
item.checked = !(item.checked ?? false);
|
||||
baseCtr.checkedCount.value =
|
||||
list.where((item) => item.checked == true).length;
|
||||
baseCtr.checkedCount.value = list
|
||||
.where((item) => item.checked == true)
|
||||
.length;
|
||||
loadingState.refresh();
|
||||
if (baseCtr.checkedCount.value == 0) {
|
||||
baseCtr.enableMultiSelect.value = false;
|
||||
@@ -113,8 +114,9 @@ class HistoryController
|
||||
// 删除已看历史记录
|
||||
void onDelHistory() {
|
||||
if (loadingState.value.isSuccess) {
|
||||
List<HistoryItemModel> list =
|
||||
loadingState.value.data!.where((e) => e.progress == -1).toList();
|
||||
List<HistoryItemModel> list = loadingState.value.data!
|
||||
.where((e) => e.progress == -1)
|
||||
.toList();
|
||||
if (list.isNotEmpty) {
|
||||
_onDelete(list);
|
||||
} else {
|
||||
@@ -130,8 +132,10 @@ class HistoryController
|
||||
}).toList();
|
||||
var response = await UserHttp.delHistory(kidList);
|
||||
if (response['status']) {
|
||||
List<HistoryItemModel> remainList =
|
||||
loadingState.value.data!.toSet().difference(result.toSet()).toList();
|
||||
List<HistoryItemModel> remainList = loadingState.value.data!
|
||||
.toSet()
|
||||
.difference(result.toSet())
|
||||
.toList();
|
||||
if (remainList.isNotEmpty) {
|
||||
loadingState.value = Success(remainList);
|
||||
} else {
|
||||
@@ -168,13 +172,15 @@ class HistoryController
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
if (loadingState.value.isSuccess) {
|
||||
_onDelete(loadingState.value.data!
|
||||
.where((e) => e.checked == true)
|
||||
.toList());
|
||||
_onDelete(
|
||||
loadingState.value.data!
|
||||
.where((e) => e.checked == true)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('确认'),
|
||||
)
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -84,63 +84,75 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
// 处理菜单项选择的逻辑
|
||||
switch (type) {
|
||||
case 'pause':
|
||||
_historyController.baseCtr
|
||||
.onPauseHistory(context);
|
||||
_historyController.baseCtr.onPauseHistory(
|
||||
context,
|
||||
);
|
||||
break;
|
||||
case 'clear':
|
||||
_historyController.baseCtr
|
||||
.onClearHistory(context, () {
|
||||
_historyController.loadingState.value =
|
||||
const Success(null);
|
||||
if (_historyController.tabController !=
|
||||
null) {
|
||||
for (final item
|
||||
in _historyController.tabs) {
|
||||
try {
|
||||
Get.find<HistoryController>(
|
||||
tag: item.type)
|
||||
.loadingState
|
||||
.value = const Success(null);
|
||||
} catch (_) {}
|
||||
_historyController.baseCtr.onClearHistory(
|
||||
context,
|
||||
() {
|
||||
_historyController
|
||||
.loadingState
|
||||
.value = const Success(
|
||||
null,
|
||||
);
|
||||
if (_historyController
|
||||
.tabController !=
|
||||
null) {
|
||||
for (final item
|
||||
in _historyController.tabs) {
|
||||
try {
|
||||
Get.find<HistoryController>(
|
||||
tag: item.type,
|
||||
).loadingState.value =
|
||||
const Success(null);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
break;
|
||||
case 'del':
|
||||
currCtr().onDelHistory();
|
||||
break;
|
||||
case 'multiple':
|
||||
_historyController.baseCtr
|
||||
.enableMultiSelect.value = true;
|
||||
_historyController
|
||||
.baseCtr
|
||||
.enableMultiSelect
|
||||
.value =
|
||||
true;
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) =>
|
||||
<PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(
|
||||
value: 'pause',
|
||||
child: Obx(
|
||||
() => Text(
|
||||
!_historyController
|
||||
.baseCtr.pauseStatus.value
|
||||
? '暂停观看记录'
|
||||
: '恢复观看记录',
|
||||
PopupMenuItem<String>(
|
||||
value: 'pause',
|
||||
child: Obx(
|
||||
() => Text(
|
||||
!_historyController
|
||||
.baseCtr
|
||||
.pauseStatus
|
||||
.value
|
||||
? '暂停观看记录'
|
||||
: '恢复观看记录',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'clear',
|
||||
child: Text('清空观看记录'),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'del',
|
||||
child: Text('删除已看记录'),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'multiple',
|
||||
child: Text('多选删除'),
|
||||
),
|
||||
],
|
||||
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),
|
||||
],
|
||||
@@ -167,8 +179,8 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
child: Text(
|
||||
'删除',
|
||||
style: TextStyle(
|
||||
color:
|
||||
Theme.of(context).colorScheme.error),
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
@@ -187,13 +199,16 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
controller: _historyController.tabController,
|
||||
onTap: (index) {
|
||||
if (!_historyController
|
||||
.tabController!.indexIsChanging) {
|
||||
.tabController!
|
||||
.indexIsChanging) {
|
||||
currCtr().scrollController.animToTop();
|
||||
} else {
|
||||
if (enableMultiSelect) {
|
||||
currCtr(_historyController
|
||||
.tabController!.previousIndex)
|
||||
.handleSelect();
|
||||
currCtr(
|
||||
_historyController
|
||||
.tabController!
|
||||
.previousIndex,
|
||||
).handleSelect();
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -213,7 +228,8 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
_historyController.tabController,
|
||||
children: [
|
||||
KeepAliveWrapper(
|
||||
builder: (context) => _buildPage),
|
||||
builder: (context) => _buildPage,
|
||||
),
|
||||
..._historyController.tabs.map(
|
||||
(item) => HistoryPage(type: item.type),
|
||||
),
|
||||
@@ -236,61 +252,61 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
}
|
||||
|
||||
Widget get _buildPage => refreshIndicator(
|
||||
onRefresh: _historyController.onRefresh,
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _historyController.scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: StyleString.safeSpace - 5,
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80,
|
||||
),
|
||||
sliver:
|
||||
Obx(() => _buildBody(_historyController.loadingState.value)),
|
||||
),
|
||||
],
|
||||
onRefresh: _historyController.onRefresh,
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _historyController.scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: StyleString.safeSpace - 5,
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80,
|
||||
),
|
||||
sliver: Obx(() => _buildBody(_historyController.loadingState.value)),
|
||||
),
|
||||
);
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildBody(LoadingState<List<HistoryItemModel>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
},
|
||||
childCount: 10,
|
||||
),
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
},
|
||||
childCount: 10,
|
||||
),
|
||||
Success(:var response) => response?.isNotEmpty == true
|
||||
? SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == response.length - 1) {
|
||||
_historyController.onLoadMore();
|
||||
}
|
||||
final item = response[index];
|
||||
return HistoryItem(
|
||||
item: item,
|
||||
ctr: _historyController.baseCtr,
|
||||
onChoose: () => _historyController.onSelect(item),
|
||||
onDelete: (kid, business) =>
|
||||
_historyController.delHistory(item),
|
||||
);
|
||||
},
|
||||
childCount: response!.length,
|
||||
),
|
||||
Success(:var response) =>
|
||||
response?.isNotEmpty == true
|
||||
? SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == response.length - 1) {
|
||||
_historyController.onLoadMore();
|
||||
}
|
||||
final item = response[index];
|
||||
return HistoryItem(
|
||||
item: item,
|
||||
ctr: _historyController.baseCtr,
|
||||
onChoose: () => _historyController.onSelect(item),
|
||||
onDelete: (kid, business) =>
|
||||
_historyController.delHistory(item),
|
||||
);
|
||||
},
|
||||
childCount: response!.length,
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
onReload: _historyController.onReload,
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
onReload: _historyController.onReload,
|
||||
),
|
||||
Error(:var errMsg) => HttpError(
|
||||
errMsg: errMsg,
|
||||
onReload: _historyController.onReload,
|
||||
),
|
||||
errMsg: errMsg,
|
||||
onReload: _historyController.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,8 @@ class HistoryItem extends StatelessWidget {
|
||||
} else if (item.history.business == 'pgc') {
|
||||
PageUtils.viewPgc(epId: item.history.epid);
|
||||
} else {
|
||||
int? cid = item.history.cid ??
|
||||
int? cid =
|
||||
item.history.cid ??
|
||||
await SearchHttp.ab2c(
|
||||
aid: aid,
|
||||
bvid: bvid,
|
||||
@@ -138,15 +139,17 @@ class HistoryItem extends StatelessWidget {
|
||||
type: PBadgeType.gray,
|
||||
),
|
||||
// 右上角
|
||||
if (HistoryBusinessType.showBadge
|
||||
.contains(item.history.business) ||
|
||||
if (HistoryBusinessType.showBadge.contains(
|
||||
item.history.business,
|
||||
) ||
|
||||
item.history.business ==
|
||||
HistoryBusinessType.live.type)
|
||||
PBadge(
|
||||
text: item.badge,
|
||||
top: 6.0,
|
||||
right: 6.0,
|
||||
type: item.history.business ==
|
||||
type:
|
||||
item.history.business ==
|
||||
HistoryBusinessType.live.type &&
|
||||
item.liveStatus != 1
|
||||
? PBadgeType.gray
|
||||
@@ -181,28 +184,34 @@ class HistoryItem extends StatelessWidget {
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: item.checked == true ? 1 : 0,
|
||||
duration:
|
||||
const Duration(milliseconds: 250),
|
||||
duration: const Duration(
|
||||
milliseconds: 250,
|
||||
),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
tooltip: '取消选择',
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStateProperty.all(
|
||||
EdgeInsets.zero),
|
||||
EdgeInsets.zero,
|
||||
),
|
||||
backgroundColor:
|
||||
WidgetStateProperty.resolveWith(
|
||||
(states) {
|
||||
return theme.colorScheme.surface
|
||||
.withValues(alpha: 0.8);
|
||||
},
|
||||
),
|
||||
(states) {
|
||||
return theme
|
||||
.colorScheme
|
||||
.surface
|
||||
.withValues(alpha: 0.8);
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
feedBack();
|
||||
onChoose?.call();
|
||||
},
|
||||
icon: Icon(Icons.done_all_outlined,
|
||||
color: theme.colorScheme.primary),
|
||||
icon: Icon(
|
||||
Icons.done_all_outlined,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -236,55 +245,60 @@ class HistoryItem extends StatelessWidget {
|
||||
position: PopupMenuPosition.under,
|
||||
itemBuilder: (BuildContext context) =>
|
||||
<PopupMenuEntry<String>>[
|
||||
if (item.authorMid != null &&
|
||||
item.authorName?.isNotEmpty == true)
|
||||
PopupMenuItem<String>(
|
||||
onTap: () =>
|
||||
Get.toNamed('/member?mid=${item.authorMid}'),
|
||||
height: 35,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(MdiIcons.accountCircleOutline, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'访问:${item.authorName}',
|
||||
style: const TextStyle(fontSize: 13),
|
||||
)
|
||||
],
|
||||
if (item.authorMid != null &&
|
||||
item.authorName?.isNotEmpty == true)
|
||||
PopupMenuItem<String>(
|
||||
onTap: () =>
|
||||
Get.toNamed('/member?mid=${item.authorMid}'),
|
||||
height: 35,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
MdiIcons.accountCircleOutline,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'访问:${item.authorName}',
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (item.history.business != 'pgc' &&
|
||||
item.badge != '番剧' &&
|
||||
item.tagName?.contains('动画') != true &&
|
||||
item.history.business != 'live' &&
|
||||
item.history.business?.contains('article') != true)
|
||||
PopupMenuItem<String>(
|
||||
onTap: () async {
|
||||
var res = await UserHttp.toViewLater(
|
||||
bvid: item.history.bvid,
|
||||
);
|
||||
SmartDialog.showToast(res['msg']);
|
||||
},
|
||||
height: 35,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.watch_later_outlined, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text('稍后再看', style: TextStyle(fontSize: 13)),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
onTap: () =>
|
||||
onDelete(item.kid, item.history.business),
|
||||
height: 35,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.close_outlined, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text('删除记录', style: TextStyle(fontSize: 13)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (item.history.business != 'pgc' &&
|
||||
item.badge != '番剧' &&
|
||||
item.tagName?.contains('动画') != true &&
|
||||
item.history.business != 'live' &&
|
||||
item.history.business?.contains('article') != true)
|
||||
PopupMenuItem<String>(
|
||||
onTap: () async {
|
||||
var res = await UserHttp.toViewLater(
|
||||
bvid: item.history.bvid);
|
||||
SmartDialog.showToast(res['msg']);
|
||||
},
|
||||
height: 35,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.watch_later_outlined, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text('稍后再看', style: TextStyle(fontSize: 13))
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
onTap: () => onDelete(item.kid, item.history.business),
|
||||
height: 35,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.close_outlined, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text('删除记录', style: TextStyle(fontSize: 13))
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user