Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Let a physical page-turn button flip pages in the reader and play or pause outside it

Barnabasfc1878a2d74c
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
index 156a41ac..890413d5 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
@@ -236,6 +236,25 @@ class MainActivity : AudioServiceActivity() {
return super.onKeyUp(keyCode, event)
}
+ // Physical page-turn keys - e-ink devices like the Boox Palma map their
+ // side button to these. They must be grabbed BEFORE the view tree: a
+ // focused WebView treats PAGE_UP/DOWN as scroll keys and shifts the
+ // paginated book vertically instead of letting the app turn the page.
+ // The Dart side decides what they do (page turn in the reader, play/pause
+ // toggle otherwise).
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.keyCode == KeyEvent.KEYCODE_PAGE_UP ||
+ event.keyCode == KeyEvent.KEYCODE_PAGE_DOWN) {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ volumeKeysChannel?.invokeMethod(
+ "pagePressed",
+ if (event.keyCode == KeyEvent.KEYCODE_PAGE_UP) "up" else "down")
+ }
+ return true
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
// Move downloaded temp files into the user's SAF folder, creating the nested
// [subfolder] (e.g. "Author/Title") under the granted tree via the DocumentFile
// chain so files nest correctly and stay readable through the original grant.
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dart
index 634a1914..38233b52 100644
--- a/lib/screens/app_shell.dart
+++ b/lib/screens/app_shell.dart
@@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import '../providers/library_provider.dart';
import '../services/audio_player_service.dart';
+import '../services/volume_key_service.dart';
import '../services/chromecast_service.dart';
import '../services/home_widget_service.dart';
import '../services/sleep_timer_service.dart';
@@ -326,6 +327,7 @@ class _AppShellState extends State<AppShell>
void initState() {
super.initState();
_instance = this;
+ EreaderVolumeNav.ensureHandler();
if (!widget.startOnAbsorbing) _loadStartScreen();
_ensurePageBuilt(_currentIndex);
_playerHadBook = _player.hasBook;
diff --git a/lib/services/volume_key_service.dart b/lib/services/volume_key_service.dart
index 32fd9d1b..0d933092 100644
--- a/lib/services/volume_key_service.dart
+++ b/lib/services/volume_key_service.dart
@@ -69,17 +69,47 @@ class EreaderVolumeNav with WidgetsBindingObserver {
} catch (_) {}
}
+ /// Registers the channel handler app-wide so physical page keys work before
+ /// any reader has opened - outside the reader they toggle play/pause.
+ static void ensureHandler() => _channel.setMethodCallHandler(_onCall);
+
static Future<dynamic> _onCall(MethodCall call) async {
- if (call.method != 'volumePressed') return null;
final nav = _active;
- if (nav == null || !nav._watching) return null;
final up = (call.arguments as String? ?? '') == 'up';
- // 'normal' matches the ABS app: volume up = previous page, down = next.
- final prev = nav._mode == 'mirrored' ? !up : up;
- if (prev) {
- nav.onPrev();
- } else {
- nav.onNext();
+ if (call.method == 'volumePressed') {
+ if (nav == null || !nav._watching) return null;
+ // 'normal' matches the ABS app: volume up = previous page, down = next.
+ final prev = nav._mode == 'mirrored' ? !up : up;
+ if (prev) {
+ nav.onPrev();
+ } else {
+ nav.onNext();
+ }
+ return null;
+ }
+ if (call.method == 'pagePressed') {
+ // Dedicated page keys (Boox Palma side button and page-turn covers).
+ // While a reader is open they always turn pages - no setting needed,
+ // that is their whole job. Otherwise they toggle play/pause so the
+ // button stays useful while just listening.
+ if (nav != null) {
+ final prev = nav._mode == 'mirrored' ? !up : up;
+ if (prev) {
+ nav.onPrev();
+ } else {
+ nav.onNext();
+ }
+ return null;
+ }
+ final player = AudioPlayerService();
+ if (player.currentItemId != null) {
+ if (player.isPlaying) {
+ player.pause();
+ } else {
+ player.play(fromUi: true, logDetail: 'page key');
+ }
+ }
+ return null;
}
return null;
}