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,8 +123,13 @@ 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,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
children: [ children: [
@@ -142,6 +160,7 @@ class _PayCoinsPageState extends State<PayCoinsPage>
child: SizedBox( child: SizedBox(
height: 100, height: 100,
child: PageView.builder( child: PageView.builder(
key: PageStorageKey('PageView'),
itemCount: widget.copyright == 1 ? 2 : 1, itemCount: widget.copyright == 1 ? 2 : 1,
controller: _controller, controller: _controller,
onPageChanged: (index) => setState(() { onPageChanged: (index) => setState(() {
@@ -152,8 +171,10 @@ class _PayCoinsPageState extends State<PayCoinsPage>
listenable: _controller, listenable: _controller,
builder: (context, child) { builder: (context, child) {
double factor = index == 0 ? 1 : 0; double factor = index == 0 ? 1 : 0;
if (_controller.position.hasContentDimensions) { if (_controller
factor = 1 - (_controller.page! - index).abs(); .position.hasContentDimensions) {
factor =
1 - (_controller.page! - index).abs();
} }
return Visibility( return Visibility(
visible: !_isPaying || _index == index, visible: !_isPaying || _index == index,
@@ -165,7 +186,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
SlideTransition( SlideTransition(
position: _boxAnimController.drive( position:
_boxAnimController.drive(
Tween( Tween(
begin: const Offset(0.0, 0.0), begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -0.2), end: const Offset(0.0, -0.2),
@@ -176,7 +198,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
), ),
), ),
SlideTransition( SlideTransition(
position: _coinSlideController.drive( position:
_coinSlideController.drive(
Tween( Tween(
begin: const Offset(0.0, 0.0), begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -2), end: const Offset(0.0, -2),
@@ -185,7 +208,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
child: FadeTransition( child: FadeTransition(
opacity: Tween<double>( opacity: Tween<double>(
begin: 1, end: 0) begin: 1, end: 0)
.animate(_coinFadeController), .animate(
_coinFadeController),
child: Image.asset( child: Image.asset(
height: 35 + (factor * 15), height: 35 + (factor * 15),
width: 35 + (factor * 15), width: 35 + (factor * 15),
@@ -231,20 +255,20 @@ class _PayCoinsPageState extends State<PayCoinsPage>
), ),
], ],
), ),
const SizedBox(height: 25), SizedBox(height: isV ? 25 : 10),
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onPanUpdate: _handlePanUpdate, onPanUpdate: _handlePanUpdate,
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
height: 140, height: 155,
child: Center( child: Center(
child: GestureDetector( child: GestureDetector(
onTap: _onPayCoin, onTap: _onPayCoin,
onPanUpdate: (e) => _handlePanUpdate(e, true), onPanUpdate: (e) => _handlePanUpdate(e, true),
child: ScaleTransition( child: ScaleTransition(
scale: _scale22Controller.drive( scale: _scale22Controller.drive(
Tween(begin: 1, end: 1.2), Tween(begin: 1, end: 1.1),
), ),
child: SlideTransition( child: SlideTransition(
position: _slide22Controller.drive( position: _slide22Controller.drive(
@@ -254,8 +278,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
), ),
), ),
child: SizedBox( child: SizedBox(
width: 100, width: 110,
height: 140, height: 155,
child: Image.asset( child: Image.asset(
_index == 0 _index == 0
? 'assets/images/paycoins/ic_22_mario.png' ? 'assets/images/paycoins/ic_22_mario.png'
@@ -268,11 +292,58 @@ class _PayCoinsPageState extends State<PayCoinsPage>
), ),
), ),
), ),
SizedBox( const SizedBox(height: 10),
height: Stack(
(isV ? 50 : 0) + MediaQuery.of(context).padding.bottom), alignment: Alignment.centerLeft,
children: [
GestureDetector(
onTap: () {
_coinWithLike.value = _coinWithLike.value.not;
GStorage.setting.put(
SettingBoxKey.coinWithLike,
_coinWithLike.value,
);
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(width: 12),
Obx(
() => Icon(
_coinWithLike.value
? Icons.check_box_outlined
: Icons.check_box_outline_blank,
size: 20,
),
),
const Text(
' 同时点赞',
style: TextStyle(color: Colors.white),
),
], ],
), ),
),
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),
],
),
),
),
], ],
); );
@@ -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',