improve reader; fix #21

This commit is contained in:
2024-11-07 09:31:57 +08:00
parent 5a14ea48c1
commit 082aa36316
6 changed files with 44 additions and 5 deletions

View File

@@ -171,7 +171,9 @@
"Long press to zoom": "长按缩放", "Long press to zoom": "长按缩放",
"Updates Available": "更新可用", "Updates Available": "更新可用",
"Unselected": "未选择", "Unselected": "未选择",
"Long press and drag to reorder.": "长按并拖动以重新排序。" "Long press and drag to reorder.": "长按并拖动以重新排序。",
"Limit image width": "限制图片宽度",
"When using Continuous(Top to Bottom) mode": "当使用连续(从上到下)模式"
}, },
"zh_TW": { "zh_TW": {
"Home": "首頁", "Home": "首頁",
@@ -345,6 +347,8 @@
"Long press to zoom": "長按縮放", "Long press to zoom": "長按縮放",
"Updates Available": "更新可用", "Updates Available": "更新可用",
"Unselected": "未選擇", "Unselected": "未選擇",
"Long press and drag to reorder.": "長按並拖動以重新排序。" "Long press and drag to reorder.": "長按並拖動以重新排序。",
"Limit image width": "限制圖片寬度",
"When using Continuous(Top to Bottom) mode": "當使用連續(從上到下)模式"
} }
} }

View File

@@ -113,6 +113,7 @@ class _Settings with ChangeNotifier {
'downloadThreads': 5, 'downloadThreads': 5,
'enableLongPressToZoom': true, 'enableLongPressToZoom': true,
'checkUpdateOnStart': true, 'checkUpdateOnStart': true,
'limitImageWidth': true,
}; };
operator [](String key) { operator [](String key) {

View File

@@ -22,6 +22,8 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
_DragListener? dragListener; _DragListener? dragListener;
int fingers = 0;
@override @override
void initState() { void initState() {
_tapGestureRecognizer = TapGestureRecognizer() _tapGestureRecognizer = TapGestureRecognizer()
@@ -38,6 +40,7 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
return Listener( return Listener(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onPointerDown: (event) { onPointerDown: (event) {
fingers++;
_lastTapPointer = event.pointer; _lastTapPointer = event.pointer;
_lastTapMoveDistance = Offset.zero; _lastTapMoveDistance = Offset.zero;
_tapGestureRecognizer.addPointer(event); _tapGestureRecognizer.addPointer(event);
@@ -46,7 +49,7 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
_dragInProgress = false; _dragInProgress = false;
} }
Future.delayed(_kLongPressMinTime, () { Future.delayed(_kLongPressMinTime, () {
if (_lastTapPointer == event.pointer) { if (_lastTapPointer == event.pointer && fingers == 1) {
if(_lastTapMoveDistance!.distanceSquared < 20.0 * 20.0) { if(_lastTapMoveDistance!.distanceSquared < 20.0 * 20.0) {
onLongPressedDown(event.position); onLongPressedDown(event.position);
_longPressInProgress = true; _longPressInProgress = true;
@@ -67,6 +70,19 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
} }
}, },
onPointerUp: (event) { onPointerUp: (event) {
fingers--;
if (_longPressInProgress) {
onLongPressedUp(event.position);
}
if(_dragInProgress) {
dragListener?.onEnd?.call();
_dragInProgress = false;
}
_lastTapPointer = null;
_lastTapMoveDistance = null;
},
onPointerCancel: (event) {
fingers--;
if (_longPressInProgress) { if (_longPressInProgress) {
onLongPressedUp(event.position); onLongPressedUp(event.position);
} }

View File

@@ -471,18 +471,24 @@ class _ContinuousModeState extends State<_ContinuousMode>
}, },
child: widget, child: widget,
); );
var width = MediaQuery.of(context).size.width;
var height = MediaQuery.of(context).size.height;
if(appdata.settings['limitImageWidth'] && width / height > 0.7) {
width = height * 0.7;
}
return PhotoView.customChild( return PhotoView.customChild(
backgroundDecoration: BoxDecoration( backgroundDecoration: BoxDecoration(
color: context.colorScheme.surface, color: context.colorScheme.surface,
), ),
childSize: Size(width, height),
minScale: 1.0, minScale: 1.0,
maxScale: 2.5, maxScale: 2.5,
strictScale: true, strictScale: true,
controller: photoViewController, controller: photoViewController,
child: SizedBox( child: SizedBox(
width: MediaQuery.of(context).size.width, width: width,
height: MediaQuery.of(context).size.height, height: height,
child: widget, child: widget,
), ),
); );

View File

@@ -61,6 +61,14 @@ class _ReaderSettingsState extends State<ReaderSettings> {
widget.onChanged?.call('enableLongPressToZoom'); widget.onChanged?.call('enableLongPressToZoom');
}, },
).toSliver(), ).toSliver(),
_SwitchSetting(
title: 'Limit image width'.tl,
subtitle: 'When using Continuous(Top to Bottom) mode'.tl,
settingKey: 'limitImageWidth',
onChanged: () {
widget.onChanged?.call('limitImageWidth');
},
).toSliver(),
], ],
); );
} }

View File

@@ -5,6 +5,7 @@ class _SwitchSetting extends StatefulWidget {
required this.title, required this.title,
required this.settingKey, required this.settingKey,
this.onChanged, this.onChanged,
this.subtitle,
}); });
final String title; final String title;
@@ -13,6 +14,8 @@ class _SwitchSetting extends StatefulWidget {
final VoidCallback? onChanged; final VoidCallback? onChanged;
final String? subtitle;
@override @override
State<_SwitchSetting> createState() => _SwitchSettingState(); State<_SwitchSetting> createState() => _SwitchSettingState();
} }
@@ -24,6 +27,7 @@ class _SwitchSettingState extends State<_SwitchSetting> {
return ListTile( return ListTile(
title: Text(widget.title), title: Text(widget.title),
subtitle: widget.subtitle == null ? null : Text(widget.subtitle!),
trailing: Switch( trailing: Switch(
value: appdata.settings[widget.settingKey], value: appdata.settings[widget.settingKey],
onChanged: (value) { onChanged: (value) {