mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-08-01 00:10:16 +08:00
opt: select (#937)
This commit is contained in:
committed by
GitHub
parent
afb09e8a0a
commit
01552801f2
@@ -6,6 +6,7 @@ import 'package:PiliPlus/models/common/video/source_type.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_detail/data.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_detail/media.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_folder/list.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select_controller.dart';
|
||||
import 'package:PiliPlus/pages/fav_sort/view.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
@@ -14,14 +15,70 @@ import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
mixin BaseFavController
|
||||
on
|
||||
CommonListController<FavDetailData, FavDetailItemModel>,
|
||||
DeleteItemMixin<FavDetailData, FavDetailItemModel> {
|
||||
bool get isOwner;
|
||||
int get mediaId;
|
||||
|
||||
void onRemove(int count) {}
|
||||
|
||||
void onViewFav(FavDetailItemModel item, int? index);
|
||||
|
||||
Future<void> onCancelFav(int index, int id, int type) async {
|
||||
var result = await FavHttp.favVideo(
|
||||
resources: '$id:$type',
|
||||
delIds: mediaId.toString(),
|
||||
);
|
||||
if (result['status']) {
|
||||
loadingState
|
||||
..value.data!.removeAt(index)
|
||||
..refresh();
|
||||
onRemove(1);
|
||||
SmartDialog.showToast('取消收藏');
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onConfirm() {
|
||||
showConfirmDialog(
|
||||
context: Get.context!,
|
||||
content: '确认删除所选收藏吗?',
|
||||
title: '提示',
|
||||
onConfirm: () async {
|
||||
final checked = allChecked.toSet();
|
||||
var result = await FavHttp.favVideo(
|
||||
resources: checked.map((item) => '${item.id}:${item.type}').join(','),
|
||||
delIds: mediaId.toString(),
|
||||
);
|
||||
if (result['status']) {
|
||||
afterDelete(checked);
|
||||
onRemove(checked.length);
|
||||
SmartDialog.showToast('取消收藏');
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FavDetailController
|
||||
extends MultiSelectController<FavDetailData, FavDetailItemModel> {
|
||||
extends MultiSelectController<FavDetailData, FavDetailItemModel>
|
||||
with BaseFavController {
|
||||
@override
|
||||
late int mediaId;
|
||||
late String heroTag;
|
||||
final Rx<FavFolderInfo> folderInfo = FavFolderInfo().obs;
|
||||
final Rx<bool?> isOwner = Rx<bool?>(null);
|
||||
final Rx<bool?> _isOwner = Rx<bool?>(null);
|
||||
final Rx<FavOrderType> order = FavOrderType.mtime.obs;
|
||||
|
||||
@override
|
||||
bool get isOwner => _isOwner.value ?? false;
|
||||
|
||||
AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
@override
|
||||
@@ -57,27 +114,16 @@ class FavDetailController
|
||||
if (isRefresh) {
|
||||
FavDetailData data = response.response;
|
||||
folderInfo.value = data.info!;
|
||||
isOwner.value = data.info?.mid == accountService.mid;
|
||||
_isOwner.value = data.info?.mid == accountService.mid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> onCancelFav(int index, int id, int type) async {
|
||||
var result = await FavHttp.favVideo(
|
||||
resources: '$id:$type',
|
||||
delIds: mediaId.toString(),
|
||||
);
|
||||
if (result['status']) {
|
||||
folderInfo
|
||||
..value.mediaCount -= 1
|
||||
..refresh();
|
||||
loadingState
|
||||
..value.data!.removeAt(index)
|
||||
..refresh();
|
||||
SmartDialog.showToast('取消收藏');
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
@override
|
||||
void onRemove(int count) {
|
||||
folderInfo
|
||||
..value.mediaCount -= count
|
||||
..refresh();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -89,31 +135,6 @@ class FavDetailController
|
||||
order: order.value,
|
||||
);
|
||||
|
||||
@override
|
||||
void onConfirm() {
|
||||
showConfirmDialog(
|
||||
context: Get.context!,
|
||||
content: '确认删除所选收藏吗?',
|
||||
title: '提示',
|
||||
onConfirm: () async {
|
||||
final checked = allChecked.toSet();
|
||||
var result = await FavHttp.favVideo(
|
||||
resources: checked.map((item) => '${item.id}:${item.type}').join(','),
|
||||
delIds: mediaId.toString(),
|
||||
);
|
||||
if (result['status']) {
|
||||
afterDelete(checked);
|
||||
folderInfo
|
||||
..value.mediaCount -= checked.length
|
||||
..refresh();
|
||||
SmartDialog.showToast('取消收藏');
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void toViewPlayAll() {
|
||||
if (loadingState.value.isSuccess) {
|
||||
List<FavDetailItemModel>? list = loadingState.value.data;
|
||||
@@ -126,22 +147,7 @@ class FavDetailController
|
||||
if (element.bvid != list.first.bvid) {
|
||||
SmartDialog.showToast('已跳过不支持播放的视频');
|
||||
}
|
||||
final folderInfo = this.folderInfo.value;
|
||||
PageUtils.toVideoPage(
|
||||
bvid: element.bvid,
|
||||
cid: element.ugc!.firstCid!,
|
||||
cover: element.cover,
|
||||
title: element.title,
|
||||
extraArguments: {
|
||||
'sourceType': SourceType.fav,
|
||||
'mediaId': folderInfo.id,
|
||||
'oid': element.id,
|
||||
'favTitle': folderInfo.title,
|
||||
'count': folderInfo.mediaCount,
|
||||
'desc': true,
|
||||
'isOwner': isOwner.value ?? false,
|
||||
},
|
||||
);
|
||||
onViewFav(element, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -191,4 +197,25 @@ class FavDetailController
|
||||
Get.to(FavSortPage(favDetailController: this));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onViewFav(FavDetailItemModel item, int? index) {
|
||||
final folder = folderInfo.value;
|
||||
PageUtils.toVideoPage(
|
||||
bvid: item.bvid,
|
||||
cid: item.ugc!.firstCid!,
|
||||
cover: item.cover,
|
||||
title: item.title,
|
||||
extraArguments: {
|
||||
'sourceType': SourceType.fav,
|
||||
'mediaId': folder.id,
|
||||
'oid': item.id,
|
||||
'favTitle': folder.title,
|
||||
'count': folder.mediaCount,
|
||||
'desc': true,
|
||||
if (index != null) 'isContinuePlaying': index != 0,
|
||||
'isOwner': isOwner,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||
@@ -8,7 +7,6 @@ import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/fav.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/fav_order_type.dart';
|
||||
import 'package:PiliPlus/models/common/video/source_type.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_detail/data.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_detail/media.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_folder/list.dart';
|
||||
@@ -17,7 +15,6 @@ import 'package:PiliPlus/pages/fav_detail/controller.dart';
|
||||
import 'package:PiliPlus/pages/fav_detail/widget/fav_video_card.dart';
|
||||
import 'package:PiliPlus/utils/fav_util.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/request_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -156,7 +153,7 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
||||
'mediaId': int.parse(mediaId),
|
||||
'title': folderInfo.title,
|
||||
'count': folderInfo.mediaCount,
|
||||
'isOwner': _favDetailController.isOwner.value ?? false,
|
||||
'isOwner': _favDetailController.isOwner,
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -198,7 +195,7 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
||||
PopupMenuButton(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
itemBuilder: (context) {
|
||||
final isOwner = _favDetailController.isOwner.value ?? false;
|
||||
final isOwner = _favDetailController.isOwner;
|
||||
final folderInfo = _favDetailController.folderInfo.value;
|
||||
return [
|
||||
if (isOwner) ...[
|
||||
@@ -373,7 +370,7 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
||||
right: 6,
|
||||
top: 6,
|
||||
child: Obx(() {
|
||||
if (_favDetailController.isOwner.value != false) {
|
||||
if (_favDetailController.isOwner) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
bool isFav = folderInfo.favState == 1;
|
||||
@@ -485,113 +482,11 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
final isOwner = _favDetailController.isOwner.value ?? false;
|
||||
FavDetailItemModel item = response[index];
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: FavVideoCardH(
|
||||
item: item,
|
||||
onDelFav: isOwner
|
||||
? () => _favDetailController.onCancelFav(
|
||||
index,
|
||||
item.id!,
|
||||
item.type!,
|
||||
)
|
||||
: null,
|
||||
onViewFav: () {
|
||||
final folderInfo =
|
||||
_favDetailController.folderInfo.value;
|
||||
PageUtils.toVideoPage(
|
||||
bvid: item.bvid,
|
||||
cid: item.ugc!.firstCid!,
|
||||
cover: item.cover,
|
||||
title: item.title,
|
||||
extraArguments: {
|
||||
'sourceType': SourceType.fav,
|
||||
'mediaId': folderInfo.id,
|
||||
'oid': item.id,
|
||||
'favTitle': folderInfo.title,
|
||||
'count': folderInfo.mediaCount,
|
||||
'desc': true,
|
||||
'isContinuePlaying': index != 0,
|
||||
'isOwner': isOwner,
|
||||
},
|
||||
);
|
||||
},
|
||||
onTap: enableMultiSelect
|
||||
? () => _favDetailController.onSelect(item)
|
||||
: null,
|
||||
onLongPress: isOwner
|
||||
? () {
|
||||
if (!enableMultiSelect) {
|
||||
_favDetailController
|
||||
.enableMultiSelect
|
||||
.value =
|
||||
true;
|
||||
_favDetailController.onSelect(item);
|
||||
}
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
left: 12,
|
||||
bottom: 5,
|
||||
child: IgnorePointer(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
AnimatedOpacity(
|
||||
opacity: item.checked == true ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
height: constraints.maxHeight,
|
||||
width:
|
||||
constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: Colors.black.withValues(
|
||||
alpha: 0.6,
|
||||
),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: item.checked == true ? 1 : 0,
|
||||
duration: const Duration(
|
||||
milliseconds: 250,
|
||||
),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStateProperty.all(
|
||||
EdgeInsets.zero,
|
||||
),
|
||||
backgroundColor:
|
||||
WidgetStatePropertyAll(
|
||||
theme.colorScheme.surface
|
||||
.withValues(alpha: 0.8),
|
||||
),
|
||||
),
|
||||
onPressed: null,
|
||||
icon: Icon(
|
||||
Icons.done_all_outlined,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
return FavVideoCardH(
|
||||
item: item,
|
||||
index: index,
|
||||
ctr: _favDetailController,
|
||||
);
|
||||
},
|
||||
childCount: response!.length + 1,
|
||||
|
||||
@@ -3,10 +3,12 @@ import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/button/icon_button.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/select_mask.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/models/common/badge_type.dart';
|
||||
import 'package:PiliPlus/models/common/stat_type.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_detail/media.dart';
|
||||
import 'package:PiliPlus/pages/fav_detail/controller.dart';
|
||||
import 'package:PiliPlus/utils/date_util.dart';
|
||||
import 'package:PiliPlus/utils/duration_util.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
@@ -16,55 +18,58 @@ import 'package:get/get.dart';
|
||||
// 收藏视频卡片 - 水平布局
|
||||
class FavVideoCardH extends StatelessWidget {
|
||||
final FavDetailItemModel item;
|
||||
final GestureTapCallback? onTap;
|
||||
final GestureLongPressCallback? onLongPress;
|
||||
final VoidCallback? onDelFav;
|
||||
final VoidCallback? onViewFav;
|
||||
final bool? isSort;
|
||||
final int? index;
|
||||
final BaseFavController? ctr;
|
||||
|
||||
const FavVideoCardH({
|
||||
super.key,
|
||||
required this.item,
|
||||
this.onDelFav,
|
||||
this.onTap,
|
||||
this.onLongPress,
|
||||
this.onViewFav,
|
||||
this.isSort,
|
||||
});
|
||||
this.index,
|
||||
this.ctr,
|
||||
}) : assert(ctr == null || index != null);
|
||||
|
||||
bool get isSort => ctr == null;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isOwner = !isSort && ctr!.isOwner;
|
||||
late final enableMultiSelect = ctr?.enableMultiSelect.value ?? false;
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
onTap: isSort == true
|
||||
onTap: isSort
|
||||
? null
|
||||
: onTap ??
|
||||
() {
|
||||
if (!const [0, 16].contains(item.attr)) {
|
||||
Get.toNamed('/member?mid=${item.upper?.mid}');
|
||||
return;
|
||||
}
|
||||
: enableMultiSelect
|
||||
? () => ctr!.onSelect(item)
|
||||
: () {
|
||||
if (!const [0, 16].contains(item.attr)) {
|
||||
Get.toNamed('/member?mid=${item.upper?.mid}');
|
||||
return;
|
||||
}
|
||||
|
||||
// pgc
|
||||
if (item.type == 24) {
|
||||
PageUtils.viewPgc(
|
||||
seasonId: item.ogv!.seasonId,
|
||||
epId: item.id,
|
||||
);
|
||||
return;
|
||||
}
|
||||
// pgc
|
||||
if (item.type == 24) {
|
||||
PageUtils.viewPgc(
|
||||
seasonId: item.ogv!.seasonId,
|
||||
epId: item.id,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
onViewFav?.call();
|
||||
},
|
||||
onLongPress: isSort == true
|
||||
ctr!.onViewFav(item, index);
|
||||
},
|
||||
onLongPress: isSort
|
||||
? null
|
||||
: onLongPress ??
|
||||
() => imageSaveDialog(
|
||||
title: item.title,
|
||||
cover: item.cover,
|
||||
bvid: item.bvid,
|
||||
),
|
||||
: isOwner && !enableMultiSelect
|
||||
? () {
|
||||
ctr!.enableMultiSelect.value = true;
|
||||
ctr!.onSelect(item);
|
||||
}
|
||||
: () => imageSaveDialog(
|
||||
title: item.title,
|
||||
cover: item.cover,
|
||||
bvid: item.bvid,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: StyleString.safeSpace,
|
||||
@@ -100,13 +105,20 @@ class FavVideoCardH extends StatelessWidget {
|
||||
bottom: null,
|
||||
left: null,
|
||||
),
|
||||
if (!isSort)
|
||||
Positioned.fill(
|
||||
child: selectMask(
|
||||
Theme.of(context),
|
||||
item.checked == true,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
content(context),
|
||||
content(context, isOwner),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -114,7 +126,7 @@ class FavVideoCardH extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget content(BuildContext context) {
|
||||
Widget content(BuildContext context, bool isOwner) {
|
||||
final theme = Theme.of(context);
|
||||
return Expanded(
|
||||
child: Stack(
|
||||
@@ -170,7 +182,7 @@ class FavVideoCardH extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (onDelFav != null)
|
||||
if (isOwner)
|
||||
Positioned(
|
||||
right: 0,
|
||||
bottom: -8,
|
||||
@@ -197,7 +209,7 @@ class FavVideoCardH extends StatelessWidget {
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
onDelFav!();
|
||||
ctr!.onCancelFav(index!, item.id!, item.type!);
|
||||
},
|
||||
child: const Text('确定取消'),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user