Skip to content

Commit

Permalink
In the single page and double column reading direction, support mouse…
Browse files Browse the repository at this point in the history
… wheel page turning

Fix the bug that the modification of the image interval on the reading page does not take effect immediately

单页和双列阅读方向下,支持鼠标滚轮翻页
修复阅读页修改图片间隔时,无法立即生效的bug
  • Loading branch information
jiangtian616 committed Dec 31, 2023
1 parent 0e760fe commit dec59d4
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 41 deletions.
6 changes: 5 additions & 1 deletion changelog/v7.4.8+147.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- 现在所有平台和布局模式下均可以自定义鼠标滚轮滚动速度
- 阅读页在从上至下布局模式下,现在可以支持自定义图片区域宽度
- 下载设置中支持自定义默认下载分组
- 单页和双列阅读方向下,支持鼠标滚轮翻页
- 优化保存图片时的图片命名规则
- 优化解压归档时的icon显示
- 收藏页和关注页搜索不再继承关键字
Expand All @@ -12,13 +13,15 @@
- 现在改变下载路径时只会自动复制由JHenTai下载的画廊图片,不再移动其他文件
- 修复下载已被版权删除的画廊时,不会自动停止下载的bug
- 修复在部分场景下,自动阅读模式无法滚动到末尾的bug
- 修复阅读页修改图片间隔时,无法立即生效的bug

------------------------------------------------------------------------------------------

- Support customizing the brightness of the reading page on the mobile terminal
- Now you can customize the mouse wheel scrolling speed in all platforms and layout modes
- In the top to bottom layout mode, the reading page can now support customizing the width of the image area
- The download settings support customizing the default download group
- In the single page and double column reading direction, support mouse wheel page turning
- Optimize the toast message when canceling favorites
- Optimize the image naming rules when saving images
- Optimize the icon display when decompressing archives
Expand All @@ -29,4 +32,5 @@
- No longer support automatically creating Profile, change to select the profile to be used in the application by yourself
- Now when changing the download path, only the gallery images downloaded by JHenTai will be automatically copied, and other files will no longer be moved
- Fix the bug that when downloading a gallery that has been deleted due to copyright, the download will not be automatically stopped
- Fix the bug that auto reading mode cannot scroll to the end in some scenes
- Fix the bug that auto reading mode cannot scroll to the end in some scenes
- Fix the bug that the modification of the image interval on the reading page does not take effect immediately
9 changes: 9 additions & 0 deletions lib/src/pages/read/layout/base/base_layout_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:typed_data';
import 'package:clipboard/clipboard.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:get/get.dart';
import 'package:image_save/image_save.dart';
import 'package:jhentai/src/consts/eh_consts.dart';
Expand Down Expand Up @@ -98,6 +99,14 @@ abstract class BaseLayoutLogic extends GetxController with GetTickerProviderStat
autoModeTimer?.cancel();
}

void onPointerScroll(PointerScrollEvent value) {
if (value.scrollDelta.dy > 0) {
toNext();
} else if (value.scrollDelta.dy < 0) {
toPrev();
}
}

