Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Let each tab choose what holding it does

Barnabasdc0dc5dbe1a7
diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dart
index 4c4e1389..dac9ab47 100644
--- a/lib/screens/absorbing_screen.dart
+++ b/lib/screens/absorbing_screen.dart
@@ -32,6 +32,17 @@ class AbsorbingScreen extends StatefulWidget {
globalKey.currentState?._scrollToActiveCard();
}
+ /// Open the Manage Queue sheet from outside the screen (the nav-tab hold
+ /// shortcut). Returns false when the screen hasn't been built yet, so the
+ /// caller can switch to the tab and try again.
+ static bool openQueueManager(BuildContext context) {
+ final state = globalKey.currentState;
+ if (state == null || !state.mounted) return false;
+ final lib = context.read<LibraryProvider>();
+ state._showReorderSheet(state.context, lib, state._getAbsorbingBooks(lib));
+ return true;
+ }
+
/// Scroll to the first card (used when re-tapping the Absorbing tab)
static void scrollToFirst() {
final state = globalKey.currentState;
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dart
index 38233b52..7589e929 100644
--- a/lib/screens/app_shell.dart
+++ b/lib/screens/app_shell.dart
@@ -16,7 +16,26 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:palette_generator/palette_generator.dart';
import '../utils/cover_accent.dart';
import '../main.dart'
- show snappyTransitionsNotifier, einkModeNotifier, coverSchemeNotifier, rootNavigatorKey, applyOrientationLock;
+ show snappyTransitionsNotifier, einkModeNotifier, coverSchemeNotifier, rootNavigatorKey, applyOrientationLock, applyEinkModeTheme;
+import '../services/scoped_prefs.dart';
+import 'admin_screen.dart';
+import 'admin_api_keys_screen.dart';
+import 'admin_email_screen.dart';
+import 'admin_libraries_screen.dart';
+import 'admin_server_logs_screen.dart';
+import 'admin_server_settings_screen.dart';
+import 'admin_sessions_screen.dart';
+import 'admin_stats_screen.dart';
+import 'admin_upload_screen.dart';
+import 'admin_users_screen.dart';
+import 'bookmarks_screen.dart';
+import 'downloads_screen.dart';
+import 'upcoming_releases_screen.dart';
+import '../services/ebook_cache.dart';
+import '../widgets/action_pill.dart';
+import '../widgets/ebook_router.dart';
+import '../widgets/nav_hold_options.dart';
+import '../widgets/sleep_timer_sheet.dart';
import '../l10n/app_localizations.dart';
import '../services/wording.dart';
import '../services/android_auto_service.dart';
@@ -854,29 +873,415 @@ class _AppShellState extends State<AppShell>
final width = MediaQuery.sizeOf(context).width;
if (width <= 0 || destCount <= 0) return;
final slot = (dx / (width / destCount)).floor().clamp(0, destCount - 1);
- final absorbingSlot = destCount >= 6 ? 3 : 2;
- if (slot == 0) {
- // Home: quick library switcher.
- final lib = context.read<LibraryProvider>();
- if (lib.libraries.length < 2) return;
- HapticFeedback.mediumImpact();
- showLibraryPickerSheet(context, lib);
- } else if (slot == 1) {
- // Library: focus search.
- HapticFeedback.mediumImpact();
- final lib = context.read<LibraryProvider>();
- if (_podcastsShown(lib)) _syncTabLibrary(1, true);
- _openSearch();
- } else if (slot == absorbingSlot) {
- // Absorbing: toggle playback without leaving the current tab.
- if (!_player.hasBook) return;
- HapticFeedback.mediumImpact();
- if (_player.isPlaying) {
- _player.pause();
- } else {
- _player.play(fromUi: true);
+ HapticFeedback.mediumImpact();
+ unawaited(_runNavHold(_tabForSlot(slot, destCount)));
+ }
+
+ /// Slot index to stable tab key. The Podcasts tab only exists sometimes, so
+ /// everything after it shifts by one without this.
+ String _tabForSlot(int slot, int destCount) {
+ final hasPodcasts = destCount >= 6;
+ if (slot == 0) return 'home';
+ if (slot == 1) return 'library';
+ if (hasPodcasts && slot == 2) return 'podcasts';
+ final rest = hasPodcasts ? slot - 3 : slot - 2;
+ return switch (rest) {
+ 0 => 'absorbing',
+ 1 => 'stats',
+ _ => 'settings',
+ };
+ }
+
+ Future<void> _runNavHold(String tab) async {
+ final key = navHoldPrefKey(tab);
+ var id = await ScopedPrefs.getString(key) ?? navHoldDefaults[tab];
+ if (!mounted) return;
+ final isAdmin = context.read<AuthProvider>().isAdmin;
+ // A saved admin or scan choice is dead weight on an account that lost its
+ // admin rights - ask again rather than doing nothing.
+ if (!isAdmin && (id?.startsWith('admin') == true || id?.startsWith('scan:') == true)) {
+ id = null;
+ }
+ if (id == null) {
+ final chosen = await _showNavHoldPicker(tab, isAdmin);
+ if (chosen == null || !mounted) return;
+ await ScopedPrefs.setString(key, chosen);
+ if (!mounted) return;
+ id = chosen;
+ debugPrint('[NavHold] $tab set to $id');
+ }
+ if (id == 'menu') {
+ // Always-show-menu: the saved choice stays 'menu' forever - what gets
+ // tapped here runs once and is deliberately NOT written back, otherwise
+ // the first pick would quietly replace the menu.
+ final picked = await _showNavHoldPicker(tab, isAdmin, forRun: true);
+ if (picked == null || !mounted) return;
+ debugPrint('[NavHold] $tab menu ran $picked (still menu)');
+ _runNavHoldAction(picked);
+ return;
+ }
+ debugPrint('[NavHold] $tab ran $id');
+ _runNavHoldAction(id);
+ }
+
+ /// The action grid. [forRun] is launcher mode - the sheet is the menu itself
+ /// rather than a one-time setup, so the entries that only make sense as a
+ /// saved choice are left out.
+ Future<String?> _showNavHoldPicker(String tab, bool isAdmin,
+ {bool forRun = false}) async {
+ final l = AppLocalizations.of(context)!;
+ final picked = await showModalBottomSheet<String>(
+ context: context,
+ showDragHandle: true,
+ isScrollControlled: true,
+ builder: (ctx) {
+ final tt = Theme.of(ctx).textTheme;
+ final cs = Theme.of(ctx).colorScheme;
+ return SafeArea(
+ child: SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ forRun
+ ? navHoldTabLabel(tab, l)
+ : l.navHoldPickTitle(navHoldTabLabel(tab, l)),
+ style: tt.titleMedium,
+ ),
+ if (!forRun) ...[
+ const SizedBox(height: 6),
+ Text(
+ l.navHoldPickBody,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant),
+ ),
+ ],
+ const SizedBox(height: 14),
+ ActionPillGrid(items: [
+ for (final o in navHoldOptions)
+ if ((isAdmin || (o.id != 'admin' && o.id != 'scan')) &&
+ (!forRun || (o.id != 'menu' && o.id != 'none')))
+ ActionPillData(
+ icon: o.icon,
+ label: navHoldLabel(o.id, l),
+ onTap: () => Navigator.pop(ctx, o.id),
+ ),
+ ]),
+ ],
+ ),
+ ),
+ ),
+ );
+ },
+ );
+ if (picked == null || !mounted) return null;
+ // Folders open a second sheet; anything else is the answer.
+ if (picked == 'admin') return _showNavHoldSubSheet(_adminSubItems());
+ if (picked == 'scan') return _showNavHoldSubSheet(_scanSubItems());
+ return picked;
+ }
+
+ List<(String, IconData, String)> _adminSubItems() {
+ final l = AppLocalizations.of(context)!;
+ return [
+ for (final p in navHoldAdminPages)
+ ('admin:$p', navHoldAdminIcon(p), navHoldAdminPageLabel(p, l)),
+ ];
+ }
+
+ List<(String, IconData, String)> _scanSubItems() {
+ final l = AppLocalizations.of(context)!;
+ final libs = context.read<LibraryProvider>().libraries;
+ return [
+ ('scan:all', Icons.sync_rounded, l.navHoldScanAll),
+ for (final lib in libs)
+ if ((lib['id'] as String?)?.isNotEmpty == true)
+ (
+ 'scan:${lib['id']}',
+ Icons.folder_rounded,
+ (lib['name'] as String?) ?? '',
+ ),
+ ];
+ }
+
+ Future<String?> _showNavHoldSubSheet(List<(String, IconData, String)> items) {
+ return showModalBottomSheet<String>(
+ context: context,
+ showDragHandle: true,
+ isScrollControlled: true,
+ builder: (ctx) => SafeArea(
+ child: SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
+ child: ActionPillGrid(items: [
+ for (final (id, icon, label) in items)
+ ActionPillData(
+ icon: icon,
+ label: label,
+ onTap: () => Navigator.pop(ctx, id),
+ ),
+ ]),
+ ),
+ ),
+ ),
+ );
+ }
+
+ void _runNavHoldAction(String id) {
+ if (id.startsWith('admin:')) {
+ unawaited(_openAdminPage(id.substring(6)));
+ return;
+ }
+ if (id.startsWith('scan:')) {
+ unawaited(_runServerScan(id.substring(5)));
+ return;
+ }
+ switch (id) {
+ case 'search':
+ final lib = context.read<LibraryProvider>();
+ if (_podcastsShown(lib)) _syncTabLibrary(1, true);
+ _openSearch();
+ case 'switchLibrary':
+ final lib = context.read<LibraryProvider>();
+ if (lib.libraries.length < 2) return;
+ showLibraryPickerSheet(context, lib);
+ case 'bookmarks':
+ Navigator.push(context,
+ MaterialPageRoute(builder: (_) => const BookmarksScreen()));
+ case 'downloads':
+ Navigator.push(context,
+ MaterialPageRoute(builder: (_) => const DownloadsScreen()));
+ case 'admin':
+ Navigator.push(
+ context, MaterialPageRoute(builder: (_) => const AdminScreen()));
+ case 'sleep':
+ showSleepTimerSheet(context, Theme.of(context).colorScheme.primary);
+ case 'eink':
+ final v = !PlayerSettings.einkMode;
+ PlayerSettings.setEinkMode(v);
+ applyEinkModeTheme(v);
+ context.read<LibraryProvider>().applyEinkMode(v);
+ case 'playPause':
+ // Nothing loaded at all: start the front card rather than doing
+ // nothing, so the shortcut always plays something.
+ if (!_player.hasBook) {
+ unawaited(_playFrontCard());
+ return;
+ }
+ if (_player.isPlaying) {
+ _player.pause();
+ } else {
+ _player.play(fromUi: true);
+ }
+ case 'stop':
+ if (!_player.hasBook) return;
+ unawaited(_player.stop());
+ case 'queue':
+ // The Absorbing page is built lazily, and the sheet lives on it - if
+ // it isn't up yet, switch to the tab and open the sheet once it is.
+ if (!AbsorbingScreen.openQueueManager(context)) {
+ _switchToAbsorbing();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) AbsorbingScreen.openQueueManager(context);
+ });
+ }
+ case 'offline':
+ final lib = context.read<LibraryProvider>();
+ final going = !lib.isOffline;
+ unawaited(lib.setManualOffline(going));
+ showOverlayToast(
+ context,
+ going
+ ? AppLocalizations.of(context)!.navHoldOfflineOn
+ : AppLocalizations.of(context)!.navHoldOfflineOff,
+ icon: going ? Icons.cloud_off_rounded : Icons.cloud_done_rounded,
+ );
+ case 'readBook':
+ unawaited(_openCurrentEbook());
+ case 'scanSeries':
+ Navigator.push(
+ context,
+ MaterialPageRoute(
+ builder: (_) =>
+ const UpcomingReleasesScreen(openScanChooser: true)));
+ case 'none':
+ break;
+ }
+ }
+
+ /// Push an Admin page straight from the nav bar. Most of them need the user
+ /// or library lists the Admin hub normally loads, so fetch just those first
+ /// - the hub itself stays the fallback if a fetch comes back empty.
+ Future<void> _openAdminPage(String page) async {
+ final api = context.read<AuthProvider>().apiService;
+ if (api == null) return;
+ Widget? screen;
+ switch (page) {
+ case 'settings':
+ screen = const AdminServerSettingsScreen();
+ case 'logs':
+ screen = const AdminServerLogsScreen();
+ case 'stats':
+ screen = const AdminStatsScreen();
+ case 'users':
+ final r = await Future.wait(
+ [api.getUsers(), api.getOnlineUsers(), api.getLibraries()]);
+ screen = AdminUsersScreen(
+ users: r[0], onlineUsers: r[1], libraries: r[2]);
+ case 'sessions':
+ screen = AdminSessionsScreen(users: await api.getUsers());
+ case 'email':
+ screen = AdminEmailScreen(users: await api.getUsers());
+ case 'apikeys':
+ screen = AdminApiKeysScreen(users: await api.getUsers());
+ case 'libraries':
+ screen = AdminLibrariesScreen(libraries: await api.getLibraries());
+ case 'upload':
+ if (!mounted) return;
+ screen = AdminUploadScreen(
+ libraries: await api.getLibraries(),
+ initialLibraryId: context.read<AuthProvider>().defaultLibraryId,
+ apiService: api,
+ );
+ default:
+ screen = const AdminScreen();
+ }
+ if (!mounted) return;
+ await Navigator.push(
+ context, MaterialPageRoute(builder: (_) => screen!));
+ }
+
+ /// Kick off a server-side scan of one library, or every library.
+ Future<void> _runServerScan(String target) async {
+ final l = AppLocalizations.of(context)!;
+ final api = context.read<AuthProvider>().apiService;
+ if (api == null) return;
+ final libs = context.read<LibraryProvider>().libraries;
+ final ids = target == 'all'
+ ? [
+ for (final lib in libs)
+ if ((lib['id'] as String?)?.isNotEmpty == true) lib['id'] as String
+ ]
+ : [target];
+ if (ids.isEmpty) return;
+ var ok = false;
+ for (final id in ids) {
+ if (await api.scanLibrary(id)) ok = true;
+ }
+ if (!mounted) return;
+ showOverlayToast(
+ context,
+ ok ? l.navHoldScanStarted : l.navHoldScanFailed,
+ icon: ok ? Icons.sync_rounded : Icons.error_outline_rounded,
+ );
+ }
+
+ /// The item behind the front Absorbing card - what the user sees first when
+ /// nothing is playing. The absorbing order is the card order.
+ Map<String, dynamic>? _frontAbsorbingItem() {
+ final lib = context.read<LibraryProvider>();
+ for (final key in lib.absorbingBookIds) {
+ final item = lib.absorbingItemCache[key];
+ if (item != null) return item;
+ }
+ return null;
+ }
+
+ /// Start the front Absorbing card. Podcast episodes carry their episode in
+ /// the cached entry; books need the full item for chapters and duration.
+ Future<void> _playFrontCard() async {
+ final l = AppLocalizations.of(context)!;
+ final item = _frontAbsorbingItem();
+ final api = context.read<AuthProvider>().apiService;
+ final itemId = item?['id'] as String?;
+ if (item == null || itemId == null || api == null) {
+ showOverlayToast(context, l.navHoldNothingPlaying,
+ icon: Icons.play_disabled_rounded);
+ return;
+ }
+ final lib = context.read<LibraryProvider>();
+ final coverUrl = lib.getCoverUrl(itemId);
+ final episode = item['recentEpisode'] as Map<String, dynamic>?;
+ if (episode != null) {
+ final media = item['media'] as Map<String, dynamic>? ?? {};
+ final metadata = media['metadata'] as Map<String, dynamic>? ?? {};
+ final error = await _player.playItem(
+ api: api,
+ itemId: itemId,
+ title: episode['title'] as String? ?? '',
+ author: metadata['title'] as String? ?? '',
+ coverUrl: coverUrl,
+ totalDuration: (episode['duration'] as num?)?.toDouble() ?? 0,
+ chapters: const [],
+ episodeId: episode['id'] as String?,
+ episodeTitle: episode['title'] as String?,
+ libraryId: item['libraryId'] as String?,
+ fromUi: true,
+ );
+ if (mounted && error != null) showOverlayToast(context, error, icon: Icons.error_outline_rounded);
+ return;
+ }
+ final full = await api.getLibraryItem(itemId) ?? item;
+ if (!mounted) return;
+ final media = full['media'] as Map<String, dynamic>? ?? {};
+ final metadata = media['metadata'] as Map<String, dynamic>? ?? {};
+ final error = await _player.playItem(
+ api: api,
+ itemId: itemId,
+ title: metadata['title'] as String? ?? '',
+ author: metadata['authorName'] as String? ?? '',
+ coverUrl: coverUrl,
+ totalDuration: (media['duration'] as num?)?.toDouble() ?? 0,
+ chapters: (media['chapters'] as List<dynamic>?) ?? const [],
+ libraryId: full['libraryId'] as String?,
+ fromUi: true,
+ );
+ if (mounted && error != null) showOverlayToast(context, error, icon: Icons.error_outline_rounded);
+ }
+
+ /// Open the playing (or last-played) book's ebook, falling back to the front
+ /// Absorbing card when nothing is loaded. The reader cache is checked first
+ /// so this works with no signal, same as the player card's Read button.
+ Future<void> _openCurrentEbook() async {
+ final l = AppLocalizations.of(context)!;
+ final front = _player.hasBook ? null : _frontAbsorbingItem();
+ final itemId = _player.currentItemId ?? front?['id'] as String?;
+ var title = _player.currentTitle ?? '';
+ if (front != null) {
+ final metadata = (front['media'] as Map<String, dynamic>?)?['metadata']
+ as Map<String, dynamic>?;
+ title = metadata?['title'] as String? ?? title;
+ }
+ if (itemId == null) {
+ showOverlayToast(context, l.noEbookFileFound,
+ icon: Icons.menu_book_outlined);
+ return;
+ }
+ var ebookFile = await cachedEbookFileFor(itemId);
+ if (!mounted) return;
+ if (ebookFile == null) {
+ final api = context.read<AuthProvider>().apiService;
+ if (api != null) {
+ try {
+ final item = await api.getLibraryItem(itemId);
+ ebookFile = resolveEbookFile(item);
+ } catch (_) {}
}
}
+ if (!mounted) return;
+ if (ebookFile == null) {
+ showOverlayToast(context, l.noEbookFileFound,
+ icon: Icons.menu_book_outlined);
+ return;
+ }
+ await openEbookReader(
+ context,
+ itemId: itemId,
+ title: title,
+ ebookFile: ebookFile,
+ );
}
List<NavigationDestination> _buildDestinations(
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index e0bbe146..4dad0c69 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -23,6 +23,7 @@ import '../build_info.dart';
import '../services/update_checker_service.dart';
import '../services/audiobookshelf_update_service.dart';
import '../widgets/update_dialog.dart';
+import '../widgets/nav_hold_options.dart';
import '../screens/admin_screen.dart';
import '../screens/downloads_screen.dart';
import '../screens/bookmarks_screen.dart';
@@ -434,6 +435,84 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
+ Future<void> _showNavHoldDialog() async {
+ final l = AppLocalizations.of(context)!;
+ final isAdmin = context.read<AuthProvider>().isAdmin;
+ final libraries = context.read<LibraryProvider>().libraries;
+ final ids = navHoldAllIds(
+ isAdmin: isAdmin,
+ libraryIds: [
+ for (final lib in libraries)
+ if ((lib['id'] as String?)?.isNotEmpty == true) lib['id'] as String,
+ ],
+ );
+ final validIds = ids.toSet();
+ final podcastTab = await PlayerSettings.getPodcastTabEnabled();
+ final tabs = navHoldTabs
+ .where((t) => t != 'podcasts' || podcastTab)
+ .toList();
+ final chosen = <String, String?>{};
+ for (final tab in tabs) {
+ final saved = await ScopedPrefs.getString(navHoldPrefKey(tab)) ??
+ navHoldDefaults[tab];
+ chosen[tab] = validIds.contains(saved) ? saved : null;
+ }
+ if (!mounted) return;
+ String? libraryName(String id) {
+ for (final lib in libraries) {
+ if (lib['id'] == id) return lib['name'] as String?;
+ }
+ return null;
+ }
+ await showDialog<void>(
+ context: context,
+ builder: (ctx) => StatefulBuilder(
+ builder: (ctx, setDialogState) => AlertDialog(
+ title: Text(l.navHoldSettingTitle),
+ content: SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ for (final tab in tabs) ...[
+ DropdownButtonFormField<String?>(
+ initialValue: chosen[tab],
+ decoration:
+ InputDecoration(labelText: navHoldTabLabel(tab, l)),
+ items: [
+ DropdownMenuItem<String?>(
+ value: null, child: Text(l.navHoldAskNextTime)),
+ for (final id in ids)
+ DropdownMenuItem<String?>(
+ value: id,
+ child: Text(
+ navHoldLabel(id, l, libraryName: libraryName),
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ],
+ onChanged: (v) {
+ setDialogState(() => chosen[tab] = v);
+ v == null
+ ? ScopedPrefs.remove(navHoldPrefKey(tab))
+ : ScopedPrefs.setString(navHoldPrefKey(tab), v);
+ },
+ ),
+ if (tab != tabs.last) const SizedBox(height: 12),
+ ],
+ ],
+ ),
+ ),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.pop(ctx),
+ child: Text(l.done),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
Future<void> _showCustomColorDialog() async {
var picked = Color(_manualSeed);
final l = AppLocalizations.of(context)!;
@@ -3762,6 +3841,14 @@ class _SettingsScreenState extends State<SettingsScreen> {
isExpanded: _expandedSection == 'Advanced',
onExpansionChanged: (v) => _onSectionExpanded('Advanced', v),
children: [
+ ListTile(
+ title: Text(l.navHoldSettingTitle),
+ subtitle: Text(l.navHoldSettingSubtitle,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ trailing: const Icon(Icons.chevron_right_rounded),
+ onTap: _showNavHoldDialog,
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
SwitchListTile(
title: Row(children: [
Flexible(child: Text(l.localServer)),
diff --git a/lib/screens/upcoming_releases_screen.dart b/lib/screens/upcoming_releases_screen.dart
index e0af07d8..db28a93d 100644
--- a/lib/screens/upcoming_releases_screen.dart
+++ b/lib/screens/upcoming_releases_screen.dart
@@ -20,7 +20,10 @@ import '../widgets/stackable_sheet.dart';
import '../l10n/app_localizations.dart';
class UpcomingReleasesScreen extends StatefulWidget {
- const UpcomingReleasesScreen({super.key});
+ /// Opens the Scan series chooser as soon as the screen is up, for entry
+ /// points whose whole purpose is starting a scan (the nav-tab shortcut).
+ final bool openScanChooser;
+ const UpcomingReleasesScreen({super.key, this.openScanChooser = false});
@override
State<UpcomingReleasesScreen> createState() => _UpcomingReleasesScreenState();
@@ -43,6 +46,13 @@ class _UpcomingReleasesScreenState extends State<UpcomingReleasesScreen> {
_service.addListener(_onServiceChanged);
_initAndStart();
_loadRmabConfigured();
+ if (widget.openScanChooser) {
+ // After the first frame so the sheet has a laid-out screen behind it,
+ // and not while a scan the screen kicked off itself is already running.
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted && !_service.isRunning) _showScanChooserSheet();
+ });
+ }
}
Future<void> _loadRmabConfigured() async {
diff --git a/lib/widgets/nav_hold_options.dart b/lib/widgets/nav_hold_options.dart
new file mode 100644
index 00000000..c2341bfe
--- /dev/null
+++ b/lib/widgets/nav_hold_options.dart
@@ -0,0 +1,154 @@
+import 'package:flutter/material.dart';
+import '../l10n/app_localizations.dart';
+
+/// One choice for what holding a nav tab does. The shell maps ids to the
+/// actual actions; the settings dialog only needs ids, icons and labels for
+/// its pickers, so the two can't drift apart on what exists.
+///
+/// Ids are flat strings, including the composite ones (`admin:users`,
+/// `scan:<libraryId>`), so a choice is one value in prefs and one value in a
+/// dropdown.
+class NavHoldOption {
+ final String id;
+ final IconData icon;
+
+ /// Opens a second sheet of choices rather than doing something itself.
+ final bool isFolder;
+ const NavHoldOption(this.id, this.icon, {this.isFolder = false});
+}
+
+const navHoldOptions = [
+ NavHoldOption('search', Icons.search_rounded),
+ NavHoldOption('switchLibrary', Icons.swap_horiz_rounded),
+ NavHoldOption('bookmarks', Icons.bookmarks_rounded),
+ NavHoldOption('downloads', Icons.download_rounded),
+ NavHoldOption('sleep', Icons.bedtime_rounded),
+ NavHoldOption('eink', Icons.contrast),
+ NavHoldOption('playPause', Icons.play_arrow_rounded),
+ NavHoldOption('stop', Icons.stop_rounded),
+ NavHoldOption('queue', Icons.queue_music_rounded),
+ NavHoldOption('offline', Icons.cloud_off_rounded),
+ NavHoldOption('readBook', Icons.menu_book_rounded),
+ NavHoldOption('scanSeries', Icons.travel_explore_rounded),
+ NavHoldOption('admin', Icons.admin_panel_settings_rounded, isFolder: true),
+ NavHoldOption('scan', Icons.sync_rounded, isFolder: true),
+ NavHoldOption('menu', Icons.apps_rounded),
+ NavHoldOption('none', Icons.block_rounded),
+];
+
+/// Pages inside the Admin area a hold can open directly, as `admin:<page>`.
+const navHoldAdminPages = [
+ 'home',
+ 'users',
+ 'sessions',
+ 'libraries',
+ 'upload',
+ 'email',
+ 'apikeys',
+ 'settings',
+ 'logs',
+ 'stats',
+];
+
+IconData navHoldAdminIcon(String page) => switch (page) {
+ 'home' => Icons.admin_panel_settings_rounded,
+ 'users' => Icons.people_rounded,
+ 'sessions' => Icons.history_rounded,
+ 'libraries' => Icons.library_books_rounded,
+ 'upload' => Icons.cloud_upload_rounded,
+ 'email' => Icons.email_rounded,
+ 'apikeys' => Icons.vpn_key_rounded,
+ 'settings' => Icons.tune_rounded,
+ 'logs' => Icons.description_outlined,
+ _ => Icons.bar_chart_rounded,
+ };
+
+String navHoldAdminPageLabel(String page, AppLocalizations l) => switch (page) {
+ 'home' => l.adminTitle,
+ 'users' => l.adminUsers,
+ 'sessions' => l.adminAllSessions,
+ 'libraries' => l.adminLibrariesManage,
+ 'upload' => l.adminUploadTitle,
+ 'email' => l.adminEmail,
+ 'apikeys' => l.adminApiKeys,
+ 'settings' => l.adminServerSettings,
+ 'logs' => l.navHoldAdminLogs,
+ _ => l.adminStats,
+ };
+
+/// Label for any id, composites included. [libraryName] resolves a library id
+/// for `scan:<id>`; without it the scan falls back to the generic label.
+String navHoldLabel(
+ String id,
+ AppLocalizations l, {
+ String? Function(String libraryId)? libraryName,
+}) {
+ if (id.startsWith('admin:')) {
+ final page = id.substring(6);
+ return page == 'home'
+ ? l.adminTitle
+ : l.navHoldAdminPage(navHoldAdminPageLabel(page, l));
+ }
+ if (id.startsWith('scan:')) {
+ final target = id.substring(5);
+ if (target == 'all') return l.navHoldScanAll;
+ final name = libraryName?.call(target);
+ return name == null ? l.navHoldServerScan : l.navHoldScanLibrary(name);
+ }
+ return switch (id) {
+ 'search' => l.search,
+ 'switchLibrary' => l.switchLibraryTooltip,
+ 'bookmarks' => l.bookmarksTitle,
+ 'downloads' => l.downloads,
+ 'admin' => l.admin,
+ 'scan' => l.navHoldServerScan,
+ 'sleep' => l.sleepTimer,
+ 'eink' => l.einkModeLabel,
+ 'playPause' => l.navHoldPlayPause,
+ 'stop' => l.navHoldStop,
+ 'queue' => l.absorbingManageQueue,
+ 'offline' => l.navHoldOfflineMode,
+ 'readBook' => l.navHoldReadBook,
+ 'scanSeries' => l.upcomingReleasesScanSeries,
+ 'menu' => l.navHoldMenu,
+ 'none' => l.navHoldNothing,
+ _ => id,
+ };
+}
+
+/// Every id a saved choice may hold, in the order the settings dropdown shows
+/// them. Admin entries and server scans are only offered to admins.
+List<String> navHoldAllIds({
+ required bool isAdmin,
+ required List<String> libraryIds,
+}) =>
+ [
+ for (final o in navHoldOptions)
+ if (!o.isFolder) o.id,
+ if (isAdmin) ...[
+ for (final p in navHoldAdminPages) 'admin:$p',
+ 'scan:all',
+ for (final id in libraryIds) 'scan:$id',
+ ],
+ ];
+
+/// Stable per-tab keys, so a hold choice follows the tab rather than its
+/// position - the Podcasts tab appears and disappears, which would shift
+/// every slot index after it.
+const navHoldTabs = ['home', 'library', 'podcasts', 'absorbing', 'stats', 'settings'];
+
+/// Absorbing has toggled playback on hold since before this was
+/// configurable; keep that as its starting point instead of asking.
+const navHoldDefaults = {'absorbing': 'playPause'};
+
+String navHoldPrefKey(String tab) => 'navHold_$tab';
+
+String navHoldTabLabel(String tab, AppLocalizations l) => switch (tab) {
+ 'home' => l.appShellHomeTab,
+ 'library' => l.appShellLibraryTab,
+ 'podcasts' => l.appShellPodcastsTab,
+ 'absorbing' => l.appShellAbsorbingTab,
+ 'stats' => l.appShellStatsTab,
+ 'settings' => l.appShellSettingsTab,
+ _ => tab,
+ };