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(
Api.coinVideo,
queryParameters: {
'aid': IdUtils.bv2av(bvid),
// 'bvid': bvid,
'multiply': multiply,
'select_like': 0,
'select_like': selectLike,
'access_key': GStorage.localCache
.get(LocalCacheKey.accessKey, defaultValue: {})['value'],
// '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) {
// not init
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']) {
SmartDialog.showToast('投币成功');
hasCoin.value = true;
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 {
SmartDialog.showToast(res['msg']);
}

View File

@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:math';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@@ -22,6 +24,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
with TickerProviderStateMixin {
bool _isPaying = false;
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;
@@ -96,11 +100,20 @@ class _PayCoinsPageState extends State<PayCoinsPage>
@override
Widget build(BuildContext context) {
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(
key: _key,
alignment: Alignment.center,
children: [
Visibility(
@@ -110,8 +123,13 @@ class _PayCoinsPageState extends State<PayCoinsPage>
maintainState: true,
child: Image.asset(_images[_showThunder ? _imageIndex : 0]),
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
@@ -142,6 +160,7 @@ class _PayCoinsPageState extends State<PayCoinsPage>
child: SizedBox(
height: 100,
child: PageView.builder(
key: PageStorageKey('PageView'),
itemCount: widget.copyright == 1 ? 2 : 1,
controller: _controller,
onPageChanged: (index) => setState(() {
@@ -152,8 +171,10 @@ class _PayCoinsPageState extends State<PayCoinsPage>
listenable: _controller,
builder: (context, child) {
double factor = index == 0 ? 1 : 0;
if (_controller.position.hasContentDimensions) {
factor = 1 - (_controller.page! - index).abs();
if (_controller
.position.hasContentDimensions) {
factor =
1 - (_controller.page! - index).abs();
}
return Visibility(
visible: !_isPaying || _index == index,
@@ -165,7 +186,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
alignment: Alignment.center,
children: [
SlideTransition(
position: _boxAnimController.drive(
position:
_boxAnimController.drive(
Tween(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -0.2),
@@ -176,7 +198,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
),
),
SlideTransition(
position: _coinSlideController.drive(
position:
_coinSlideController.drive(
Tween(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -2),
@@ -185,7 +208,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
child: FadeTransition(
opacity: Tween<double>(
begin: 1, end: 0)
.animate(_coinFadeController),
.animate(
_coinFadeController),
child: Image.asset(
height: 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(
behavior: HitTestBehavior.opaque,
onPanUpdate: _handlePanUpdate,
child: SizedBox(
width: double.infinity,
height: 140,
height: 155,
child: Center(
child: GestureDetector(
onTap: _onPayCoin,
onPanUpdate: (e) => _handlePanUpdate(e, true),
child: ScaleTransition(
scale: _scale22Controller.drive(
Tween(begin: 1, end: 1.2),
Tween(begin: 1, end: 1.1),
),
child: SlideTransition(
position: _slide22Controller.drive(
@@ -254,8 +278,8 @@ class _PayCoinsPageState extends State<PayCoinsPage>
),
),
child: SizedBox(
width: 100,
height: 140,
width: 110,
height: 155,
child: Image.asset(
_index == 0
? 'assets/images/paycoins/ic_22_mario.png'
@@ -268,11 +292,58 @@ class _PayCoinsPageState extends State<PayCoinsPage>
),
),
),
SizedBox(
height:
(isV ? 50 : 0) + MediaQuery.of(context).padding.bottom),
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: [
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(() {
_coinFadeController.forward().whenComplete(() {
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
.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
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
@@ -595,6 +598,7 @@ class SettingBoxKey {
showSeekPreview = 'showSeekPreview',
showDmChart = 'showDmChart',
enableCommAntifraud = 'enableCommAntifraud',
coinWithLike = 'coinWithLike',
// Sponsor Block
enableSponsorBlock = 'enableSponsorBlock',