mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: later page: multi select
feat: fav detail page: multi select opt: reply item opt: load more Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:PiliPalaX/pages/common/multi_select_controller.dart';
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -8,12 +8,9 @@ import 'package:PiliPalaX/http/user.dart';
|
||||
import 'package:PiliPalaX/models/user/history.dart';
|
||||
import 'package:PiliPalaX/utils/storage.dart';
|
||||
|
||||
class HistoryController extends CommonController {
|
||||
class HistoryController extends MultiSelectController {
|
||||
RxBool pauseStatus = false.obs;
|
||||
|
||||
RxBool enableMultiple = false.obs;
|
||||
RxInt checkedCount = 0.obs;
|
||||
|
||||
int? max;
|
||||
int? viewAt;
|
||||
|
||||
@@ -38,7 +35,10 @@ class HistoryController extends CommonController {
|
||||
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);
|
||||
data.list?.insertAll(
|
||||
0,
|
||||
List<HisListItem>.from((loadingState.value as Success).response),
|
||||
);
|
||||
}
|
||||
loadingState.value = LoadingState.success(data.list);
|
||||
return true;
|
||||
@@ -107,7 +107,7 @@ class HistoryController extends CommonController {
|
||||
SmartDialog.showToast('清空观看历史');
|
||||
}
|
||||
Get.back();
|
||||
loadingState.value = LoadingState.success(<HisListItem>[]);
|
||||
loadingState.value = LoadingState.success([]);
|
||||
},
|
||||
child: const Text('确认清空'),
|
||||
)
|
||||
@@ -119,7 +119,7 @@ class HistoryController extends CommonController {
|
||||
|
||||
// 删除某条历史记录
|
||||
Future delHistory(kid, business) async {
|
||||
_onDelete(((loadingState.value as Success).response as List<HisListItem>)
|
||||
_onDelete(((loadingState.value as Success).response as List)
|
||||
.where((e) => e.kid == kid)
|
||||
.toList());
|
||||
}
|
||||
@@ -127,10 +127,9 @@ class HistoryController extends CommonController {
|
||||
// 删除已看历史记录
|
||||
void onDelHistory() {
|
||||
if (loadingState.value is Success) {
|
||||
List<HisListItem> list =
|
||||
((loadingState.value as Success).response as List<HisListItem>)
|
||||
.where((e) => e.progress == -1)
|
||||
.toList();
|
||||
List list = ((loadingState.value as Success).response as List)
|
||||
.where((e) => e.progress == -1)
|
||||
.toList();
|
||||
if (list.isNotEmpty) {
|
||||
_onDelete(list);
|
||||
} else {
|
||||
@@ -139,21 +138,20 @@ class HistoryController extends CommonController {
|
||||
}
|
||||
}
|
||||
|
||||
void _onDelete(List<HisListItem> result) async {
|
||||
void _onDelete(List result) async {
|
||||
SmartDialog.showLoading(msg: '请求中');
|
||||
List kidList = result.map((item) {
|
||||
return '${item.history?.business}_${item.kid}';
|
||||
}).toList();
|
||||
dynamic response = await UserHttp.delHistory(kidList);
|
||||
if (response['status']) {
|
||||
Set<HisListItem> remainList =
|
||||
((loadingState.value as Success).response as List<HisListItem>)
|
||||
.toSet()
|
||||
.difference(result.toSet());
|
||||
Set remainList = ((loadingState.value as Success).response as List)
|
||||
.toSet()
|
||||
.difference(result.toSet());
|
||||
loadingState.value = LoadingState.success(remainList.toList());
|
||||
if (enableMultiple.value) {
|
||||
if (enableMultiSelect.value) {
|
||||
checkedCount.value = 0;
|
||||
enableMultiple.value = false;
|
||||
enableMultiSelect.value = false;
|
||||
}
|
||||
}
|
||||
SmartDialog.dismiss();
|
||||
@@ -161,8 +159,8 @@ class HistoryController extends CommonController {
|
||||
}
|
||||
|
||||
// 删除选中的记录
|
||||
Future onDelCheckedHistory(BuildContext context) async {
|
||||
await showDialog(
|
||||
void onDelCheckedHistory(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
@@ -181,8 +179,7 @@ class HistoryController extends CommonController {
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
_onDelete(((loadingState.value as Success).response
|
||||
as List<HisListItem>)
|
||||
_onDelete(((loadingState.value as Success).response as List)
|
||||
.where((e) => e.checked)
|
||||
.toList());
|
||||
},
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:PiliPalaX/common/widgets/http_error.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/utils/extension.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/common/skeleton/video_card_h.dart';
|
||||
@@ -24,54 +22,19 @@ class HistoryPage extends StatefulWidget {
|
||||
class _HistoryPageState extends State<HistoryPage> {
|
||||
final _historyController = Get.put(HistoryController());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_historyController.scrollController.addListener(
|
||||
() {
|
||||
if (_historyController.scrollController.position.pixels >=
|
||||
_historyController.scrollController.position.maxScrollExtent -
|
||||
300) {
|
||||
EasyThrottle.throttle('history', const Duration(seconds: 1), () {
|
||||
_historyController.onLoadMore();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 选中
|
||||
onChoose(index) {
|
||||
List<HisListItem> list =
|
||||
(_historyController.loadingState.value as Success).response;
|
||||
list[index].checked = list[index].checked.not;
|
||||
_historyController.checkedCount.value =
|
||||
list.where((item) => item.checked).length;
|
||||
_historyController.loadingState.value = LoadingState.success(list);
|
||||
if (_historyController.checkedCount.value == 0) {
|
||||
_historyController.enableMultiple.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_historyController.scrollController.removeListener(() {});
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(
|
||||
() => PopScope(
|
||||
canPop: _historyController.enableMultiple.value.not,
|
||||
canPop: _historyController.enableMultiSelect.value.not,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (_historyController.enableMultiple.value) {
|
||||
_handleSelect();
|
||||
if (_historyController.enableMultiSelect.value) {
|
||||
_historyController.handleSelect();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBarWidget(
|
||||
visible: _historyController.enableMultiple.value,
|
||||
visible: _historyController.enableMultiSelect.value,
|
||||
child1: AppBar(
|
||||
title: Text('观看记录'),
|
||||
actions: [
|
||||
@@ -99,7 +62,7 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
_historyController.onDelHistory();
|
||||
break;
|
||||
case 'multiple':
|
||||
_historyController.enableMultiple.value = true;
|
||||
_historyController.enableMultiSelect.value = true;
|
||||
break;
|
||||
}
|
||||
},
|
||||
@@ -135,7 +98,7 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
child2: AppBar(
|
||||
leading: IconButton(
|
||||
tooltip: '取消',
|
||||
onPressed: _handleSelect,
|
||||
onPressed: _historyController.handleSelect,
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
),
|
||||
title: Obx(
|
||||
@@ -145,7 +108,7 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => _handleSelect(true),
|
||||
onPressed: () => _historyController.handleSelect(true),
|
||||
child: const Text('全选'),
|
||||
),
|
||||
TextButton(
|
||||
@@ -211,10 +174,13 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
_historyController.onLoadMore();
|
||||
}
|
||||
return HistoryItem(
|
||||
videoItem: loadingState.response[index],
|
||||
ctr: _historyController,
|
||||
onChoose: () => onChoose(index),
|
||||
onChoose: () => _historyController.onSelect(index),
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
@@ -230,19 +196,6 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
LoadingState() => throw UnimplementedError(),
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AppBarWidget extends StatelessWidget implements PreferredSizeWidget {
|
||||
|
||||
@@ -33,7 +33,7 @@ class HistoryItem extends StatelessWidget {
|
||||
String heroTag = Utils.makeHeroTag(aid);
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
if (ctr!.enableMultiple.value) {
|
||||
if (ctr!.enableMultiSelect.value) {
|
||||
feedBack();
|
||||
onChoose?.call();
|
||||
return;
|
||||
@@ -153,9 +153,9 @@ class HistoryItem extends StatelessWidget {
|
||||
if (ctr is FavSearchController) {
|
||||
return;
|
||||
}
|
||||
if (!ctr!.enableMultiple.value) {
|
||||
if (!ctr!.enableMultiSelect.value) {
|
||||
feedBack();
|
||||
ctr!.enableMultiple.value = true;
|
||||
ctr!.enableMultiSelect.value = true;
|
||||
onChoose?.call();
|
||||
}
|
||||
},
|
||||
@@ -229,43 +229,41 @@ class HistoryItem extends StatelessWidget {
|
||||
opacity: videoItem.checked ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: videoItem.checked ? 1 : 0,
|
||||
duration:
|
||||
const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
tooltip: '取消选择',
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStateProperty.all(
|
||||
EdgeInsets.zero),
|
||||
backgroundColor:
|
||||
WidgetStateProperty.resolveWith(
|
||||
(states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.surface
|
||||
.withOpacity(0.8);
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
feedBack();
|
||||
onChoose?.call();
|
||||
},
|
||||
icon: Icon(Icons.done_all_outlined,
|
||||
color: Theme.of(context)
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: videoItem.checked ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
tooltip: '取消选择',
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStateProperty.all(
|
||||
EdgeInsets.zero),
|
||||
backgroundColor:
|
||||
WidgetStateProperty.resolveWith(
|
||||
(states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.primary),
|
||||
.surface
|
||||
.withOpacity(0.8);
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
feedBack();
|
||||
onChoose?.call();
|
||||
},
|
||||
icon: Icon(Icons.done_all_outlined,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user