opt multi del

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-08-05 17:18:40 +08:00
parent 3caa684b2e
commit 104d295389
58 changed files with 379 additions and 404 deletions

View File

@@ -4,7 +4,7 @@ import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/models_new/history/data.dart';
import 'package:PiliPlus/models_new/history/list.dart';
import 'package:PiliPlus/models_new/history/tab.dart';
import 'package:PiliPlus/pages/common/multi_select_controller.dart';
import 'package:PiliPlus/pages/common/multi_select/multi_select_controller.dart';
import 'package:PiliPlus/pages/history/base_controller.dart';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/storage.dart';
@@ -89,26 +89,28 @@ class HistoryController
}
// 删除已看历史记录
void onDelHistory() {
void onDelViewedHistory() {
if (loadingState.value.isSuccess) {
final set = loadingState.value.data!
.where((e) => e.progress == -1)
.toSet();
if (set.isNotEmpty) {
_onDelete(set);
final viewedList = loadingState.value.data!.where(
(e) => e.progress == -1,
);
if (viewedList.isNotEmpty) {
_onDelete(viewedList);
} else {
SmartDialog.showToast('无已看记录');
}
}
}
Future<void> _onDelete(Set<HistoryItemModel> result) async {
Future<void> _onDelete(Iterable<HistoryItemModel> removeList) async {
SmartDialog.showLoading(msg: '请求中');
final response = await UserHttp.delHistory(
result.map((item) => '${item.history.business}_${item.kid}'),
removeList
.map((item) => '${item.history.business}_${item.kid}')
.join(','),
);
if (response['status']) {
afterDelete(result);
afterDelete(removeList);
}
SmartDialog.dismiss();
SmartDialog.showToast(response['msg']);
@@ -116,12 +118,12 @@ class HistoryController
// 删除选中的记录
@override
void onConfirm() {
void onRemove() {
showConfirmDialog(
context: Get.context!,
content: '确认删除所选历史记录吗?',
title: '提示',
onConfirm: () => _onDelete(allChecked.toSet()),
onConfirm: () => _onDelete(allChecked),
);
}

View File

@@ -52,189 +52,175 @@ class _HistoryPageState extends State<HistoryPage>
@override
Widget build(BuildContext context) {
super.build(context);
return widget.type != null
? _buildPage
: Obx(
() {
final enableMultiSelect =
_historyController.baseCtr.enableMultiSelect.value;
return PopScope(
canPop: !enableMultiSelect,
onPopInvokedWithResult: (didPop, result) {
if (enableMultiSelect) {
currCtr().handleSelect();
}
},
child: Scaffold(
appBar: MultiSelectAppBarWidget(
visible: enableMultiSelect,
ctr: currCtr(),
child: AppBar(
title: const Text('观看记录'),
bottom: _buildPauseTip,
actions: [
IconButton(
tooltip: '搜索',
onPressed: () => Get.toNamed('/historySearch'),
icon: const Icon(Icons.search_outlined),
Widget child = 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),
),
),
],
),
);
if (widget.type != null) {
return child;
}
return Obx(
() {
final enableMultiSelect =
_historyController.baseCtr.enableMultiSelect.value;
return PopScope(
canPop: !enableMultiSelect,
onPopInvokedWithResult: (didPop, result) {
if (enableMultiSelect) {
currCtr().handleSelect();
}
},
child: Scaffold(
appBar: MultiSelectAppBarWidget(
visible: enableMultiSelect,
ctr: currCtr(),
child: _buildAppBar,
),
body: Obx(() {
if (_historyController.tabs.isEmpty) {
return SafeArea(
top: false,
bottom: false,
child: child,
);
}
return SafeArea(
top: false,
bottom: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TabBar(
controller: _historyController.tabController,
onTap: (index) {
if (!_historyController
.tabController!
.indexIsChanging) {
currCtr().scrollController.animToTop();
} else {
if (enableMultiSelect) {
currCtr(
_historyController.tabController!.previousIndex,
).handleSelect();
}
}
},
tabs: [
const Tab(text: '全部'),
..._historyController.tabs.map(
(item) => Tab(text: item.name),
),
PopupMenuButton<String>(
onSelected: (String type) {
// 处理菜单项选择的逻辑
switch (type) {
case 'pause':
_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 (_) {}
}
}
},
);
break;
case 'del':
currCtr().onDelHistory();
break;
case 'multiple':
_historyController
.baseCtr
.enableMultiSelect
.value =
true;
break;
}
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
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 SizedBox(width: 6),
],
),
),
body: Obx(
() => _historyController.tabs.isNotEmpty
? SafeArea(
top: false,
bottom: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TabBar(
controller: _historyController.tabController,
onTap: (index) {
if (!_historyController
.tabController!
.indexIsChanging) {
currCtr().scrollController.animToTop();
} else {
if (enableMultiSelect) {
currCtr(
_historyController
.tabController!
.previousIndex,
).handleSelect();
}
}
},
tabs: [
const Tab(text: '全部'),
..._historyController.tabs.map(
(item) => Tab(text: item.name),
),
],
),
Expanded(
child: TabBarView(
physics: enableMultiSelect
? const NeverScrollableScrollPhysics()
: const CustomTabBarViewScrollPhysics(),
controller:
_historyController.tabController,
children: [
KeepAliveWrapper(
builder: (context) => _buildPage,
),
..._historyController.tabs.map(
(item) => HistoryPage(type: item.type),
),
],
),
),
],
),
)
: SafeArea(
top: false,
bottom: false,
child: _buildPage,
Expanded(
child: TabBarView(
physics: enableMultiSelect
? const NeverScrollableScrollPhysics()
: const CustomTabBarViewScrollPhysics(),
controller: _historyController.tabController,
children: [
KeepAliveWrapper(builder: (context) => child),
..._historyController.tabs.map(
(item) => HistoryPage(type: item.type),
),
),
],
),
),
],
),
);
},
);
}),
),
);
},
);
}
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,
AppBar get _buildAppBar => AppBar(
title: const Text('观看记录'),
bottom: _buildPauseTip,
actions: [
IconButton(
tooltip: '搜索',
onPressed: () => Get.toNamed('/historySearch'),
icon: const Icon(Icons.search_outlined),
),
PopupMenuButton<String>(
onSelected: (String type) {
switch (type) {
case 'pause':
_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 (_) {}
}
}
},
);
break;
case 'viewed':
currCtr().onDelViewedHistory();
break;
case 'multiple':
_historyController.baseCtr.enableMultiSelect.value = true;
break;
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: 'pause',
child: Text(
!_historyController.baseCtr.pauseStatus.value
? '暂停观看记录'
: '恢复观看记录',
),
),
sliver: Obx(() => _buildBody(_historyController.loadingState.value)),
),
],
),
const PopupMenuItem<String>(
value: 'clear',
child: Text('清空观看记录'),
),
const PopupMenuItem<String>(
value: 'viewed',
child: Text('删除已看记录'),
),
const PopupMenuItem<String>(
value: 'multiple',
child: Text('多选删除'),
),
],
),
const SizedBox(width: 6),
],
);
Widget _buildBody(LoadingState<List<HistoryItemModel>?> loadingState) {

View File

@@ -8,7 +8,7 @@ import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/models/common/badge_type.dart';
import 'package:PiliPlus/models/common/history_business_type.dart';
import 'package:PiliPlus/models_new/history/list.dart';
import 'package:PiliPlus/pages/common/multi_select_controller.dart';
import 'package:PiliPlus/pages/common/multi_select/base.dart';
import 'package:PiliPlus/utils/date_util.dart';
import 'package:PiliPlus/utils/duration_util.dart';
import 'package:PiliPlus/utils/id_utils.dart';
@@ -37,65 +37,63 @@ class HistoryItem extends StatelessWidget {
int aid = item.history.oid!;
String bvid = item.history.bvid ?? IdUtils.av2bv(aid);
final business = item.history.business;
final enableMultiSelect = ctr.enableMultiSelect.value;
return Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () async {
if (ctr.enableMultiSelect.value) {
ctr.onSelect(item);
return;
}
if (business?.contains('article') == true) {
PageUtils.toDupNamed(
'/articlePage',
parameters: {
'id': business == 'article-list'
? '${item.history.cid}'
: '${item.history.oid}',
'type': 'read',
onTap: enableMultiSelect
? () => ctr.onSelect(item)
: () async {
if (business?.contains('article') == true) {
PageUtils.toDupNamed(
'/articlePage',
parameters: {
'id': business == 'article-list'
? '${item.history.cid}'
: '${item.history.oid}',
'type': 'read',
},
);
} else if (business == 'live') {
if (item.liveStatus == 1) {
PageUtils.toLiveRoom(item.history.oid);
} else {
SmartDialog.showToast('直播未开播');
}
} else if (business == 'pgc') {
PageUtils.viewPgc(epId: item.history.epid);
} else if (business == 'cheese') {
if (item.uri?.isNotEmpty == true) {
PageUtils.viewPgcFromUri(
item.uri!,
isPgc: false,
aid: item.history.oid,
);
}
} else {
int? cid =
item.history.cid ??
await SearchHttp.ab2c(
aid: aid,
bvid: bvid,
part: item.history.page,
);
if (cid != null) {
PageUtils.toVideoPage(
aid: aid,
bvid: bvid,
cid: cid,
cover: item.cover,
title: item.title,
);
}
}
},
);
} else if (business == 'live') {
if (item.liveStatus == 1) {
PageUtils.toLiveRoom(item.history.oid);
} else {
SmartDialog.showToast('直播未开播');
}
} else if (business == 'pgc') {
PageUtils.viewPgc(epId: item.history.epid);
} else if (business == 'cheese') {
if (item.uri?.isNotEmpty == true) {
PageUtils.viewPgcFromUri(
item.uri!,
isPgc: false,
aid: item.history.oid,
);
}
} else {
int? cid =
item.history.cid ??
await SearchHttp.ab2c(
aid: aid,
bvid: bvid,
part: item.history.page,
);
if (cid != null) {
PageUtils.toVideoPage(
aid: aid,
bvid: bvid,
cid: cid,
cover: item.cover,
title: item.title,
);
}
}
},
onLongPress: ctr.enableMultiSelect.value
onLongPress: enableMultiSelect
? null
: () {
ctr.enableMultiSelect.value = true;
ctr.onSelect(item);
},
: () => ctr
..enableMultiSelect.value = true
..onSelect(item),
child: Stack(
clipBehavior: Clip.none,
children: [