mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-21 09:37:02 +08:00
opt: multiSelect (#935)
This commit is contained in:
committed by
GitHub
parent
d246462535
commit
7b51f15753
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/models_new/history/data.dart';
|
||||
@@ -26,6 +27,12 @@ class HistoryController
|
||||
int? max;
|
||||
int? viewAt;
|
||||
|
||||
@override
|
||||
RxInt get rxCount => baseCtr.checkedCount;
|
||||
|
||||
@override
|
||||
RxBool get enableMultiSelect => baseCtr.enableMultiSelect;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -40,36 +47,6 @@ class HistoryController
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
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;
|
||||
loadingState.refresh();
|
||||
if (baseCtr.checkedCount.value == 0) {
|
||||
baseCtr.enableMultiSelect.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSelect([bool checked = false, bool disableSelect = true]) {
|
||||
if (loadingState.value.isSuccess) {
|
||||
List<HistoryItemModel>? list = loadingState.value.data;
|
||||
if (list?.isNotEmpty == true) {
|
||||
for (HistoryItemModel item in list!) {
|
||||
item.checked = checked;
|
||||
}
|
||||
baseCtr.checkedCount.value = checked ? list.length : 0;
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
if (!checked) {
|
||||
baseCtr.enableMultiSelect.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<HistoryItemModel>? getDataList(HistoryData response) {
|
||||
return response.list;
|
||||
@@ -108,82 +85,43 @@ class HistoryController
|
||||
|
||||
// 删除某条历史记录
|
||||
void delHistory(HistoryItemModel item) {
|
||||
_onDelete([item]);
|
||||
_onDelete({item});
|
||||
}
|
||||
|
||||
// 删除已看历史记录
|
||||
void onDelHistory() {
|
||||
if (loadingState.value.isSuccess) {
|
||||
List<HistoryItemModel> list = loadingState.value.data!
|
||||
final set = loadingState.value.data!
|
||||
.where((e) => e.progress == -1)
|
||||
.toList();
|
||||
if (list.isNotEmpty) {
|
||||
_onDelete(list);
|
||||
.toSet();
|
||||
if (set.isNotEmpty) {
|
||||
_onDelete(set);
|
||||
} else {
|
||||
SmartDialog.showToast('无已看记录');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onDelete(List<HistoryItemModel> result) async {
|
||||
Future<void> _onDelete(Set<HistoryItemModel> result) async {
|
||||
SmartDialog.showLoading(msg: '请求中');
|
||||
List<String> kidList = result.map((item) {
|
||||
return '${item.history.business}_${item.kid}';
|
||||
}).toList();
|
||||
var response = await UserHttp.delHistory(kidList);
|
||||
final response = await UserHttp.delHistory(
|
||||
result.map((item) => '${item.history.business}_${item.kid}'),
|
||||
);
|
||||
if (response['status']) {
|
||||
List<HistoryItemModel> remainList = loadingState.value.data!
|
||||
.toSet()
|
||||
.difference(result.toSet())
|
||||
.toList();
|
||||
if (remainList.isNotEmpty) {
|
||||
loadingState.value = Success(remainList);
|
||||
} else {
|
||||
onReload();
|
||||
}
|
||||
if (baseCtr.enableMultiSelect.value) {
|
||||
baseCtr.checkedCount.value = 0;
|
||||
baseCtr.enableMultiSelect.value = false;
|
||||
}
|
||||
afterDelete(result);
|
||||
}
|
||||
SmartDialog.dismiss();
|
||||
SmartDialog.showToast(response['msg']);
|
||||
}
|
||||
|
||||
// 删除选中的记录
|
||||
void onDelCheckedHistory(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('提示'),
|
||||
content: const Text('确认删除所选历史记录吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Get.back,
|
||||
child: Text(
|
||||
'取消',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
if (loadingState.value.isSuccess) {
|
||||
_onDelete(
|
||||
loadingState.value.data!
|
||||
.where((e) => e.checked == true)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('确认'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
@override
|
||||
void onConfirm() {
|
||||
showConfirmDialog(
|
||||
context: Get.context!,
|
||||
content: '确认删除所选历史记录吗?',
|
||||
title: '提示',
|
||||
onConfirm: () => _onDelete(allChecked.toSet()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPlus/common/widgets/appbar/appbar.dart';
|
||||
import 'package:PiliPlus/common/widgets/keep_alive_wrapper.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
@@ -65,9 +66,10 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBarWidget(
|
||||
appBar: MultiSelectAppBarWidget(
|
||||
visible: enableMultiSelect,
|
||||
child1: AppBar(
|
||||
ctr: currCtr(),
|
||||
child: AppBar(
|
||||
title: const Text('观看记录'),
|
||||
bottom: _buildPauseTip,
|
||||
actions: [
|
||||
@@ -153,36 +155,6 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
child2: AppBar(
|
||||
bottom: _buildPauseTip,
|
||||
leading: IconButton(
|
||||
tooltip: '取消',
|
||||
onPressed: currCtr().handleSelect,
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
),
|
||||
title: Obx(
|
||||
() => Text(
|
||||
'已选: ${_historyController.baseCtr.checkedCount.value}',
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => currCtr().handleSelect(true),
|
||||
child: const Text('全选'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
currCtr().onDelCheckedHistory(context),
|
||||
child: Text(
|
||||
'删除',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: Obx(
|
||||
() => _historyController.tabs.isNotEmpty
|
||||
@@ -288,8 +260,7 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
final item = response[index];
|
||||
return HistoryItem(
|
||||
item: item,
|
||||
ctr: _historyController.baseCtr,
|
||||
onChoose: () => _historyController.onSelect(item),
|
||||
ctr: _historyController,
|
||||
onDelete: (kid, business) =>
|
||||
_historyController.delHistory(item),
|
||||
);
|
||||
@@ -359,32 +330,3 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
@override
|
||||
bool get wantKeepAlive => widget.type != null;
|
||||
}
|
||||
|
||||
class AppBarWidget extends StatelessWidget implements PreferredSizeWidget {
|
||||
const AppBarWidget({
|
||||
required this.child1,
|
||||
required this.child2,
|
||||
required this.visible,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final PreferredSizeWidget child1;
|
||||
final PreferredSizeWidget child2;
|
||||
final bool visible;
|
||||
@override
|
||||
Size get preferredSize => child1.preferredSize;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
transitionBuilder: (Widget child, Animation<double> animation) {
|
||||
return ScaleTransition(
|
||||
scale: animation,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: !visible ? child1 : child2,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/image_save.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/progress_bar/video_progress_indicator.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
@@ -9,7 +8,6 @@ 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/history/base_controller.dart';
|
||||
import 'package:PiliPlus/utils/date_util.dart';
|
||||
import 'package:PiliPlus/utils/duration_util.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
@@ -23,15 +21,13 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart
|
||||
|
||||
class HistoryItem extends StatelessWidget {
|
||||
final HistoryItemModel item;
|
||||
final dynamic ctr;
|
||||
final Function? onChoose;
|
||||
final Function(dynamic kid, dynamic business) onDelete;
|
||||
final MultiSelectMixin ctr;
|
||||
final void Function(int kid, String business) onDelete;
|
||||
|
||||
const HistoryItem({
|
||||
super.key,
|
||||
required this.item,
|
||||
this.ctr,
|
||||
this.onChoose,
|
||||
required this.ctr,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
@@ -45,11 +41,9 @@ class HistoryItem extends StatelessWidget {
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
if (ctr is MultiSelectController || ctr is HistoryBaseController) {
|
||||
if (ctr.enableMultiSelect.value) {
|
||||
onChoose?.call();
|
||||
return;
|
||||
}
|
||||
if (ctr.enableMultiSelect.value) {
|
||||
ctr.onSelect(item);
|
||||
return;
|
||||
}
|
||||
if (item.history.business?.contains('article') == true) {
|
||||
PageUtils.toDupNamed(
|
||||
@@ -97,18 +91,16 @@ class HistoryItem extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (ctr is MultiSelectController || ctr is HistoryBaseController) {
|
||||
if (!ctr.enableMultiSelect.value) {
|
||||
ctr.enableMultiSelect.value = true;
|
||||
onChoose?.call();
|
||||
}
|
||||
return;
|
||||
if (!ctr.enableMultiSelect.value) {
|
||||
ctr.enableMultiSelect.value = true;
|
||||
ctr.onSelect(item);
|
||||
}
|
||||
imageSaveDialog(
|
||||
title: item.title,
|
||||
cover: item.cover,
|
||||
bvid: bvid,
|
||||
);
|
||||
return;
|
||||
// imageSaveDialog(
|
||||
// title: item.title,
|
||||
// cover: item.cover,
|
||||
// bvid: bvid,
|
||||
// );
|
||||
},
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
@@ -205,7 +197,7 @@ class HistoryItem extends StatelessWidget {
|
||||
),
|
||||
onPressed: () {
|
||||
feedBack();
|
||||
onChoose?.call();
|
||||
ctr.onSelect(item);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.done_all_outlined,
|
||||
@@ -287,7 +279,7 @@ class HistoryItem extends StatelessWidget {
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
onTap: () =>
|
||||
onDelete(item.kid, item.history.business),
|
||||
onDelete(item.kid!, item.history.business!),
|
||||
height: 35,
|
||||
child: const Row(
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user