void showBottomMenuInOnlineMode(int index, BuildContext context) {
showCupertinoModalPopup(
context: context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:jhentai/src/extension/get_logic_extension.dart';
import 'package:jhentai/src/model/read_page_info.dart';
import 'package:jhentai/src/pages/read/layout/horizontal_double_column/horizontal_double_column_layout_state.dart';
import 'package:jhentai/src/widget/eh_wheel_scroll_listener.dart';
import 'package:photo_view/photo_view_gallery.dart';

import '../../../../setting/read_setting.dart';
Expand All @@ -21,23 +22,26 @@ class HorizontalDoubleColumnLayout extends BaseLayout {

@override
Widget buildBody(BuildContext context) {
return PhotoViewGallery.builder(
scrollPhysics: const ClampingScrollPhysics(),
pageController: state.pageController,
cacheExtent: (ReadSetting.preloadPageCount.value.toDouble() + 1) / 2,
reverse: ReadSetting.isInRight2LeftDirection,
itemCount: state.pageCount,
builder: (context, index) => PhotoViewGalleryPageOptions.customChild(
initialScale: 1.0,
minScale: 1.0,
maxScale: 2.5,
scaleStateCycle: ReadSetting.enableDoubleTapToScaleUp.isTrue ? logic.scaleStateCycle : null,
enableTapDragZoom: ReadSetting.enableTapDragToScaleUp.isTrue,
child: index < 0 || index >= state.pageCount
? null
: readPageState.readPageInfo.mode == ReadMode.online
? _buildDoubleColumnItemInOnlineMode(context, index)
: _buildDoubleColumnItemInLocalMode(context, index),
return EHWheelListener(
onPointerScroll: logic.onPointerScroll,
child: PhotoViewGallery.builder(
scrollPhysics: const ClampingScrollPhysics(),
pageController: state.pageController,
cacheExtent: (ReadSetting.preloadPageCount.value.toDouble() + 1) / 2,
reverse: ReadSetting.isInRight2LeftDirection,
itemCount: state.pageCount,
builder: (context, index) => PhotoViewGalleryPageOptions.customChild(
initialScale: 1.0,
minScale: 1.0,
maxScale: 2.5,
scaleStateCycle: ReadSetting.enableDoubleTapToScaleUp.isTrue ? logic.scaleStateCycle : null,
enableTapDragZoom: ReadSetting.enableTapDragToScaleUp.isTrue,
child: index < 0 || index >= state.pageCount
? null
: readPageState.readPageInfo.mode == ReadMode.online
? _buildDoubleColumnItemInOnlineMode(context, index)
: _buildDoubleColumnItemInLocalMode(context, index),
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/model/read_page_info.dart';
import 'package:jhentai/src/widget/eh_wheel_scroll_listener.dart';
import 'package:photo_view/photo_view_gallery.dart';

import '../../../../setting/read_setting.dart';
Expand All @@ -18,27 +19,30 @@ class HorizontalPageLayout extends BaseLayout {

@override
Widget buildBody(BuildContext context) {
return PhotoViewGallery.builder(
itemCount: readPageState.readPageInfo.pageCount,
scrollPhysics: const ClampingScrollPhysics(),
pageController: logic.pageController,
cacheExtent: ReadSetting.preloadPageCount.value.toDouble(),
reverse: ReadSetting.isInRight2LeftDirection,
builder: (context, index) => PhotoViewGalleryPageOptions.customChild(
initialScale: 1.0,
minScale: 1.0,
maxScale: 2.5,
scaleStateCycle: ReadSetting.enableDoubleTapToScaleUp.isTrue ? logic.scaleStateCycle : null,
enableTapDragZoom: ReadSetting.enableTapDragToScaleUp.isTrue,
child: Obx(() {
Widget item = readPageState.readPageInfo.mode == ReadMode.online ? buildItemInOnlineMode(context, index) : buildItemInLocalMode(context, index);
return EHWheelListener(
onPointerScroll: ReadSetting.isInFitWidthReadDirection ? null : logic.onPointerScroll,
child: PhotoViewGallery.builder(
itemCount: readPageState.readPageInfo.pageCount,
scrollPhysics: const ClampingScrollPhysics(),
pageController: logic.pageController,
cacheExtent: ReadSetting.preloadPageCount.value.toDouble(),
reverse: ReadSetting.isInRight2LeftDirection,
builder: (context, index) => PhotoViewGalleryPageOptions.customChild(
initialScale: 1.0,
minScale: 1.0,
maxScale: 2.5,
scaleStateCycle: ReadSetting.enableDoubleTapToScaleUp.isTrue ? logic.scaleStateCycle : null,
enableTapDragZoom: ReadSetting.enableTapDragToScaleUp.isTrue,
child: Obx(() {
Widget item = readPageState.readPageInfo.mode == ReadMode.online ? buildItemInOnlineMode(context, index) : buildItemInLocalMode(context, index);

if (ReadSetting.isInFitWidthReadDirection) {
item = Center(child: SingleChildScrollView(controller: ScrollController(), child: item));
}
if (ReadSetting.isInFitWidthReadDirection) {
item = Center(child: SingleChildScrollView(controller: ScrollController(), child: item));
}

return item;
}),
return item;
}),
),
),
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/src/pages/read/read_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ReadPageLogic extends GetxController {
late Worker toggleCurrentImmersiveModeLister;
late Worker toggleDeviceOrientationLister;
late Worker readDirectionLister;
late Worker imageSpaceLister;
late Worker displayFirstPageAloneListener;
late Worker enableCustomBrightnessListener;
late Worker customBrightnessListener;
Expand Down Expand Up @@ -113,6 +114,10 @@ class ReadPageLogic extends GetxController {
updateSafely([layoutId]);
});

imageSpaceLister = ever(ReadSetting.imageSpace, (_) {
updateSafely([layoutId]);
});

displayFirstPageAloneListener = ever(ReadSetting.displayFirstPageAlone, (value) {
if (state.displayFirstPageAlone != value) {
state.displayFirstPageAlone = value;
Expand Down Expand Up @@ -168,6 +173,7 @@ class ReadPageLogic extends GetxController {
refreshCurrentTimeAndBatteryLevelTimer.cancel();
toggleCurrentImmersiveModeLister.dispose();
readDirectionLister.dispose();
imageSpaceLister.dispose();
flushReadProgressTimer.cancel();
displayFirstPageAloneListener.dispose();
enableCustomBrightnessListener.dispose();
Expand Down
21 changes: 21 additions & 0 deletions lib/src/widget/eh_wheel_scroll_listener.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class EHWheelListener extends StatelessWidget {
final Widget child;
final ValueChanged<PointerScrollEvent>? onPointerScroll;

const EHWheelListener({Key? key, required this.child, this.onPointerScroll}) : super(key: key);

@override
Widget build(BuildContext context) {
return Listener(
onPointerSignal: (PointerSignalEvent event) {
if (event is PointerScrollEvent) {
onPointerScroll?.call(event);
}
},
child: child,
);
}
}
4 changes: 0 additions & 4 deletions lib/src/widget/eh_wheel_speed_controller_for_read_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class EHWheelSpeedControllerForReadPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (!GetPlatform.isDesktop) {
return child;
}

return Listener(
/// For some reason (probably because of the high resolution monitor), scroll by mouse wheel is very slow,
/// so i call [animateTo] to simulate a faster scroll speed.
Expand Down

0 comments on commit dec59d4

Please sign in to comment.