A cross platform Audiobookshelf client for Android and iOS
Dart
Add a cover size setting and stop big library grids crashing the app
Barnabas15ddaca35c1e
diff --git a/lib/main.dart b/lib/main.dartindex d4e173c9..9aad6e21 100644--- a/lib/main.dart+++ b/lib/main.dart@@ -196,6 +196,7 @@ void main() async {classicWordingNotifier.value = await PlayerSettings.getClassicWording();PlayerSettings.showExplicitBadge = await PlayerSettings.getShowExplicitBadge();PlayerSettings.mp3IndexSeeking = await PlayerSettings.getMp3IndexSeeking();+ PlayerSettings.coverSize = await PlayerSettings.getCoverSize();// Restore last cover seed color so the theme doesn't flash on startup{final seedInt = await PlayerSettings.getCoverSeedColor();@@ -610,6 +611,7 @@ class _AuthGateState extends State<AuthGate> {classicWordingNotifier.value = await PlayerSettings.getClassicWording();PlayerSettings.showExplicitBadge = await PlayerSettings.getShowExplicitBadge();PlayerSettings.mp3IndexSeeking = await PlayerSettings.getMp3IndexSeeking();+ PlayerSettings.coverSize = await PlayerSettings.getCoverSize();// Rotation lock: main() applied it before scope was active, so that pass// read the never-written unscoped key and always came up unlocked. The// timeout matters: on a headless boot (Android Auto bind) there is nodiff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dartindex 5994015e..51c67f85 100644--- a/lib/providers/auth_provider.dart+++ b/lib/providers/auth_provider.dart@@ -1270,6 +1270,7 @@ class AuthProvider extends ChangeNotifier {PlayerSettings.showExplicitBadge =await PlayerSettings.getShowExplicitBadge();PlayerSettings.mp3IndexSeeking = await PlayerSettings.getMp3IndexSeeking();+ PlayerSettings.coverSize = await PlayerSettings.getCoverSize();// Reload EQ settings from the new account's scope. Without this the// EqualizerService singleton keeps the previous account's in-memorydiff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dartindex 129f24e0..2a7d048c 100644--- a/lib/screens/library_screen.dart+++ b/lib/screens/library_screen.dart@@ -32,6 +32,7 @@ import 'admin_podcasts_screen.dart';import 'app_shell.dart';import 'upcoming_releases_screen.dart';import '../widgets/audible_series_sheet.dart' show showAudibleRegionPicker;+import '../widgets/books_sheet_shared.dart' show coverGridCount;import '../widgets/offline_status_icon.dart';import '../widgets/rmab_config_sheet.dart'show kRmabBaseUrlKey, kRmabApiTokenKey;@@ -41,12 +42,9 @@ import '../services/scoped_prefs.dart';import '../services/user_account_service.dart';import '../l10n/app_localizations.dart';-/// Responsive grid column count based on available width.-/// Returns 3 on phones, scales up on tablets/iPads.-int responsiveGridCount(BuildContext context) {- final width = MediaQuery.of(context).size.width;- return (width / 130).floor().clamp(3, 10);-}+/// Responsive grid column count based on available width and the cover size+/// setting; scales up on tablets/iPads.+int responsiveGridCount(BuildContext context) => coverGridCount(context);/// Bottom padding for the library tab grids/lists so the last row clears the/// floating tab bar (`Library/Series/Authors/Narrators`) plus the AppShell@@ -2710,8 +2708,8 @@ class LibraryScreenState extends State<LibraryScreen>? 156: ((_filter != LibraryFilter.none ||_seriesFilter != SeriesFilter.none)- ? 196- : 184),+ ? 204+ : 192),backgroundColor: scaffoldBg,surfaceTintColor: Colors.transparent,elevation: 0,diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dartindex cf648c1a..3b22d58d 100644--- a/lib/screens/settings_screen.dart+++ b/lib/screens/settings_screen.dart@@ -131,6 +131,7 @@ class _SettingsScreenState extends State<SettingsScreen> {bool _snappyTransitions = false;bool _classicWording = false;bool _rectangleCovers = false;+ String _coverSize = 'medium';// Per-library overrides shown in the Library section, scoped to whichever// library is currently selected (scales to accounts with many libraries -// no giant list, just "whatever you're browsing right now").@@ -826,6 +827,7 @@ class _SettingsScreenState extends State<SettingsScreen> {final s = results[0] as AutoRewindSettings;final progressScale = results.last as double;final mp3IndexSeek = await PlayerSettings.getMp3IndexSeeking();+ final coverSize = await PlayerSettings.getCoverSize();final flatBackground = await PlayerSettings.getFlatBackground();final colorSource = await PlayerSettings.getColorSource();final manualSeed = await PlayerSettings.getManualSeedColor();@@ -966,6 +968,7 @@ class _SettingsScreenState extends State<SettingsScreen> {_startScreen = startScreen;// cardBtnLayout removed (now managed in edit sheet)_rectangleCovers = rectCovers;+ _coverSize = coverSize;_coverPlayButton = coverPlay;_cardBackground = cardBg;_progressTextScale = progressScale;@@ -1745,6 +1748,42 @@ class _SettingsScreenState extends State<SettingsScreen> {} : null,),const Divider(height: 1, indent: 16, endIndent: 16),+ Padding(+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(l.coverSize, style: tt.titleSmall),+ const SizedBox(height: 4),+ Text(+ l.coverSizeSubtitle,+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant),+ ),+ const SizedBox(height: 12),+ SizedBox(+ width: double.infinity,+ child: SegmentedButton<String>(+ showSelectedIcon: false,+ segments: [+ ButtonSegment(value: 'small', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.coverSizeSmall, maxLines: 1))),+ ButtonSegment(value: 'medium', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.coverSizeMedium, maxLines: 1))),+ ButtonSegment(value: 'large', label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.coverSizeLarge, maxLines: 1))),+ ],+ selected: {_coverSize},+ onSelectionChanged: _loaded ? (selected) {+ final v = selected.first;+ setState(() => _coverSize = v);+ PlayerSettings.setCoverSize(v);+ } : null,+ style: const ButtonStyle(+ visualDensity: VisualDensity.compact,+ ),+ ),+ ),+ ],+ ),+ ),+ const Divider(height: 1, indent: 16, endIndent: 16),SwitchListTile(title: const Text('Classic wording'),subtitle: Text(diff --git a/lib/services/backup_service.dart b/lib/services/backup_service.dartindex 65737fb0..f17afe4a 100644--- a/lib/services/backup_service.dart+++ b/lib/services/backup_service.dart@@ -87,6 +87,7 @@ class BackupService {'cardSingleRow': await PlayerSettings.getCardSingleRow(),'cardMoreInline': await PlayerSettings.getCardMoreInline(),'rectangleCovers': await PlayerSettings.getRectangleCovers(),+ 'coverSize': await PlayerSettings.getCoverSize(),'coverPlayButton': await PlayerSettings.getCoverPlayButton(),'whenFinished': await PlayerSettings.getWhenFinished(),'sleepRewindSeconds': await PlayerSettings.getSleepRewindSeconds(),@@ -536,6 +537,7 @@ class BackupService {if (s['cardSingleRow'] != null) PlayerSettings.setCardSingleRow(s['cardSingleRow'] as bool);if (s['cardMoreInline'] != null) PlayerSettings.setCardMoreInline(s['cardMoreInline'] as bool);if (s['rectangleCovers'] != null) PlayerSettings.setRectangleCovers(s['rectangleCovers'] as bool);+ if (s['coverSize'] != null) PlayerSettings.setCoverSize(s['coverSize'] as String);if (s['coverPlayButton'] != null) PlayerSettings.setCoverPlayButton(s['coverPlayButton'] as bool);if (s['sleepRewindSeconds'] != null) PlayerSettings.setSleepRewindSeconds(s['sleepRewindSeconds'] as int);if (s['sleepTimerTab'] != null) PlayerSettings.setSleepTimerTab(s['sleepTimerTab'] as int);diff --git a/lib/services/player_settings.dart b/lib/services/player_settings.dartindex e0c5fffb..4fdd4d14 100644--- a/lib/services/player_settings.dart+++ b/lib/services/player_settings.dart@@ -925,6 +925,15 @@ class PlayerSettings {static Future<bool> getRectangleCovers() => _get('rectangleCovers', false);static Future<void> setRectangleCovers(bool value) => _set('rectangleCovers', value, notify: true);+ /// Cached value for synchronous access in grid builders.+ /// 'small' | 'medium' | 'large'; medium keeps the long-standing layout.+ static String coverSize = 'medium';+ static Future<String> getCoverSize() => _get('coverSize', 'medium');+ static Future<void> setCoverSize(String value) async {+ coverSize = value;+ await _set('coverSize', value, notify: true);+ }+/// Per-library cover-shape override: 'rect', 'square', or null (= follow/// the global toggle). Lets an ebook library run tall covers while the/// audiobook libraries stay square.diff --git a/lib/widgets/books_sheet_shared.dart b/lib/widgets/books_sheet_shared.dartindex df484596..86ba6694 100644--- a/lib/widgets/books_sheet_shared.dart+++ b/lib/widgets/books_sheet_shared.dart@@ -21,13 +21,50 @@ void registerBookCovers(LibraryProvider lib, Iterable<Map<String, dynamic>> book}}+/// Column count for cover grids. Small/large scale the width-based medium+/// count by a third, so phones land on exactly 4/3/2 columns no matter their+/// display scale while tablets move proportionally (e.g. 8/6/4).+int coverGridCount(BuildContext context) {+ final width = MediaQuery.of(context).size.width;+ final base = (width / 130).floor().clamp(3, 10);+ switch (PlayerSettings.coverSize) {+ case 'small':+ return ((base * 4) / 3).round().clamp(4, 12);+ case 'large':+ return ((base * 2) / 3).round().clamp(2, 10);+ default:+ return base;+ }+}++/// Label scale for cover-grid tiles: 1.0 at the stock phone tile width and+/// growing with the tile, so big tablet or large-cover grids don't pair big+/// covers with tiny labels. Never shrinks below 1.0 on dense grids.+double coverGridTextScale(BuildContext context) {+ final columns = coverGridCount(context);+ final width = MediaQuery.of(context).size.width;+ final tile = (width - 32 - 10 * (columns - 1)) / columns;+ return (tile / 120).clamp(1.0, 1.5);+}++/// Decode width in physical pixels for a cover in the current grid. Disk+/// caching only saves the download - every tile scrolled into view still+/// decodes its bitmap, so decoding at tile size instead of the full server+/// cover is what keeps a long scroll from ballooning memory.+int coverGridDecodeWidth(BuildContext context) {+ final columns = coverGridCount(context);+ final mq = MediaQuery.of(context);+ final tile = (mq.size.width - 32 - 10 * (columns - 1)) / columns;+ return (tile * mq.devicePixelRatio).round();+}+/// Standard grid delegate for book grids inside sheets.SliverGridDelegateWithFixedCrossAxisCount sheetBookGridDelegate(BuildContext context, {double childAspectRatio = 0.55,}) {return SliverGridDelegateWithFixedCrossAxisCount(- crossAxisCount: (MediaQuery.of(context).size.width / 130).floor().clamp(3, 10),+ crossAxisCount: coverGridCount(context),mainAxisSpacing: 8,crossAxisSpacing: 8,childAspectRatio: childAspectRatio,diff --git a/lib/widgets/collection_detail_sheet.dart b/lib/widgets/collection_detail_sheet.dartindex 4b2871cd..35cae49b 100644--- a/lib/widgets/collection_detail_sheet.dart+++ b/lib/widgets/collection_detail_sheet.dart@@ -14,6 +14,7 @@ import '../services/audio_player_service.dart';import '../services/download_service.dart';import 'add_books_search_sheet.dart';import 'book_detail_sheet.dart';+import 'books_sheet_shared.dart' show coverGridCount;import 'editable_sheet_item.dart';import 'stackable_sheet.dart';import 'swipe_action.dart';@@ -580,8 +581,8 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {controller: widget.scrollController,padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4).copyWith(bottom: 40),- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(- crossAxisCount: 3,+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(+ crossAxisCount: coverGridCount(context),mainAxisSpacing: 12,crossAxisSpacing: 12,childAspectRatio: 0.62,diff --git a/lib/widgets/finished_books_this_year_sheet.dart b/lib/widgets/finished_books_this_year_sheet.dartindex 033657b6..5222335b 100644--- a/lib/widgets/finished_books_this_year_sheet.dart+++ b/lib/widgets/finished_books_this_year_sheet.dart@@ -9,6 +9,7 @@ import '../providers/library_provider.dart';import '../services/audio_player_service.dart';import '../services/download_service.dart';import 'book_detail_sheet.dart';+import 'books_sheet_shared.dart' show coverGridCount;import 'overlay_toast.dart';import 'stackable_sheet.dart';@@ -307,8 +308,8 @@ class _FinishedBooksThisYearSheetStatereturn GridView.builder(controller: widget.scrollController,padding: EdgeInsets.fromLTRB(16, 4, 16, bottomPad),- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(- crossAxisCount: 3,+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(+ crossAxisCount: coverGridCount(context),mainAxisSpacing: 12,crossAxisSpacing: 12,childAspectRatio: 0.55,diff --git a/lib/widgets/library_grid_tiles.dart b/lib/widgets/library_grid_tiles.dartindex 3bb1505e..b87f3540 100644--- a/lib/widgets/library_grid_tiles.dart+++ b/lib/widgets/library_grid_tiles.dart@@ -10,6 +10,7 @@ import '../services/audio_player_service.dart';import '../services/download_service.dart';import 'absorbing_shared.dart';import 'book_detail_sheet.dart';+import 'books_sheet_shared.dart' show coverGridTextScale, coverGridDecodeWidth;import 'episode_list_sheet.dart';import '../services/upcoming_releases_service.dart';import 'series_books_sheet.dart';@@ -265,7 +266,7 @@ class _GridBookTileState extends State<GridBookTile> {style: tt.labelSmall?.copyWith(fontWeight: FontWeight.w600,color: cs.onSurface,- fontSize: 11,+ fontSize: 11 * coverGridTextScale(context),),),// Author@@ -276,7 +277,7 @@ class _GridBookTileState extends State<GridBookTile> {overflow: TextOverflow.ellipsis,style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant,- fontSize: 10,+ fontSize: 10 * coverGridTextScale(context),),),],@@ -287,30 +288,42 @@ class _GridBookTileState extends State<GridBookTile> {Widget _blurCover(String coverUrl, Map<String, String> headers, ColorScheme cs, double aspectRatio, String title, String author) {final placeholder = CoverPlaceholder(title: title, author: author);final isSquare = (aspectRatio - 1.0).abs() < 0.01;+ final decodeWidth = coverGridDecodeWidth(context);if (!isSquare) {if (coverUrl.startsWith('/')) {return Image.file(File(coverUrl), fit: BoxFit.cover,+ cacheWidth: decodeWidth,errorBuilder: (_, __, ___) => placeholder);}return CachedNetworkImage(imageUrl: coverUrl, fit: BoxFit.cover,- httpHeaders: headers, placeholder: (_, __) => placeholder,+ httpHeaders: headers, memCacheWidth: decodeWidth,+ placeholder: (_, __) => placeholder,errorWidget: (_, __, ___) => placeholder);}+ // The letterbox fill behind non-square art. A real gaussian here means one+ // offscreen blur layer per tile, which piles up GPU memory on dense grids+ // and gets the app OOM-killed mid-scroll - a tiny decode stretched to size+ // looks the same under the scrim at tile sizes and costs nothing.if (coverUrl.startsWith('/')) {- return BlurPaddedCover(- blurChild: Image.file(File(coverUrl), fit: BoxFit.cover,- errorBuilder: (_, __ ,___) => const SizedBox.shrink()),- child: Image.file(File(coverUrl), fit: BoxFit.contain,+ return Stack(fit: StackFit.expand, children: [+ Image.file(File(coverUrl), fit: BoxFit.cover, cacheWidth: 32,+ errorBuilder: (_, __, ___) => const SizedBox.shrink()),+ Container(color: Colors.black.withValues(alpha: 0.15)),+ Image.file(File(coverUrl), fit: BoxFit.contain,+ cacheWidth: decodeWidth,errorBuilder: (_, __, ___) => placeholder),- );+ ]);}- return BlurPaddedCover(- blurChild: CachedNetworkImage(imageUrl: coverUrl, fit: BoxFit.cover,- httpHeaders: headers, errorWidget: (_, __, ___) => const SizedBox.shrink()),- child: CachedNetworkImage(imageUrl: coverUrl, fit: BoxFit.contain,- httpHeaders: headers, placeholder: (_, __) => placeholder,+ return Stack(fit: StackFit.expand, children: [+ CachedNetworkImage(imageUrl: coverUrl, fit: BoxFit.cover,+ httpHeaders: headers, memCacheWidth: 32,+ errorWidget: (_, __, ___) => const SizedBox.shrink()),+ Container(color: Colors.black.withValues(alpha: 0.15)),+ CachedNetworkImage(imageUrl: coverUrl, fit: BoxFit.contain,+ httpHeaders: headers, memCacheWidth: decodeWidth,+ placeholder: (_, __) => placeholder,errorWidget: (_, __, ___) => placeholder),- );+ ]);}}@@ -363,7 +376,7 @@ class _StackedCovers extends StatelessWidget {bottom: i * inset,child: ClipRRect(borderRadius: BorderRadius.circular(10),- child: _coverImage(coverUrls[i]),+ child: _coverImage(context, coverUrls[i]),),),// Front cover (bottom-left)@@ -390,7 +403,7 @@ class _StackedCovers extends StatelessWidget {child: Stack(fit: StackFit.expand,children: [- _coverImage(coverUrls.isNotEmpty ? coverUrls[0] : null),+ _coverImage(context, coverUrls.isNotEmpty ? coverUrls[0] : null),// Series progress barif (seriesProgress > 0 && booksFinished < numBooks)Positioned(@@ -445,15 +458,18 @@ class _StackedCovers extends StatelessWidget {);}- Widget _coverImage(String? url) {+ Widget _coverImage(BuildContext context, String? url) {if (url == null) return _placeholder();+ final decodeWidth = coverGridDecodeWidth(context);// Series stacked covers are always cropped to fit - no blur padding neededif (url.startsWith('/')) {return Image.file(File(url), fit: BoxFit.cover,+ cacheWidth: decodeWidth,errorBuilder: (_, __, ___) => _placeholder());}return CachedNetworkImage(imageUrl: url, fit: BoxFit.cover,- httpHeaders: mediaHeaders, placeholder: (_, __) => _placeholder(),+ httpHeaders: mediaHeaders, memCacheWidth: decodeWidth,+ placeholder: (_, __) => _placeholder(),errorWidget: (_, __, ___) => _placeholder());}@@ -553,7 +569,7 @@ class GridSeriesTile extends StatelessWidget {style: tt.labelSmall?.copyWith(fontWeight: FontWeight.w600,color: cs.onSurface,- fontSize: 11,+ fontSize: 11 * coverGridTextScale(context),),),if (author.isNotEmpty)@@ -563,7 +579,7 @@ class GridSeriesTile extends StatelessWidget {overflow: TextOverflow.ellipsis,style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant,- fontSize: 10,+ fontSize: 10 * coverGridTextScale(context),),),],@@ -666,7 +682,7 @@ class GridSeriesTileDirect extends StatelessWidget {style: tt.labelSmall?.copyWith(fontWeight: FontWeight.w600,color: cs.onSurface,- fontSize: 11,+ fontSize: 11 * coverGridTextScale(context),),),if (author.isNotEmpty)@@ -676,7 +692,7 @@ class GridSeriesTileDirect extends StatelessWidget {overflow: TextOverflow.ellipsis,style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant,- fontSize: 10,+ fontSize: 10 * coverGridTextScale(context),),),],@@ -751,7 +767,7 @@ class GridListTile extends StatelessWidget {isPlaylist? Icons.playlist_play_rounded: Icons.collections_bookmark_rounded,- size: 12,+ size: 12 * coverGridTextScale(context),color: cs.onSurfaceVariant),const SizedBox(width: 3),Expanded(@@ -762,7 +778,7 @@ class GridListTile extends StatelessWidget {style: tt.labelSmall?.copyWith(fontWeight: FontWeight.w600,color: cs.onSurface,- fontSize: 11,+ fontSize: 11 * coverGridTextScale(context),),),),@@ -774,7 +790,9 @@ class GridListTile extends StatelessWidget {: l.collectionDetailBookCount(count),maxLines: 1,overflow: TextOverflow.ellipsis,- style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant, fontSize: 10),+ style: tt.labelSmall?.copyWith(+ color: cs.onSurfaceVariant,+ fontSize: 10 * coverGridTextScale(context)),),],),@@ -861,6 +879,7 @@ class GridAuthorTile extends StatelessWidget {imageUrl: imageUrl,fit: BoxFit.cover,httpHeaders: headers,+ memCacheWidth: coverGridDecodeWidth(context),placeholder: (_, __) => _placeholder(cs),errorWidget: (_, __, ___) => _placeholder(cs),),@@ -941,7 +960,7 @@ class GridAuthorTile extends StatelessWidget {style: tt.labelSmall?.copyWith(fontWeight: FontWeight.w600,color: cs.onSurface,- fontSize: 11,+ fontSize: 11 * coverGridTextScale(context),),),],diff --git a/lib/widgets/playlist_detail_sheet.dart b/lib/widgets/playlist_detail_sheet.dartindex d5cf6e6e..8041e83d 100644--- a/lib/widgets/playlist_detail_sheet.dart+++ b/lib/widgets/playlist_detail_sheet.dart@@ -15,6 +15,7 @@ import '../services/download_service.dart';import '../screens/app_shell.dart';import 'add_books_search_sheet.dart';import 'book_detail_sheet.dart';+import 'books_sheet_shared.dart' show coverGridCount;import 'editable_sheet_item.dart';import 'episode_list_sheet.dart';import 'stackable_sheet.dart';@@ -705,8 +706,8 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {controller: widget.scrollController,padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4).copyWith(bottom: 40),- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(- crossAxisCount: 3,+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(+ crossAxisCount: coverGridCount(context),mainAxisSpacing: 12,crossAxisSpacing: 12,childAspectRatio: 0.62,diff --git a/lib/widgets/section_detail_sheet.dart b/lib/widgets/section_detail_sheet.dartindex 036062b6..62da9ff9 100644--- a/lib/widgets/section_detail_sheet.dart+++ b/lib/widgets/section_detail_sheet.dart@@ -10,6 +10,7 @@ import '../providers/library_provider.dart';import '../services/audio_player_service.dart';import '../services/download_service.dart';import 'book_detail_sheet.dart';+import 'books_sheet_shared.dart' show coverGridCount;import 'episode_detail_sheet.dart';import 'overlay_toast.dart';import 'swipe_action.dart';@@ -252,7 +253,7 @@ class _SectionDetailSheetState extends State<SectionDetailSheet> {padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4).copyWith(bottom: 40),gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(- crossAxisCount: 3,+ crossAxisCount: coverGridCount(context),mainAxisSpacing: 12,crossAxisSpacing: 12,childAspectRatio: childAspectRatio,