feat: 快速收藏

This commit is contained in:
guozhigq
2023-08-30 11:04:01 +08:00
parent 108c37f0d7
commit b485399517
5 changed files with 83 additions and 11 deletions

View File

@ -55,6 +55,12 @@ class _ExtraSettingState extends State<ExtraSetting> {
defaultVal: true, defaultVal: true,
callFn: (val) => {SmartDialog.showToast('下次启动时生效')}, callFn: (val) => {SmartDialog.showToast('下次启动时生效')},
), ),
const SetSwitchItem(
title: '快速收藏',
subTitle: '点按收藏至默认,长按选择文件夹',
setKey: SettingBoxKey.enableQuickFav,
defaultVal: false,
),
ListTile( ListTile(
dense: false, dense: false,
title: Text('评论展示', style: titleStyle), title: Text('评论展示', style: titleStyle),

View File

@ -144,6 +144,8 @@ class VideoIntroController extends GetxController {
// 获取收藏状态 // 获取收藏状态
Future queryHasFavVideo() async { Future queryHasFavVideo() async {
/// fix 延迟查询
await Future.delayed(const Duration(milliseconds: 200));
var result = await VideoHttp.hasFavVideo(aid: IdUtils.bv2av(bvid)); var result = await VideoHttp.hasFavVideo(aid: IdUtils.bv2av(bvid));
if (result['status']) { if (result['status']) {
hasFav.value = result["data"]['favoured']; hasFav.value = result["data"]['favoured'];
@ -275,7 +277,27 @@ class VideoIntroController extends GetxController {
} }
// (取消)收藏 // (取消)收藏
Future actionFavVideo() async { Future actionFavVideo({type = 'choose'}) async {
// 收藏至默认文件夹
if (type == 'default') {
await queryVideoInFolder();
int defaultFolderId = favFolderData.value.list!.first.id!;
int favStatus = favFolderData.value.list!.first.favState!;
print('favStatus: $favStatus');
var result = await VideoHttp.favVideo(
aid: IdUtils.bv2av(bvid),
addIds: favStatus == 0 ? '$defaultFolderId' : '',
delIds: favStatus == 1 ? '$defaultFolderId' : '',
);
if (result['status']) {
if (result['data']['prompt']) {
// 重新获取收藏状态
await queryHasFavVideo();
SmartDialog.showToast('✅ 操作成功');
}
}
return;
}
try { try {
for (var i in favFolderData.value.list!.toList()) { for (var i in favFolderData.value.list!.toList()) {
if (i.favState == 1) { if (i.favState == 1) {
@ -288,17 +310,19 @@ class VideoIntroController extends GetxController {
// ignore: avoid_print // ignore: avoid_print
print(e); print(e);
} }
SmartDialog.showLoading(msg: '请求中');
var result = await VideoHttp.favVideo( var result = await VideoHttp.favVideo(
aid: IdUtils.bv2av(bvid), aid: IdUtils.bv2av(bvid),
addIds: addMediaIdsNew.join(','), addIds: addMediaIdsNew.join(','),
delIds: delMediaIdsNew.join(',')); delIds: delMediaIdsNew.join(','));
SmartDialog.dismiss();
if (result['status']) { if (result['status']) {
if (result['data']['prompt']) { if (result['data']['prompt']) {
addMediaIdsNew = []; addMediaIdsNew = [];
delMediaIdsNew = []; delMediaIdsNew = [];
Get.back(); Get.back();
// 重新获取收藏状态 // 重新获取收藏状态
queryHasFavVideo(); await queryHasFavVideo();
SmartDialog.showToast('✅ 操作成功'); SmartDialog.showToast('✅ 操作成功');
} }
} }

View File

@ -122,6 +122,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
late final Map<dynamic, dynamic> videoItem; late final Map<dynamic, dynamic> videoItem;
Box localCache = GStrorage.localCache; Box localCache = GStrorage.localCache;
Box setting = GStrorage.setting;
late double sheetHeight; late double sheetHeight;
late final bool loadingStatus; // 加载状态 late final bool loadingStatus; // 加载状态
@ -150,19 +151,50 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
} }
// 收藏 // 收藏
showFavBottomSheet() { showFavBottomSheet({type = 'tap'}) {
if (videoIntroController.userInfo == null) { if (videoIntroController.userInfo == null) {
SmartDialog.showToast('账号未登录'); SmartDialog.showToast('账号未登录');
return; return;
} }
showModalBottomSheet( bool enableDragQuickFav =
context: context, setting.get(SettingBoxKey.enableQuickFav, defaultValue: false);
useRootNavigator: true, // 快速收藏 &
isScrollControlled: true, // 点按 收藏至默认文件夹
builder: (context) { // 长按选择文件夹
return FavPanel(ctr: videoIntroController); if (enableDragQuickFav) {
}, if (type == 'tap') {
); if (!videoIntroController.hasFav.value) {
videoIntroController.actionFavVideo(type: 'default');
} else {
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (context) {
return FavPanel(ctr: videoIntroController);
},
);
}
} else {
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (context) {
return FavPanel(ctr: videoIntroController);
},
);
}
} else if (type != 'longPress') {
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (context) {
return FavPanel(ctr: videoIntroController);
},
);
}
} }
// 视频介绍 // 视频介绍
@ -510,6 +542,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
() => ActionRowItem( () => ActionRowItem(
icon: const Icon(FontAwesomeIcons.heart), icon: const Icon(FontAwesomeIcons.heart),
onTap: () => showFavBottomSheet(), onTap: () => showFavBottomSheet(),
onLongPress: () => showFavBottomSheet(type: 'longPress'),
selectStatus: videoIntroController.hasFav.value, selectStatus: videoIntroController.hasFav.value,
loadingStatus: loadingStatus, loadingStatus: loadingStatus,
text: !loadingStatus text: !loadingStatus

View File

@ -8,6 +8,7 @@ class ActionRowItem extends StatelessWidget {
final bool? loadingStatus; final bool? loadingStatus;
final String? text; final String? text;
final bool selectStatus; final bool selectStatus;
final Function? onLongPress;
const ActionRowItem({ const ActionRowItem({
Key? key, Key? key,
@ -17,6 +18,7 @@ class ActionRowItem extends StatelessWidget {
this.loadingStatus, this.loadingStatus,
this.text, this.text,
this.selectStatus = false, this.selectStatus = false,
this.onLongPress,
}) : super(key: key); }) : super(key: key);
@override @override
@ -32,6 +34,12 @@ class ActionRowItem extends StatelessWidget {
feedBack(), feedBack(),
onTap!(), onTap!(),
}, },
onLongPress: () {
feedBack();
if (onLongPress != null) {
onLongPress!();
}
},
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(15, 7, 15, 7), padding: const EdgeInsets.fromLTRB(15, 7, 15, 7),
child: Row( child: Row(

View File

@ -108,6 +108,7 @@ class SettingBoxKey {
static const String replySortType = 'replySortType'; static const String replySortType = 'replySortType';
static const String defaultDynamicType = 'defaultDynamicType'; static const String defaultDynamicType = 'defaultDynamicType';
static const String enableHotKey = 'enableHotKey'; static const String enableHotKey = 'enableHotKey';
static const String enableQuickFav = 'enableQuickFav';
/// 外观 /// 外观
static const String themeMode = 'themeMode'; static const String themeMode = 'themeMode';