From d66ff4d536115606d4599e8c3631a947fc004a5a Mon Sep 17 00:00:00 2001 From: niuhuan Date: Tue, 2 Apr 2024 20:56:17 +0800 Subject: [PATCH] :sparkles: volume next ep --- ci/version.info.txt | 1 + lib/basic/config/VolumeNextChapter.dart | 31 ++++++++++++++++++++ lib/screens/InitScreen.dart | 2 ++ lib/screens/SettingsScreen.dart | 2 ++ lib/screens/components/ImageReader.dart | 38 +++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 lib/basic/config/VolumeNextChapter.dart diff --git a/ci/version.info.txt b/ci/version.info.txt index a575c5f..3a2e932 100644 --- a/ci/version.info.txt +++ b/ci/version.info.txt @@ -1,5 +1,6 @@ v1.7.8 - [x] ♻️ iOS可以使用FaceID进行解锁App +- [x] ✨ 音量键快速翻阅下一章节(设置中开启) v1.7.7 - [x] 🐛 修复一些极端情况下崩溃 diff --git a/lib/basic/config/VolumeNextChapter.dart b/lib/basic/config/VolumeNextChapter.dart new file mode 100644 index 0000000..4233460 --- /dev/null +++ b/lib/basic/config/VolumeNextChapter.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import '../Method.dart'; + +const _propertyName = "volumeNextChapter"; + +late bool _volumeNextChapter; + +Future initVolumeNextChapter() async { + _volumeNextChapter = + (await method.loadProperty(_propertyName, "true")) == "true"; +} + +bool volumeNextChapter() { + return _volumeNextChapter; +} + +Widget volumeNextChapterSetting() { + return StatefulBuilder( + builder: (BuildContext context, void Function(void Function()) setState) { + return SwitchListTile( + title: const Text("双击音量键下一章节"), + value: _volumeNextChapter, + onChanged: (value) async { + await method.saveProperty(_propertyName, "$value"); + _volumeNextChapter = value; + setState(() {}); + }, + ); + }, + ); +} diff --git a/lib/screens/InitScreen.dart b/lib/screens/InitScreen.dart index 4875caa..56c4173 100644 --- a/lib/screens/InitScreen.dart +++ b/lib/screens/InitScreen.dart @@ -53,6 +53,7 @@ import '../basic/config/HiddenFdIcon.dart'; import '../basic/config/IconLoading.dart'; import '../basic/config/IsPro.dart'; import '../basic/config/ReaderBackgroundColor.dart'; +import '../basic/config/VolumeNextChapter.dart'; import '../basic/config/WebDav.dart'; import 'AccountScreen.dart'; import 'AppScreen.dart'; @@ -125,6 +126,7 @@ class _InitScreenState extends State { await initEBookScrolling(); await initEBookScrollingRange(); await initEBookScrollingTrigger(); + await initVolumeNextChapter(); String? initUrl; if (Platform.isAndroid || Platform.isIOS) { diff --git a/lib/screens/SettingsScreen.dart b/lib/screens/SettingsScreen.dart index ef3506d..9ffd568 100644 --- a/lib/screens/SettingsScreen.dart +++ b/lib/screens/SettingsScreen.dart @@ -31,6 +31,7 @@ import 'package:pikapika/basic/config/ShowCommentAtDownload.dart'; import 'package:pikapika/basic/config/Themes.dart'; import 'package:pikapika/basic/config/TimeOffsetHour.dart'; import 'package:pikapika/basic/config/VolumeController.dart'; +import 'package:pikapika/basic/config/VolumeNextChapter.dart'; import 'package:pikapika/screens/components/NetworkSetting.dart'; import 'package:pikapika/screens/components/RightClickPop.dart'; @@ -165,6 +166,7 @@ class _SettingsScreenState extends State { autoFullScreenSetting(), fullScreenActionSetting(), volumeControllerSetting(), + volumeNextChapterSetting(), keyboardControllerSetting(), const Divider(), noAnimationSetting(), diff --git a/lib/screens/components/ImageReader.dart b/lib/screens/components/ImageReader.dart index a38878f..b3166d6 100644 --- a/lib/screens/components/ImageReader.dart +++ b/lib/screens/components/ImageReader.dart @@ -5,6 +5,7 @@ import 'package:another_xlider/another_xlider.dart'; import 'package:event/event.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_styled_toast/flutter_styled_toast.dart'; import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:photo_view/photo_view_gallery.dart'; import 'package:pikapika/basic/Common.dart'; @@ -27,6 +28,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../../basic/config/IconLoading.dart'; import '../../basic/config/ReaderBackgroundColor.dart'; import '../../basic/config/UseApiLoadImage.dart'; +import '../../basic/config/VolumeNextChapter.dart'; import '../FilePhotoViewScreen.dart'; import 'gesture_zoom_box.dart'; @@ -272,12 +274,48 @@ abstract class _ImageReaderContentState extends State<_ImageReaderContent> { case "DOWN": if (_current < widget.struct.images.length - 1) { _needJumpTo(_current + 1, true); + } else { + if (volumeNextChapter()) { + final now = DateTime.now().millisecondsSinceEpoch; + if (_noticeTime + 3000 > now) { + if (_hasNextEp()) { + _onNextAction(); + } else { + showToast( + "已经到头了", + context: context, + position: StyledToastPosition.center, + animation: StyledToastAnimation.scale, + reverseAnimation: StyledToastAnimation.fade, + duration: const Duration(seconds: 3), + animDuration: const Duration(milliseconds: 300), + curve: Curves.elasticOut, + reverseCurve: Curves.linear, + ); + } + } else { + _noticeTime = now; + showToast( + "再次点击跳转到下一章", + context: context, + position: StyledToastPosition.center, + animation: StyledToastAnimation.scale, + reverseAnimation: StyledToastAnimation.fade, + duration: const Duration(seconds: 3), + animDuration: const Duration(milliseconds: 300), + curve: Curves.elasticOut, + reverseCurve: Curves.linear, + ); + } + } } break; } } } + int _noticeTime = 0; + late int _startIndex; late int _current; late int _slider;