mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: unify fav & coin of video & pgc (#916)
This commit is contained in:
committed by
GitHub
parent
e945daba3a
commit
05c9269531
@@ -1,11 +1,17 @@
|
||||
import 'package:PiliPlus/http/fav.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_folder/data.dart';
|
||||
import 'package:PiliPlus/models_new/video/video_detail/stat_detail.dart';
|
||||
import 'package:PiliPlus/models_new/video/video_tag/data.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -29,9 +35,119 @@ abstract class CommonIntroController extends GetxController {
|
||||
|
||||
AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
Future queryVideoInFolder();
|
||||
(Object, int) getFavRidType();
|
||||
|
||||
Future<void> actionFavVideo({bool isQuick = false});
|
||||
StatDetail? getStat();
|
||||
|
||||
Future<LoadingState<FavFolderData>> queryVideoInFolder() async {
|
||||
favIds = null;
|
||||
final (rid, type) = getFavRidType();
|
||||
final result = await FavHttp.videoInFolder(
|
||||
mid: accountService.mid,
|
||||
rid: rid,
|
||||
type: type,
|
||||
);
|
||||
if (result.isSuccess) {
|
||||
favFolderData.value = result.data;
|
||||
favIds = result.data.list
|
||||
?.where((item) => item.favState == 1)
|
||||
.map((item) => item.id)
|
||||
.toSet();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> actionFavVideo({bool isQuick = false}) async {
|
||||
final (rid, type) = getFavRidType();
|
||||
// 收藏至默认文件夹
|
||||
if (isQuick) {
|
||||
SmartDialog.showLoading(msg: '请求中');
|
||||
queryVideoInFolder().then((res) async {
|
||||
if (res.isSuccess) {
|
||||
final hasFav = this.hasFav.value;
|
||||
var result = hasFav
|
||||
? await FavHttp.unfavAll(rid: rid, type: type)
|
||||
: await FavHttp.favVideo(
|
||||
resources: '$rid:$type',
|
||||
addIds: favFolderId.toString(),
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (result['status']) {
|
||||
getStat()!.favorite += hasFav ? -1 : 1;
|
||||
this.hasFav.value = !hasFav;
|
||||
SmartDialog.showToast('✅ 快速收藏/取消收藏成功');
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
} else {
|
||||
SmartDialog.dismiss();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
List<int?> addMediaIdsNew = [];
|
||||
List<int?> delMediaIdsNew = [];
|
||||
try {
|
||||
for (var i in favFolderData.value.list!) {
|
||||
bool isFaved = favIds?.contains(i.id) == true;
|
||||
if (i.favState == 1) {
|
||||
if (!isFaved) {
|
||||
addMediaIdsNew.add(i.id);
|
||||
}
|
||||
} else {
|
||||
if (isFaved) {
|
||||
delMediaIdsNew.add(i.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) debugPrint(e.toString());
|
||||
}
|
||||
SmartDialog.showLoading(msg: '请求中');
|
||||
var result = await FavHttp.favVideo(
|
||||
resources: '$rid:$type',
|
||||
addIds: addMediaIdsNew.join(','),
|
||||
delIds: delMediaIdsNew.join(','),
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (result['status']) {
|
||||
Get.back();
|
||||
final newVal =
|
||||
addMediaIdsNew.isNotEmpty || favIds?.length != delMediaIdsNew.length;
|
||||
if (hasFav.value != newVal) {
|
||||
getStat()!.favorite += newVal ? 1 : -1;
|
||||
hasFav.value = newVal;
|
||||
}
|
||||
SmartDialog.showToast('操作成功');
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> coinVideo(int coin, [bool selectLike = false]) async {
|
||||
final stat = getStat();
|
||||
if (stat == null) {
|
||||
return;
|
||||
}
|
||||
var res = await VideoHttp.coinVideo(
|
||||
bvid: bvid,
|
||||
multiply: coin,
|
||||
selectLike: selectLike ? 1 : 0,
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast('投币成功');
|
||||
coinNum.value += coin;
|
||||
GlobalData().afterCoin(coin);
|
||||
stat.coin += coin;
|
||||
if (selectLike && !hasLike.value) {
|
||||
stat.like++;
|
||||
hasLike.value = true;
|
||||
}
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
late final enableQuickFav = Pref.enableQuickFav;
|
||||
int? quickFavId;
|
||||
|
||||
Reference in New Issue
Block a user