feat: get/check coin

Closes #661

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-11 17:20:25 +08:00
parent 9a6ba82467
commit 3801bdf9d7
12 changed files with 235 additions and 225 deletions

View File

@@ -7,12 +7,12 @@ import 'package:PiliPlus/http/member.dart';
import 'package:PiliPlus/pages/dynamics/repost_dyn_panel.dart';
import 'package:PiliPlus/pages/video/detail/introduction/pay_coins_page.dart';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/global_data.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:expandable/expandable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
import 'package:PiliPlus/http/constants.dart';
import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/http/video.dart';
@@ -58,8 +58,10 @@ class VideoIntroController extends GetxController
RxBool hasLike = false.obs;
// 是否点踩
RxBool hasDislike = false.obs;
// 投币数量
final RxInt _coinNum = 0.obs;
// 是否投币
RxBool hasCoin = false.obs;
bool get hasCoin => _coinNum.value != 0;
// 是否收藏
RxBool hasFav = false.obs;
// 是否稍后再看
@@ -179,13 +181,6 @@ class VideoIntroController extends GetxController
queryVideoIntroData.value = result;
if (isLogin) {
queryAllStatus();
// // 获取点赞状态
// queryHasLikeVideo();
// // 获取投币状态
// queryHasCoinVideo();
// // 获取收藏状态
// queryHasFavVideo();
// //
queryFollowStatus();
}
}
@@ -194,7 +189,6 @@ class VideoIntroController extends GetxController
var result = await UserHttp.videoTags(bvid: bvid);
if (result['status']) {
videoTags = result['data'];
// debugPrint('tags: ${result['data']}');
}
}
@@ -234,40 +228,11 @@ class VideoIntroController extends GetxController
var data = result['data'];
hasLike.value = data['like'];
hasDislike.value = data['dislike'];
hasCoin.value = data['coin'] != 0;
_coinNum.value = data['coin'];
hasFav.value = data['favorite'];
// followStatus['attritube'] = data['attention'] ? 2 : 0;
}
}
// // 获取点赞状态
// Future queryHasLikeVideo() async {
// var result = await VideoHttp.hasLikeVideo(bvid: bvid);
// // data num 被点赞标志 0未点赞 1已点赞 2已点踩
// hasLike.value = result["data"] == 1;
// hasDislike.value = result["data"] == 2;
// }
// // 获取投币状态
// Future queryHasCoinVideo() async {
// var result = await VideoHttp.hasCoinVideo(bvid: bvid);
// if (result['status']) {
// hasCoin.value = result["data"]['multiply'] != 0;
// }
// }
// // 获取收藏状态
// 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'];
// } else {
// hasFav.value = false;
// }
// }
// 一键三连
Future actionOneThree() async {
feedBack();
@@ -275,7 +240,7 @@ class VideoIntroController extends GetxController
SmartDialog.showToast('账号未登录');
return;
}
if (hasLike.value && hasCoin.value && hasFav.value) {
if (hasLike.value && hasCoin && hasFav.value) {
// 已点赞、投币、收藏
SmartDialog.showToast('已三连');
return false;
@@ -283,7 +248,10 @@ class VideoIntroController extends GetxController
var result = await VideoHttp.oneThree(bvid: bvid);
if (result['status']) {
hasLike.value = result["data"]["like"];
hasCoin.value = result["data"]["coin"];
if (result["data"]["coin"]) {
_coinNum.value = 2;
GlobalData().afterCoin(2);
}
hasFav.value = result["data"]["fav"];
SmartDialog.showToast('三连成功');
} else {
@@ -362,7 +330,8 @@ class VideoIntroController extends GetxController
);
if (res['status']) {
SmartDialog.showToast('投币成功');
hasCoin.value = true;
_coinNum.value += coin;
GlobalData().afterCoin(coin);
videoDetail.value.stat!.coin = videoDetail.value.stat!.coin! + coin;
if (selectLike && hasLike.value.not) {
hasLike.value = true;
@@ -380,60 +349,23 @@ class VideoIntroController extends GetxController
return;
}
Navigator.of(Get.context!).push(
GetDialogRoute(
pageBuilder: (buildContext, animation, secondaryAnimation) {
return PayCoinsPage(
callback: coinVideo,
copyright: (queryVideoIntroData.value['data'] as VideoDetailData?)
?.copyright ??
1,
);
},
transitionDuration: const Duration(milliseconds: 225),
transitionBuilder: (context, animation, secondaryAnimation, child) {
const begin = 0.0;
const end = 1.0;
const curve = Curves.linear;
if (_coinNum.value >= 2) {
SmartDialog.showToast('超过投币上限啦~');
return;
}
var tween = Tween<double>(begin: begin, end: end)
.chain(CurveTween(curve: curve));
if (GlobalData().coins != null && GlobalData().coins! < 1) {
SmartDialog.showToast('硬币不足');
return;
}
return FadeTransition(
opacity: animation.drive(tween),
child: child,
);
},
),
PayCoinsPage.toPayCoinsPage(
onPayCoin: coinVideo,
copyright:
(queryVideoIntroData.value['data'] as VideoDetailData?)?.copyright ??
1,
hasCoin: _coinNum.value == 1,
);
// showDialog(
// context: Get.context!,
// builder: (context) {
// return AlertDialog(
// title: const Text('选择投币个数'),
// contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
// actions: [
// TextButton(
// onPressed: () => Get.back(),
// child: Text('取消',
// style: TextStyle(
// color: Theme.of(context).colorScheme.outline))),
// TextButton(
// onPressed: () async {
// coinVideo(1);
// Get.back();
// },
// child: const Text('投 1 枚')),
// TextButton(
// onPressed: () async {
// coinVideo(2);
// Get.back();
// },
// child: const Text('投 2 枚'))
// ],
// );
// },
// );
}
// (取消)收藏

View File

@@ -2,22 +2,58 @@ import 'dart:async';
import 'dart:math';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/global_data.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
class PayCoinsPage extends StatefulWidget {
const PayCoinsPage({
super.key,
required this.callback,
required this.onPayCoin,
this.copyright = 1,
this.hasCoin = false,
});
final Function callback;
final Function(int coin, bool coinWithLike) onPayCoin;
final int copyright;
final bool hasCoin;
@override
State<PayCoinsPage> createState() => _PayCoinsPageState();
static toPayCoinsPage({
required Function(int coin, bool coinWithLike) onPayCoin,
int copyright = 1,
bool hasCoin = false,
}) async {
Navigator.of(Get.context!).push(
GetDialogRoute(
pageBuilder: (buildContext, animation, secondaryAnimation) {
return PayCoinsPage(
onPayCoin: onPayCoin,
copyright: copyright,
hasCoin: hasCoin,
);
},
transitionDuration: const Duration(milliseconds: 225),
transitionBuilder: (context, animation, secondaryAnimation, child) {
const begin = 0.0;
const end = 1.0;
const curve = Curves.linear;
var tween = Tween<double>(begin: begin, end: end)
.chain(CurveTween(curve: curve));
return FadeTransition(
opacity: animation.drive(tween),
child: child,
);
},
),
);
}
}
class _PayCoinsPageState extends State<PayCoinsPage>
@@ -29,6 +65,48 @@ class _PayCoinsPageState extends State<PayCoinsPage>
int get _index => _controller.hasClients ? _controller.page?.round() ?? 0 : 0;
num? get _coins => GlobalData().coins;
bool get _canPay {
if (_index == 1 && widget.hasCoin) {
return false;
}
if (_coins == null) {
return true;
}
if (_index == 0 && _coins! >= 1) {
return true;
}
if (_index == 1 && _coins! >= 2) {
return true;
}
return false;
}
Color _getColorFilter(int index) {
if (index == 1 && widget.hasCoin) {
return Colors.black45;
}
if (_coins == null) {
return Colors.transparent;
}
if (index == 0 && _coins == 0) {
return Colors.black45;
}
if (index == 1 && _coins! < 2) {
return Colors.black45;
}
return Colors.transparent;
}
String get _getImage {
if (!_canPay) {
return 'assets/images/paycoins/ic_22_not_enough_pay.png';
}
return _index == 0
? 'assets/images/paycoins/ic_22_mario.png'
: 'assets/images/paycoins/ic_22_gun_sister.png';
}
late AnimationController _slide22Controller;
late AnimationController _scale22Controller;
late AnimationController _coinSlideController;
@@ -162,6 +240,7 @@ class _PayCoinsPageState extends State<PayCoinsPage>
height: 100,
child: PageView.builder(
key: PageStorageKey('PageView'),
physics: const ClampingScrollPhysics(),
itemCount: widget.copyright == 1 ? 2 : 1,
controller: _controller,
onPageChanged: (index) => setState(() {
@@ -183,44 +262,53 @@ class _PayCoinsPageState extends State<PayCoinsPage>
child: SizedBox(
height: 70 + (factor * 30),
width: 70 + (factor * 30),
child: Stack(
alignment: Alignment.center,
children: [
SlideTransition(
position:
_boxAnimController.drive(
Tween(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -0.2),
child: ColorFiltered(
colorFilter: ColorFilter.mode(
_getColorFilter(index),
BlendMode.srcATop,
),
child: Stack(
alignment: Alignment.center,
children: [
SlideTransition(
position:
_boxAnimController.drive(
Tween(
begin:
const Offset(0.0, 0.0),
end:
const Offset(0.0, -0.2),
),
),
),
child: Image.asset(
'assets/images/paycoins/ic_pay_coins_box.png',
),
),
SlideTransition(
position:
_coinSlideController.drive(
Tween(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -2),
),
),
child: FadeTransition(
opacity: Tween<double>(
begin: 1, end: 0)
.animate(
_coinFadeController),
child: Image.asset(
height: 35 + (factor * 15),
width: 35 + (factor * 15),
index == 0
? 'assets/images/paycoins/ic_coins_one.png'
: 'assets/images/paycoins/ic_coins_two.png',
'assets/images/paycoins/ic_pay_coins_box.png',
),
),
),
],
SlideTransition(
position:
_coinSlideController.drive(
Tween(
begin:
const Offset(0.0, 0.0),
end: const Offset(0.0, -2),
),
),
child: FadeTransition(
opacity: Tween<double>(
begin: 1, end: 0)
.animate(
_coinFadeController),
child: Image.asset(
height: 35 + (factor * 15),
width: 35 + (factor * 15),
index == 0
? 'assets/images/paycoins/ic_coins_one.png'
: 'assets/images/paycoins/ic_coins_two.png',
),
),
),
],
),
),
),
),
@@ -265,8 +353,9 @@ class _PayCoinsPageState extends State<PayCoinsPage>
height: 155,
child: Center(
child: GestureDetector(
onTap: _onPayCoin,
onPanUpdate: (e) => _handlePanUpdate(e, true),
onTap: _canPay ? _onPayCoin : null,
onPanUpdate:
_canPay ? (e) => _handlePanUpdate(e, true) : null,
child: ScaleTransition(
scale: _scale22Controller.drive(
Tween(begin: 1, end: 1.1),
@@ -281,11 +370,7 @@ class _PayCoinsPageState extends State<PayCoinsPage>
child: SizedBox(
width: 110,
height: 155,
child: Image.asset(
_index == 0
? 'assets/images/paycoins/ic_22_mario.png'
: 'assets/images/paycoins/ic_22_gun_sister.png',
),
child: Image.asset(_getImage),
),
),
),
@@ -293,6 +378,15 @@ class _PayCoinsPageState extends State<PayCoinsPage>
),
),
),
if (_coins != null || widget.hasCoin) ...[
const SizedBox(height: 10),
Center(
child: Text(
'${_coins != null ? '硬币余额:${_coins!.toDouble().toPrecision(1)}' : ''}${widget.hasCoin ? '${_coins != null ? '' : ''}已投1枚硬币' : ''}',
style: TextStyle(color: Colors.white, fontSize: 13),
),
),
],
const SizedBox(height: 10),
Stack(
alignment: Alignment.centerLeft,
@@ -394,7 +488,7 @@ class _PayCoinsPageState extends State<PayCoinsPage>
_coinSlideController.forward().whenComplete(() {
_coinFadeController.forward().whenComplete(() {
Get.back();
widget.callback(_index + 1, _coinWithLike.value);
widget.onPayCoin(_index + 1, _coinWithLike.value);
});
});
});

View File

@@ -926,7 +926,7 @@ class _VideoInfoState extends State<VideoInfo> {
: '-',
needAnim: true,
hasTriple: videoIntroController.hasLike.value &&
videoIntroController.hasCoin.value &&
videoIntroController.hasCoin &&
videoIntroController.hasFav.value,
callBack: (start) {
if (start) {
@@ -958,7 +958,7 @@ class _VideoInfoState extends State<VideoInfo> {
icon: const Icon(FontAwesomeIcons.b),
selectIcon: const Icon(FontAwesomeIcons.b),
onTap: () => handleState(videoIntroController.actionCoinVideo),
selectStatus: videoIntroController.hasCoin.value,
selectStatus: videoIntroController.hasCoin,
loadingStatus: widget.loadingStatus,
semanticsLabel: '投币',
text: !widget.loadingStatus
@@ -1032,7 +1032,7 @@ class _VideoInfoState extends State<VideoInfo> {
() => ActionRowItem(
icon: const Icon(FontAwesomeIcons.b),
onTap: () => handleState(videoIntroController.actionCoinVideo),
selectStatus: videoIntroController.hasCoin.value,
selectStatus: videoIntroController.hasCoin,
loadingStatus: widget.loadingStatus,
text:
!widget.loadingStatus ? videoDetail.stat!.coin!.toString() : '-',

View File

@@ -2300,7 +2300,7 @@ class HeaderControlState extends State<HeaderControl> {
semanticsLabel: '点赞',
needAnim: true,
hasTriple: videoIntroController.hasLike.value &&
videoIntroController.hasCoin.value &&
videoIntroController.hasCoin &&
videoIntroController.hasFav.value,
callBack: (start) {
if (start) {
@@ -2352,8 +2352,7 @@ class HeaderControlState extends State<HeaderControl> {
),
selectIcon: const Icon(FontAwesomeIcons.b),
onTap: videoIntroController.actionCoinVideo,
selectStatus:
videoIntroController.hasCoin.value,
selectStatus: videoIntroController.hasCoin,
semanticsLabel: '投币',
needAnim: true,
),
@@ -2422,7 +2421,7 @@ class HeaderControlState extends State<HeaderControl> {
needAnim: true,
hasTriple:
bangumiIntroController.hasLike.value &&
bangumiIntroController.hasCoin.value &&
bangumiIntroController.hasCoin &&
bangumiIntroController.hasFav.value,
callBack: (start) {
if (start) {
@@ -2455,8 +2454,7 @@ class HeaderControlState extends State<HeaderControl> {
),
selectIcon: const Icon(FontAwesomeIcons.b),
onTap: bangumiIntroController.actionCoinVideo,
selectStatus:
bangumiIntroController.hasCoin.value,
selectStatus: bangumiIntroController.hasCoin,
semanticsLabel: '投币',
needAnim: true,
),