mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
[Android] Turn page by volume keys
This commit is contained in:
@@ -188,7 +188,8 @@
|
|||||||
"Data Sync": "数据同步",
|
"Data Sync": "数据同步",
|
||||||
"Quick Favorite": "快速收藏",
|
"Quick Favorite": "快速收藏",
|
||||||
"Long press on the favorite button to quickly add to this folder": "长按收藏按钮快速添加到这个文件夹",
|
"Long press on the favorite button to quickly add to this folder": "长按收藏按钮快速添加到这个文件夹",
|
||||||
"Added": "已添加"
|
"Added": "已添加",
|
||||||
|
"Turn page by volume keys": "使用音量键翻页"
|
||||||
},
|
},
|
||||||
"zh_TW": {
|
"zh_TW": {
|
||||||
"Home": "首頁",
|
"Home": "首頁",
|
||||||
@@ -379,6 +380,7 @@
|
|||||||
"Data Sync": "數據同步",
|
"Data Sync": "數據同步",
|
||||||
"Quick Favorite": "快速收藏",
|
"Quick Favorite": "快速收藏",
|
||||||
"Long press on the favorite button to quickly add to this folder": "長按收藏按鈕快速添加到這個文件夾",
|
"Long press on the favorite button to quickly add to this folder": "長按收藏按鈕快速添加到這個文件夾",
|
||||||
"Added": "已添加"
|
"Added": "已添加",
|
||||||
|
"Turn page by volume keys": "使用音量鍵翻頁"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -117,6 +117,7 @@ class _Settings with ChangeNotifier {
|
|||||||
'webdav': [], // empty means not configured
|
'webdav': [], // empty means not configured
|
||||||
'dataVersion': 0,
|
'dataVersion': 0,
|
||||||
'quickFavorite': null,
|
'quickFavorite': null,
|
||||||
|
'enableTurnPageByVolumeKey': true,
|
||||||
};
|
};
|
||||||
|
|
||||||
operator [](String key) {
|
operator [](String key) {
|
||||||
|
@@ -23,6 +23,7 @@ import 'package:venera/pages/settings/settings_page.dart';
|
|||||||
import 'package:venera/utils/file_type.dart';
|
import 'package:venera/utils/file_type.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
|
import 'package:venera/utils/volume.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
part 'scaffold.dart';
|
part 'scaffold.dart';
|
||||||
@@ -97,6 +98,8 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
|||||||
|
|
||||||
var focusNode = FocusNode();
|
var focusNode = FocusNode();
|
||||||
|
|
||||||
|
VolumeListener? volumeListener;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
page = widget.initialPage ?? 1;
|
page = widget.initialPage ?? 1;
|
||||||
@@ -107,6 +110,9 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
|||||||
updateHistory();
|
updateHistory();
|
||||||
});
|
});
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
||||||
|
if(appdata.settings['enableTurnPageByVolumeKey']) {
|
||||||
|
handleVolumeEvent();
|
||||||
|
}
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +121,7 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
|||||||
autoPageTurningTimer?.cancel();
|
autoPageTurningTimer?.cancel();
|
||||||
focusNode.dispose();
|
focusNode.dispose();
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
|
stopVolumeEvent();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +159,31 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
|||||||
HistoryManager().addHistory(history!);
|
HistoryManager().addHistory(history!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleVolumeEvent() {
|
||||||
|
if(!App.isAndroid) {
|
||||||
|
// Currently only support Android
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(volumeListener != null) {
|
||||||
|
volumeListener?.cancel();
|
||||||
|
}
|
||||||
|
volumeListener = VolumeListener(
|
||||||
|
onDown: () {
|
||||||
|
toNextPage();
|
||||||
|
},
|
||||||
|
onUp: () {
|
||||||
|
toPrevPage();
|
||||||
|
},
|
||||||
|
)..listen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopVolumeEvent() {
|
||||||
|
if(volumeListener != null) {
|
||||||
|
volumeListener?.cancel();
|
||||||
|
volumeListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract mixin class _ReaderLocation {
|
abstract mixin class _ReaderLocation {
|
||||||
|
@@ -470,6 +470,13 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
context.reader.mode = ReaderMode.fromKey(appdata.settings[key]);
|
context.reader.mode = ReaderMode.fromKey(appdata.settings[key]);
|
||||||
App.rootContext.pop();
|
App.rootContext.pop();
|
||||||
}
|
}
|
||||||
|
if (key == "enableTurnPageByVolumeKey") {
|
||||||
|
if(appdata.settings[key]) {
|
||||||
|
context.reader.handleVolumeEvent();
|
||||||
|
} else {
|
||||||
|
context.reader.stopVolumeEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
context.reader.update();
|
context.reader.update();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@@ -69,6 +69,14 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
widget.onChanged?.call('limitImageWidth');
|
widget.onChanged?.call('limitImageWidth');
|
||||||
},
|
},
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
|
if(App.isAndroid)
|
||||||
|
_SwitchSetting(
|
||||||
|
title: 'Turn page by volume key'.tl,
|
||||||
|
settingKey: 'enableTurnPageByVolumeKey',
|
||||||
|
onChanged: () {
|
||||||
|
widget.onChanged?.call('enableTurnPageByVolumeKey');
|
||||||
|
},
|
||||||
|
).toSliver(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
31
lib/utils/volume.dart
Normal file
31
lib/utils/volume.dart
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
class VolumeListener {
|
||||||
|
static const channel = EventChannel('venera/volume');
|
||||||
|
|
||||||
|
void Function()? onUp;
|
||||||
|
|
||||||
|
void Function()? onDown;
|
||||||
|
|
||||||
|
VolumeListener({this.onUp, this.onDown});
|
||||||
|
|
||||||
|
StreamSubscription? stream;
|
||||||
|
|
||||||
|
void listen() {
|
||||||
|
stream = channel.receiveBroadcastStream().listen(onEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onEvent(event) {
|
||||||
|
if (event == 1) {
|
||||||
|
onUp!();
|
||||||
|
} else if (event == 2) {
|
||||||
|
onDown!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cancel() {
|
||||||
|
stream?.cancel();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user