mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: triple
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -455,7 +455,7 @@ class _BangumiInfoState extends State<BangumiInfo>
|
||||
bangumiItem!.stat!['likes']!,
|
||||
),
|
||||
needAnim: true,
|
||||
hasOneThree: bangumiIntroController.hasLike.value &&
|
||||
hasTriple: bangumiIntroController.hasLike.value &&
|
||||
bangumiIntroController.hasCoin.value &&
|
||||
bangumiIntroController.hasFav.value,
|
||||
callBack: (start) {
|
||||
|
||||
@@ -862,7 +862,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
? Utils.numFormat(videoDetail.stat!.like!)
|
||||
: '-',
|
||||
needAnim: true,
|
||||
hasOneThree: videoIntroController.hasLike.value &&
|
||||
hasTriple: videoIntroController.hasLike.value &&
|
||||
videoIntroController.hasCoin.value &&
|
||||
videoIntroController.hasFav.value,
|
||||
callBack: (start) {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
class ActionItem extends StatefulWidget {
|
||||
final Icon icon;
|
||||
@@ -14,7 +17,7 @@ class ActionItem extends StatefulWidget {
|
||||
final bool selectStatus;
|
||||
final String semanticsLabel;
|
||||
final bool needAnim;
|
||||
final bool hasOneThree;
|
||||
final bool hasTriple;
|
||||
final Function? callBack;
|
||||
final bool? expand;
|
||||
|
||||
@@ -28,7 +31,7 @@ class ActionItem extends StatefulWidget {
|
||||
this.text,
|
||||
this.selectStatus = false,
|
||||
this.needAnim = false,
|
||||
this.hasOneThree = false,
|
||||
this.hasTriple = false,
|
||||
this.callBack,
|
||||
required this.semanticsLabel,
|
||||
this.expand,
|
||||
@@ -42,28 +45,32 @@ class ActionItemState extends State<ActionItem> with TickerProviderStateMixin {
|
||||
AnimationController? controller;
|
||||
Animation<double>? _animation;
|
||||
|
||||
bool get _isThumbUp => widget.semanticsLabel == '点赞';
|
||||
late final _isThumbsUp = widget.semanticsLabel == '点赞';
|
||||
late int _lastTime;
|
||||
bool _hideCircle = false;
|
||||
late bool _hideCircle = false;
|
||||
Timer? _timer;
|
||||
|
||||
void _startLongPress() {
|
||||
_lastTime = DateTime.now().millisecondsSinceEpoch;
|
||||
if (!widget.hasOneThree) {
|
||||
_timer ??= Timer(const Duration(milliseconds: 100), () {
|
||||
feedBack();
|
||||
_timer ??= Timer(const Duration(milliseconds: 100), () {
|
||||
if (widget.hasTriple) {
|
||||
HapticFeedback.lightImpact();
|
||||
SmartDialog.showToast('已经完成三连');
|
||||
} else {
|
||||
controller?.forward();
|
||||
widget.callBack?.call(true);
|
||||
cancelTimer();
|
||||
});
|
||||
}
|
||||
}
|
||||
cancelTimer();
|
||||
});
|
||||
}
|
||||
|
||||
void _cancelLongPress([bool isCancel = false]) {
|
||||
int duration = DateTime.now().millisecondsSinceEpoch - _lastTime;
|
||||
if (duration >= 100 && duration < 1500) {
|
||||
controller?.reverse();
|
||||
widget.callBack?.call(false);
|
||||
if (widget.hasTriple.not) {
|
||||
controller?.reverse();
|
||||
widget.callBack?.call(false);
|
||||
}
|
||||
} else if (duration < 100) {
|
||||
cancelTimer();
|
||||
if (!isCancel) {
|
||||
@@ -81,19 +88,23 @@ class ActionItemState extends State<ActionItem> with TickerProviderStateMixin {
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
reverseDuration: const Duration(milliseconds: 400),
|
||||
);
|
||||
)..addListener(listener);
|
||||
|
||||
_animation = Tween<double>(begin: 0, end: -2 * pi).animate(controller!)
|
||||
..addListener(listener);
|
||||
_animation = Tween<double>(begin: 0, end: -2 * pi).animate(
|
||||
CurvedAnimation(
|
||||
parent: controller!,
|
||||
curve: Curves.easeInOut,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void listener() {
|
||||
setState(() {
|
||||
_hideCircle = _animation?.value == -2 * pi;
|
||||
_hideCircle = controller?.value == 1;
|
||||
if (_hideCircle) {
|
||||
controller?.reset();
|
||||
if (_isThumbUp) {
|
||||
if (_isThumbsUp) {
|
||||
widget.onLongPress?.call();
|
||||
}
|
||||
}
|
||||
@@ -108,7 +119,7 @@ class ActionItemState extends State<ActionItem> with TickerProviderStateMixin {
|
||||
@override
|
||||
void dispose() {
|
||||
cancelTimer();
|
||||
_animation?.removeListener(listener);
|
||||
controller?.removeListener(listener);
|
||||
controller?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -124,20 +135,20 @@ class ActionItemState extends State<ActionItem> with TickerProviderStateMixin {
|
||||
widget.semanticsLabel,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
onTap: _isThumbUp
|
||||
onTap: _isThumbsUp
|
||||
? null
|
||||
: () {
|
||||
feedBack();
|
||||
widget.onTap?.call();
|
||||
},
|
||||
onLongPress: _isThumbUp
|
||||
onLongPress: _isThumbsUp
|
||||
? null
|
||||
: () {
|
||||
widget.onLongPress?.call();
|
||||
},
|
||||
onTapDown: (details) => _isThumbUp ? _startLongPress() : null,
|
||||
onTapUp: (details) => _isThumbUp ? _cancelLongPress() : null,
|
||||
onTapCancel: () => _isThumbUp ? _cancelLongPress(true) : null,
|
||||
onTapDown: (details) => _isThumbsUp ? _startLongPress() : null,
|
||||
onTapUp: (details) => _isThumbsUp ? _cancelLongPress() : null,
|
||||
onTapCancel: () => _isThumbsUp ? _cancelLongPress(true) : null,
|
||||
// borderRadius: StyleString.mdRadius,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -180,13 +191,14 @@ class ActionItemState extends State<ActionItem> with TickerProviderStateMixin {
|
||||
},
|
||||
child: Text(
|
||||
widget.text!,
|
||||
key: ValueKey<String>(widget.text ?? ''),
|
||||
key: ValueKey<String>(widget.text!),
|
||||
style: TextStyle(
|
||||
color: widget.selectStatus
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.outline,
|
||||
fontSize:
|
||||
Theme.of(context).textTheme.labelSmall!.fontSize),
|
||||
color: widget.selectStatus
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.outline,
|
||||
fontSize:
|
||||
Theme.of(context).textTheme.labelSmall!.fontSize,
|
||||
),
|
||||
semanticsLabel: "",
|
||||
),
|
||||
),
|
||||
|
||||
@@ -2129,10 +2129,9 @@ class _HeaderControlState extends State<HeaderControl> {
|
||||
videoIntroController.hasLike.value,
|
||||
semanticsLabel: '点赞',
|
||||
needAnim: true,
|
||||
hasOneThree:
|
||||
videoIntroController.hasLike.value &&
|
||||
videoIntroController.hasCoin.value &&
|
||||
videoIntroController.hasFav.value,
|
||||
hasTriple: videoIntroController.hasLike.value &&
|
||||
videoIntroController.hasCoin.value &&
|
||||
videoIntroController.hasFav.value,
|
||||
callBack: (start) {
|
||||
if (start) {
|
||||
HapticFeedback.lightImpact();
|
||||
@@ -2250,7 +2249,7 @@ class _HeaderControlState extends State<HeaderControl> {
|
||||
bangumiIntroController.hasLike.value,
|
||||
semanticsLabel: '点赞',
|
||||
needAnim: true,
|
||||
hasOneThree:
|
||||
hasTriple:
|
||||
bangumiIntroController.hasLike.value &&
|
||||
bangumiIntroController.hasCoin.value &&
|
||||
bangumiIntroController.hasFav.value,
|
||||
|
||||
Reference in New Issue
Block a user