diff --git a/lib/pages/bangumi/introduction/view.dart b/lib/pages/bangumi/introduction/view.dart index 607d7e2a..776d8e6b 100644 --- a/lib/pages/bangumi/introduction/view.dart +++ b/lib/pages/bangumi/introduction/view.dart @@ -455,7 +455,7 @@ class _BangumiInfoState extends State bangumiItem!.stat!['likes']!, ), needAnim: true, - hasOneThree: bangumiIntroController.hasLike.value && + hasTriple: bangumiIntroController.hasLike.value && bangumiIntroController.hasCoin.value && bangumiIntroController.hasFav.value, callBack: (start) { diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index fb02f3dd..ce30c306 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -862,7 +862,7 @@ class _VideoInfoState extends State 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) { diff --git a/lib/pages/video/detail/introduction/widgets/action_item.dart b/lib/pages/video/detail/introduction/widgets/action_item.dart index c7270e32..ae3b100e 100644 --- a/lib/pages/video/detail/introduction/widgets/action_item.dart +++ b/lib/pages/video/detail/introduction/widgets/action_item.dart @@ -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 with TickerProviderStateMixin { AnimationController? controller; Animation? _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 with TickerProviderStateMixin { vsync: this, duration: const Duration(milliseconds: 1500), reverseDuration: const Duration(milliseconds: 400), - ); + )..addListener(listener); - _animation = Tween(begin: 0, end: -2 * pi).animate(controller!) - ..addListener(listener); + _animation = Tween(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 with TickerProviderStateMixin { @override void dispose() { cancelTimer(); - _animation?.removeListener(listener); + controller?.removeListener(listener); controller?.dispose(); super.dispose(); } @@ -124,20 +135,20 @@ class ActionItemState extends State 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 with TickerProviderStateMixin { }, child: Text( widget.text!, - key: ValueKey(widget.text ?? ''), + key: ValueKey(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: "", ), ), diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index 1a420f0a..c487b17a 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -2129,10 +2129,9 @@ class _HeaderControlState extends State { 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 { bangumiIntroController.hasLike.value, semanticsLabel: '点赞', needAnim: true, - hasOneThree: + hasTriple: bangumiIntroController.hasLike.value && bangumiIntroController.hasCoin.value && bangumiIntroController.hasFav.value,