mod: coin with like

Closes #231

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-12 12:32:25 +08:00
parent a4e63fe0e8
commit 3217731486
5 changed files with 240 additions and 153 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -421,14 +421,18 @@ class VideoHttp {
} }
// 投币 // 投币
static Future coinVideo({required String bvid, required int multiply}) async { static Future coinVideo({
required String bvid,
required int multiply,
int selectLike = 0,
}) async {
var res = await Request().post( var res = await Request().post(
Api.coinVideo, Api.coinVideo,
queryParameters: { queryParameters: {
'aid': IdUtils.bv2av(bvid), 'aid': IdUtils.bv2av(bvid),
// 'bvid': bvid, // 'bvid': bvid,
'multiply': multiply, 'multiply': multiply,
'select_like': 0, 'select_like': selectLike,
'access_key': GStorage.localCache 'access_key': GStorage.localCache
.get(LocalCacheKey.accessKey, defaultValue: {})['value'], .get(LocalCacheKey.accessKey, defaultValue: {})['value'],
// 'csrf': await Request.getCsrf(), // 'csrf': await Request.getCsrf(),

View File

@@ -309,16 +309,24 @@ class VideoIntroController extends GetxController
} }
} }
void coinVideo(int coin) async { void coinVideo(int coin, [bool selectLike = false]) async {
if (videoDetail.value.stat?.coin == null) { if (videoDetail.value.stat?.coin == null) {
// not init // not init
return; return;
} }
var res = await VideoHttp.coinVideo(bvid: bvid, multiply: coin); var res = await VideoHttp.coinVideo(
bvid: bvid,
multiply: coin,
selectLike: selectLike ? 1 : 0,
);
if (res['status']) { if (res['status']) {
SmartDialog.showToast('投币成功'); SmartDialog.showToast('投币成功');
hasCoin.value = true; hasCoin.value = true;
videoDetail.value.stat!.coin = videoDetail.value.stat!.coin! + coin; videoDetail.value.stat!.coin = videoDetail.value.stat!.coin! + coin;
if (selectLike && hasLike.value.not) {
hasLike.value = true;
videoDetail.value.stat!.like = videoDetail.value.stat!.like! + 1;
}
} else { } else {
SmartDialog.showToast(res['msg']); SmartDialog.showToast(res['msg']);
} }

View File

@@ -1,6 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:math'; import 'dart:math';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@@ -22,6 +24,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
with TickerProviderStateMixin { with TickerProviderStateMixin {
bool _isPaying = false; bool _isPaying = false;
late final _controller = PageController(viewportFraction: 0.30); late final _controller = PageController(viewportFraction: 0.30);
late final RxBool _coinWithLike = GStorage.coinWithLike.obs;
final _key = GlobalKey();
int get _index => _controller.hasClients ? _controller.page?.round() ?? 0 : 0; int get _index => _controller.hasClients ? _controller.page?.round() ?? 0 : 0;
@@ -96,11 +100,20 @@ class _PayCoinsPageState extends State<PayCoinsPage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) { return LayoutBuilder(builder: (context, constraints) {
return _buildBody(constraints.maxHeight > constraints.maxWidth); bool isV = constraints.maxHeight > constraints.maxWidth;
return isV
? _buildBody(isV)
: Row(
children: [
const Spacer(),
Expanded(child: _buildBody(isV)),
],
);
}); });
} }
Widget _buildBody(isV) => Stack( Widget _buildBody(isV) => Stack(
key: _key,
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
Visibility( Visibility(
@@ -110,168 +123,226 @@ class _PayCoinsPageState extends State<PayCoinsPage>
maintainState: true, maintainState: true,
child: Image.asset(_images[_showThunder ? _imageIndex : 0]), child: Image.asset(_images[_showThunder ? _imageIndex : 0]),
), ),
Column( Align(
mainAxisAlignment: MainAxisAlignment.end, alignment: Alignment.bottomCenter,
children: [ child: GestureDetector(
Row( behavior: HitTestBehavior.opaque,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Visibility( Row(
visible: !_isPaying && widget.copyright == 1, children: [
maintainSize: true, Visibility(
maintainAnimation: true, visible: !_isPaying && widget.copyright == 1,
maintainState: true, maintainSize: true,
child: GestureDetector( maintainAnimation: true,
onTap: _index == 0 maintainState: true,
? null child: GestureDetector(
: () { onTap: _index == 0
_onScroll(0); ? null
}, : () {
child: Padding( _onScroll(0);
padding: const EdgeInsets.only(left: 12), },
child: Image.asset( child: Padding(
width: 16, padding: const EdgeInsets.only(left: 12),
height: 28, child: Image.asset(
_index == 0 width: 16,
? 'assets/images/paycoins/ic_left_disable.png' height: 28,
: 'assets/images/paycoins/ic_left.png', _index == 0
? 'assets/images/paycoins/ic_left_disable.png'
: 'assets/images/paycoins/ic_left.png',
),
),
), ),
), ),
), Expanded(
), child: SizedBox(
Expanded( height: 100,
child: SizedBox( child: PageView.builder(
height: 100, key: PageStorageKey('PageView'),
child: PageView.builder( itemCount: widget.copyright == 1 ? 2 : 1,
itemCount: widget.copyright == 1 ? 2 : 1, controller: _controller,
controller: _controller, onPageChanged: (index) => setState(() {
onPageChanged: (index) => setState(() { _scale();
_scale(); }),
}), itemBuilder: (context, index) {
itemBuilder: (context, index) { return ListenableBuilder(
return ListenableBuilder( listenable: _controller,
listenable: _controller, builder: (context, child) {
builder: (context, child) { double factor = index == 0 ? 1 : 0;
double factor = index == 0 ? 1 : 0; if (_controller
if (_controller.position.hasContentDimensions) { .position.hasContentDimensions) {
factor = 1 - (_controller.page! - index).abs(); factor =
} 1 - (_controller.page! - index).abs();
return Visibility( }
visible: !_isPaying || _index == index, return Visibility(
child: Center( visible: !_isPaying || _index == index,
child: SizedBox( child: Center(
height: 70 + (factor * 30), child: SizedBox(
width: 70 + (factor * 30), height: 70 + (factor * 30),
child: Stack( width: 70 + (factor * 30),
alignment: Alignment.center, child: Stack(
children: [ alignment: Alignment.center,
SlideTransition( children: [
position: _boxAnimController.drive( SlideTransition(
Tween( position:
begin: const Offset(0.0, 0.0), _boxAnimController.drive(
end: const Offset(0.0, -0.2), 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(
child: Image.asset( position:
'assets/images/paycoins/ic_pay_coins_box.png', _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',
),
),
),
],
), ),
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',
),
),
),
],
), ),
), );
), },
); );
}, },
),
),
),
Visibility(
visible: !_isPaying && widget.copyright == 1,
maintainSize: true,
maintainAnimation: true,
maintainState: true,
child: GestureDetector(
onTap: _index == 1
? null
: () {
_onScroll(1);
},
child: Padding(
padding: const EdgeInsets.only(right: 12),
child: Image.asset(
width: 16,
height: 28,
_index == 1
? 'assets/images/paycoins/ic_right_disable.png'
: 'assets/images/paycoins/ic_right.png',
),
),
),
),
],
),
SizedBox(height: isV ? 25 : 10),
GestureDetector(
behavior: HitTestBehavior.opaque,
onPanUpdate: _handlePanUpdate,
child: SizedBox(
width: double.infinity,
height: 155,
child: Center(
child: GestureDetector(
onTap: _onPayCoin,
onPanUpdate: (e) => _handlePanUpdate(e, true),
child: ScaleTransition(
scale: _scale22Controller.drive(
Tween(begin: 1, end: 1.1),
),
child: SlideTransition(
position: _slide22Controller.drive(
Tween(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -0.2),
),
),
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',
),
),
),
),
),
),
),
),
const SizedBox(height: 10),
Stack(
alignment: Alignment.centerLeft,
children: [
GestureDetector(
onTap: () {
_coinWithLike.value = _coinWithLike.value.not;
GStorage.setting.put(
SettingBoxKey.coinWithLike,
_coinWithLike.value,
); );
}, },
), child: Row(
), mainAxisSize: MainAxisSize.min,
), children: [
Visibility( const SizedBox(width: 12),
visible: !_isPaying && widget.copyright == 1, Obx(
maintainSize: true, () => Icon(
maintainAnimation: true, _coinWithLike.value
maintainState: true, ? Icons.check_box_outlined
child: GestureDetector( : Icons.check_box_outline_blank,
onTap: _index == 1 size: 20,
? null ),
: () { ),
_onScroll(1); const Text(
}, ' 同时点赞',
child: Padding( style: TextStyle(color: Colors.white),
padding: const EdgeInsets.only(right: 12), ),
child: Image.asset( ],
width: 16,
height: 28,
_index == 1
? 'assets/images/paycoins/ic_right_disable.png'
: 'assets/images/paycoins/ic_right.png',
), ),
), ),
), Center(
child: GestureDetector(
onTap: Get.back,
child: SizedBox(
width: 30,
height: 30,
child: Image.asset(
'assets/images/paycoins/ic_panel_close.png',
),
),
),
),
],
), ),
SizedBox(
height: (isV ? 50 : 10) +
MediaQuery.of(context).padding.bottom),
], ],
), ),
const SizedBox(height: 25), ),
GestureDetector(
behavior: HitTestBehavior.opaque,
onPanUpdate: _handlePanUpdate,
child: SizedBox(
width: double.infinity,
height: 140,
child: Center(
child: GestureDetector(
onTap: _onPayCoin,
onPanUpdate: (e) => _handlePanUpdate(e, true),
child: ScaleTransition(
scale: _scale22Controller.drive(
Tween(begin: 1, end: 1.2),
),
child: SlideTransition(
position: _slide22Controller.drive(
Tween(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -0.2),
),
),
child: SizedBox(
width: 100,
height: 140,
child: Image.asset(
_index == 0
? 'assets/images/paycoins/ic_22_mario.png'
: 'assets/images/paycoins/ic_22_gun_sister.png',
),
),
),
),
),
),
),
),
SizedBox(
height:
(isV ? 50 : 0) + MediaQuery.of(context).padding.bottom),
],
), ),
], ],
); );
@@ -321,7 +392,7 @@ class _PayCoinsPageState extends State<PayCoinsPage>
_coinSlideController.forward().whenComplete(() { _coinSlideController.forward().whenComplete(() {
_coinFadeController.forward().whenComplete(() { _coinFadeController.forward().whenComplete(() {
Get.back(); Get.back();
widget.callback(_index + 1); widget.callback(_index + 1, _coinWithLike.value);
}); });
}); });
}); });

View File

@@ -364,6 +364,9 @@ class GStorage {
static bool get enableCommAntifraud => GStorage.setting static bool get enableCommAntifraud => GStorage.setting
.get(SettingBoxKey.enableCommAntifraud, defaultValue: false); .get(SettingBoxKey.enableCommAntifraud, defaultValue: false);
static bool get coinWithLike =>
GStorage.setting.get(SettingBoxKey.coinWithLike, defaultValue: false);
static List<double> get dynamicDetailRatio => List<double>.from(setting static List<double> get dynamicDetailRatio => List<double>.from(setting
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0])); .get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
@@ -595,6 +598,7 @@ class SettingBoxKey {
showSeekPreview = 'showSeekPreview', showSeekPreview = 'showSeekPreview',
showDmChart = 'showDmChart', showDmChart = 'showDmChart',
enableCommAntifraud = 'enableCommAntifraud', enableCommAntifraud = 'enableCommAntifraud',
coinWithLike = 'coinWithLike',
// Sponsor Block // Sponsor Block
enableSponsorBlock = 'enableSponsorBlock', enableSponsorBlock = 'enableSponsorBlock',