Skip to content

Commit

Permalink
Merge pull request #503 from xxfttkx/branch-fix-time
Browse files Browse the repository at this point in the history
simplify code
  • Loading branch information
Predidit authored Dec 22, 2024
2 parents 1ee164b + f24d41d commit 749f69e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 38 deletions.
4 changes: 1 addition & 3 deletions lib/bean/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
void switchChange(value) async {
val = value ?? !val;
await Setting.put(widget.setKey, val);
if (widget.callFn != null) {
widget.callFn!.call(val);
}
widget.callFn?.call(val);
if (widget.needReboot != null && widget.needReboot!) {
KazumiDialog.showToast(message: '重启生效');
}
Expand Down
46 changes: 11 additions & 35 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ class _PlayerItemState extends State<PlayerItem>
void _handleTap() {
if (!showPositioned) {
_animationController.forward();
if (hideTimer != null) {
hideTimer!.cancel();
}
hideTimer?.cancel();
hideTimer = Timer(const Duration(seconds: 4), () {
if (mounted) {
setState(() {
Expand All @@ -139,9 +137,7 @@ class _PlayerItemState extends State<PlayerItem>
});
} else {
_animationController.reverse();
if (hideTimer != null) {
hideTimer!.cancel();
}
hideTimer?.cancel();
}
setState(() {
showPositioned = !showPositioned;
Expand All @@ -155,9 +151,7 @@ class _PlayerItemState extends State<PlayerItem>
setState(() {
showPositioned = true;
});
if (hideTimer != null) {
hideTimer!.cancel();
}
hideTimer?.cancel();

hideTimer = Timer(const Duration(seconds: 4), () {
if (mounted) {
Expand All @@ -174,10 +168,7 @@ class _PlayerItemState extends State<PlayerItem>
setState(() {
showVolume = true;
});
if (mouseScrollerTimer != null) {
mouseScrollerTimer!.cancel();
}

mouseScrollerTimer?.cancel();
mouseScrollerTimer = Timer(const Duration(seconds: 2), () {
if (mounted) {
setState(() {
Expand All @@ -192,10 +183,7 @@ class _PlayerItemState extends State<PlayerItem>
setState(() {
showVolume = true;
});
if (hideVolumeUITimer != null) {
hideVolumeUITimer!.cancel();
}

hideVolumeUITimer?.cancel();
hideVolumeUITimer = Timer(const Duration(seconds: 2), () {
if (mounted) {
setState(() {
Expand Down Expand Up @@ -766,9 +754,7 @@ class _PlayerItemState extends State<PlayerItem>
void dispose() {
WidgetsBinding.instance.removeObserver(this);
windowManager.removeListener(this);
if (playerTimer != null) {
playerTimer!.cancel();
}
playerTimer?.cancel();
_animationController.dispose();
infoController.episodeCommentsList.clear();
infoController.episodeInfo.reset();
Expand Down Expand Up @@ -844,9 +830,7 @@ class _PlayerItemState extends State<PlayerItem>
LogicalKeyboardKey.arrowRight) {
lastPlayerSpeed =
playerController.playerSpeed;
if (keyShortPressTimer != null) {
keyShortPressTimer!.cancel();
}
keyShortPressTimer?.cancel();
keyShortPressTimer = Timer(
const Duration(milliseconds: 300), () {
keyShortPressTimer = null;
Expand All @@ -862,9 +846,7 @@ class _PlayerItemState extends State<PlayerItem>
targetPosition = 0;
}
try {
if (playerTimer != null) {
playerTimer!.cancel();
}
playerTimer?.cancel();
playerController.currentPosition =
Duration(seconds: targetPosition);
playerController
Expand Down Expand Up @@ -935,9 +917,7 @@ class _PlayerItemState extends State<PlayerItem>
} else {
keyShortPressTimer = null;
try {
if (playerTimer != null) {
playerTimer!.cancel();
}
playerTimer?.cancel();
playerController.currentPosition =
Duration(
seconds: playerController
Expand Down Expand Up @@ -1075,9 +1055,7 @@ class _PlayerItemState extends State<PlayerItem>
setState(() {
showPosition = true;
});
if (playerTimer != null) {
playerTimer!.cancel();
}
playerTimer?.cancel();
playerController.pause();
final double scale =
180000 / MediaQuery.sizeOf(context).width;
Expand Down Expand Up @@ -1639,9 +1617,7 @@ class _PlayerItemState extends State<PlayerItem>
buffered: playerController.buffer,
total: playerController.duration,
onSeek: (duration) {
if (playerTimer != null) {
playerTimer!.cancel();
}
playerTimer?.cancel();
playerController.currentPosition = duration;
playerController.seek(duration);
playerTimer = getPlayerTimer(); //Bug_time
Expand Down

0 comments on commit 749f69e

Please sign in to comment.