feat: 快速收藏
This commit is contained in:
@ -55,6 +55,12 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
||||
defaultVal: true,
|
||||
callFn: (val) => {SmartDialog.showToast('下次启动时生效')},
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '快速收藏',
|
||||
subTitle: '点按收藏至默认,长按选择文件夹',
|
||||
setKey: SettingBoxKey.enableQuickFav,
|
||||
defaultVal: false,
|
||||
),
|
||||
ListTile(
|
||||
dense: false,
|
||||
title: Text('评论展示', style: titleStyle),
|
||||
|
@ -144,6 +144,8 @@ class VideoIntroController extends GetxController {
|
||||
|
||||
// 获取收藏状态
|
||||
Future queryHasFavVideo() async {
|
||||
/// fix 延迟查询
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
var result = await VideoHttp.hasFavVideo(aid: IdUtils.bv2av(bvid));
|
||||
if (result['status']) {
|
||||
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 {
|
||||
for (var i in favFolderData.value.list!.toList()) {
|
||||
if (i.favState == 1) {
|
||||
@ -288,17 +310,19 @@ class VideoIntroController extends GetxController {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
}
|
||||
SmartDialog.showLoading(msg: '请求中');
|
||||
var result = await VideoHttp.favVideo(
|
||||
aid: IdUtils.bv2av(bvid),
|
||||
addIds: addMediaIdsNew.join(','),
|
||||
delIds: delMediaIdsNew.join(','));
|
||||
SmartDialog.dismiss();
|
||||
if (result['status']) {
|
||||
if (result['data']['prompt']) {
|
||||
addMediaIdsNew = [];
|
||||
delMediaIdsNew = [];
|
||||
Get.back();
|
||||
// 重新获取收藏状态
|
||||
queryHasFavVideo();
|
||||
await queryHasFavVideo();
|
||||
SmartDialog.showToast('✅ 操作成功');
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +122,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
late final Map<dynamic, dynamic> videoItem;
|
||||
|
||||
Box localCache = GStrorage.localCache;
|
||||
Box setting = GStrorage.setting;
|
||||
late double sheetHeight;
|
||||
|
||||
late final bool loadingStatus; // 加载状态
|
||||
@ -150,19 +151,50 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
// 收藏
|
||||
showFavBottomSheet() {
|
||||
showFavBottomSheet({type = 'tap'}) {
|
||||
if (videoIntroController.userInfo == null) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
builder: (context) {
|
||||
return FavPanel(ctr: videoIntroController);
|
||||
},
|
||||
);
|
||||
bool enableDragQuickFav =
|
||||
setting.get(SettingBoxKey.enableQuickFav, defaultValue: false);
|
||||
// 快速收藏 &
|
||||
// 点按 收藏至默认文件夹
|
||||
// 长按选择文件夹
|
||||
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(
|
||||
icon: const Icon(FontAwesomeIcons.heart),
|
||||
onTap: () => showFavBottomSheet(),
|
||||
onLongPress: () => showFavBottomSheet(type: 'longPress'),
|
||||
selectStatus: videoIntroController.hasFav.value,
|
||||
loadingStatus: loadingStatus,
|
||||
text: !loadingStatus
|
||||
|
@ -8,6 +8,7 @@ class ActionRowItem extends StatelessWidget {
|
||||
final bool? loadingStatus;
|
||||
final String? text;
|
||||
final bool selectStatus;
|
||||
final Function? onLongPress;
|
||||
|
||||
const ActionRowItem({
|
||||
Key? key,
|
||||
@ -17,6 +18,7 @@ class ActionRowItem extends StatelessWidget {
|
||||
this.loadingStatus,
|
||||
this.text,
|
||||
this.selectStatus = false,
|
||||
this.onLongPress,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -32,6 +34,12 @@ class ActionRowItem extends StatelessWidget {
|
||||
feedBack(),
|
||||
onTap!(),
|
||||
},
|
||||
onLongPress: () {
|
||||
feedBack();
|
||||
if (onLongPress != null) {
|
||||
onLongPress!();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(15, 7, 15, 7),
|
||||
child: Row(
|
||||
|
@ -108,6 +108,7 @@ class SettingBoxKey {
|
||||
static const String replySortType = 'replySortType';
|
||||
static const String defaultDynamicType = 'defaultDynamicType';
|
||||
static const String enableHotKey = 'enableHotKey';
|
||||
static const String enableQuickFav = 'enableQuickFav';
|
||||
|
||||
/// 外观
|
||||
static const String themeMode = 'themeMode';
|
||||
|
Reference in New Issue
Block a user