Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Give Android Auto and CarPlay their own settings section and add Collections and Playlists to the car library

Barnabas31cb0901e527
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index 4b5fb963..f090001b 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -4180,6 +4180,8 @@
"carConnectAutoplayIos": "Start playback when CarPlay connects",
"carConnectAutoplayOnSubtitle": "The last book you were listening to starts by itself when the car connects",
"carConnectAutoplayOffSubtitle": "Playback waits for you to press play",
+ "sectionCar": "Android Auto",
+ "sectionCarIos": "CarPlay",
"carBookOrder": "Book order in the car",
"carBookOrderReverse": "Reverse book order",
"carBookOrderReverseSubtitle": "Z to A, or oldest added first",
@@ -4189,6 +4191,8 @@
"androidAutoCatBooks": "Books",
"androidAutoCatSeries": "Series",
"androidAutoCatAuthors": "Authors",
+ "androidAutoCatCollections": "Collections",
+ "androidAutoCatPlaylists": "Playlists",
"showTipsAgain": "Show tips again",
"showTipsAgainSubtitle": "Bring back feature tips you've dismissed",
"tipsRestored": "Tips restored",
diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart
index 5f60a1bf..dfb07bc3 100644
--- a/lib/l10n/app_localizations.dart
+++ b/lib/l10n/app_localizations.dart
@@ -11979,6 +11979,18 @@ abstract class AppLocalizations {
/// **'Playback waits for you to press play'**
String get carConnectAutoplayOffSubtitle;
+ /// No description provided for @sectionCar.
+ ///
+ /// In en, this message translates to:
+ /// **'Android Auto'**
+ String get sectionCar;
+
+ /// No description provided for @sectionCarIos.
+ ///
+ /// In en, this message translates to:
+ /// **'CarPlay'**
+ String get sectionCarIos;
+
/// No description provided for @carBookOrder.
///
/// In en, this message translates to:
@@ -12033,6 +12045,18 @@ abstract class AppLocalizations {
/// **'Authors'**
String get androidAutoCatAuthors;
+ /// No description provided for @androidAutoCatCollections.
+ ///
+ /// In en, this message translates to:
+ /// **'Collections'**
+ String get androidAutoCatCollections;
+
+ /// No description provided for @androidAutoCatPlaylists.
+ ///
+ /// In en, this message translates to:
+ /// **'Playlists'**
+ String get androidAutoCatPlaylists;
+
/// No description provided for @showTipsAgain.
///
/// In en, this message translates to:
diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart
index 214cd179..f35b6fa5 100644
--- a/lib/l10n/app_localizations_de.dart
+++ b/lib/l10n/app_localizations_de.dart
@@ -7103,6 +7103,12 @@ class AppLocalizationsDe extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7131,6 +7137,12 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Autoren';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Tipps wieder anzeigen';
diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dart
index 87ac40d2..a251fcad 100644
--- a/lib/l10n/app_localizations_el.dart
+++ b/lib/l10n/app_localizations_el.dart
@@ -7004,6 +7004,12 @@ class AppLocalizationsEl extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7032,6 +7038,12 @@ class AppLocalizationsEl extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart
index e5bf2d78..e934ffed 100644
--- a/lib/l10n/app_localizations_en.dart
+++ b/lib/l10n/app_localizations_en.dart
@@ -7004,6 +7004,12 @@ class AppLocalizationsEn extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7032,6 +7038,12 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart
index a91a9c69..41daaea3 100644
--- a/lib/l10n/app_localizations_es.dart
+++ b/lib/l10n/app_localizations_es.dart
@@ -7006,6 +7006,12 @@ class AppLocalizationsEs extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7034,6 +7040,12 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart
index 5c3730f6..e9bf47dd 100644
--- a/lib/l10n/app_localizations_fr.dart
+++ b/lib/l10n/app_localizations_fr.dart
@@ -7055,6 +7055,12 @@ class AppLocalizationsFr extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7083,6 +7089,12 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Auteurs';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Afficher les conseils à nouveau';
diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart
index f2737bdf..76f82b13 100644
--- a/lib/l10n/app_localizations_it.dart
+++ b/lib/l10n/app_localizations_it.dart
@@ -7004,6 +7004,12 @@ class AppLocalizationsIt extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7032,6 +7038,12 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart
index 0e6bedba..abdcbc36 100644
--- a/lib/l10n/app_localizations_ja.dart
+++ b/lib/l10n/app_localizations_ja.dart
@@ -7004,6 +7004,12 @@ class AppLocalizationsJa extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7032,6 +7038,12 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dart
index e7b45bda..43481727 100644
--- a/lib/l10n/app_localizations_no.dart
+++ b/lib/l10n/app_localizations_no.dart
@@ -7004,6 +7004,12 @@ class AppLocalizationsNo extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7032,6 +7038,12 @@ class AppLocalizationsNo extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart
index 6718801c..890ad654 100644
--- a/lib/l10n/app_localizations_pt.dart
+++ b/lib/l10n/app_localizations_pt.dart
@@ -7004,6 +7004,12 @@ class AppLocalizationsPt extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7032,6 +7038,12 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dart
index d55eb717..de2de514 100644
--- a/lib/l10n/app_localizations_ro.dart
+++ b/lib/l10n/app_localizations_ro.dart
@@ -7004,6 +7004,12 @@ class AppLocalizationsRo extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7032,6 +7038,12 @@ class AppLocalizationsRo extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart
index caa565d3..475c83e7 100644
--- a/lib/l10n/app_localizations_ru.dart
+++ b/lib/l10n/app_localizations_ru.dart
@@ -7008,6 +7008,12 @@ class AppLocalizationsRu extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -7036,6 +7042,12 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => 'Show tips again';
diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart
index 2e6b7ad3..04e4b571 100644
--- a/lib/l10n/app_localizations_zh.dart
+++ b/lib/l10n/app_localizations_zh.dart
@@ -6914,6 +6914,12 @@ class AppLocalizationsZh extends AppLocalizations {
String get carConnectAutoplayOffSubtitle =>
'Playback waits for you to press play';
+ @override
+ String get sectionCar => 'Android Auto';
+
+ @override
+ String get sectionCarIos => 'CarPlay';
+
@override
String get carBookOrder => 'Book order in the car';
@@ -6942,6 +6948,12 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get androidAutoCatAuthors => 'Authors';
+ @override
+ String get androidAutoCatCollections => 'Collections';
+
+ @override
+ String get androidAutoCatPlaylists => 'Playlists';
+
@override
String get showTipsAgain => '再次显示提示';
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 39f895e5..e2926df9 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -3035,7 +3035,51 @@ class _SettingsScreenState extends State<SettingsScreen> {
PlayerSettings.setLockSeekBar(v);
} : null,
),
- const Divider(height: 1, indent: 16, endIndent: 16),
+ // Android only: chooses which pair fills the phone media
+ // player's two extra slots. iOS uses CarPlay's own buttons.
+ if (Platform.isAndroid) ...[
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ SwitchListTile(
+ title: const Text('Duck brief interruptions'),
+ subtitle: Text(
+ _duckBriefInterruptions
+ ? 'Notifications and prompts lower the volume instead of pausing'
+ : 'Notifications and prompts pause playback',
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _duckBriefInterruptions,
+ onChanged: _loaded ? (v) {
+ setState(() => _duckBriefInterruptions = v);
+ PlayerSettings.setDuckBriefInterruptions(v);
+ } : null,
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ SwitchListTile(
+ title: Text(l.speedBookmarkInControls),
+ subtitle: Text(
+ _notifSpeedBookmark
+ ? l.speedBookmarkOnSubtitle
+ : l.speedBookmarkOffSubtitle,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _notifSpeedBookmark,
+ onChanged: _loaded ? (v) {
+ setState(() => _notifSpeedBookmark = v);
+ PlayerSettings.setMediaControlsSpeedBookmark(v);
+ } : null,
+ ),
+ ],
+ ],
+ ),
+ const SizedBox(height: 16),
+
+ // ── Car ──
+ CollapsibleSection(
+ key: _keyFor('Car'),
+ icon: Icons.directions_car_rounded,
+ title: Platform.isIOS ? l.sectionCarIos : l.sectionCar,
+ cs: cs,
+ isExpanded: _expandedSection == 'Car',
+ onExpansionChanged: (v) => _onSectionExpanded('Car', v),
+ children: [
SwitchListTile(
title: Text(Platform.isIOS
? l.carConnectAutoplayIos
@@ -3097,38 +3141,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
.then((_) => AndroidAutoService.browseOrderChanged());
} : null,
),
- // Android only: chooses which pair fills the phone media
- // player's two extra slots. iOS uses CarPlay's own buttons.
- if (Platform.isAndroid) ...[
- const Divider(height: 1, indent: 16, endIndent: 16),
- SwitchListTile(
- title: const Text('Duck brief interruptions'),
- subtitle: Text(
- _duckBriefInterruptions
- ? 'Notifications and prompts lower the volume instead of pausing'
- : 'Notifications and prompts pause playback',
- style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
- value: _duckBriefInterruptions,
- onChanged: _loaded ? (v) {
- setState(() => _duckBriefInterruptions = v);
- PlayerSettings.setDuckBriefInterruptions(v);
- } : null,
- ),
- const Divider(height: 1, indent: 16, endIndent: 16),
- SwitchListTile(
- title: Text(l.speedBookmarkInControls),
- subtitle: Text(
- _notifSpeedBookmark
- ? l.speedBookmarkOnSubtitle
- : l.speedBookmarkOffSubtitle,
- style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
- value: _notifSpeedBookmark,
- onChanged: _loaded ? (v) {
- setState(() => _notifSpeedBookmark = v);
- PlayerSettings.setMediaControlsSpeedBookmark(v);
- } : null,
- ),
- ],
],
),
const SizedBox(height: 16),
diff --git a/lib/screens/settings_search_index.dart b/lib/screens/settings_search_index.dart
index 6ae9e513..3e6809a2 100644
--- a/lib/screens/settings_search_index.dart
+++ b/lib/screens/settings_search_index.dart
@@ -69,16 +69,20 @@ List<SettingSearchEntry> settingsSearchEntries(BuildContext context) {
// ── Media Controls ──
SettingSearchEntry('Media Controls', l.sectionMediaControls, l.chapterProgressInNotification, [l.chapterProgressInNotificationIos, l.chapterProgressOnSubtitle, l.chapterProgressOnSubtitleIos, l.chapterProgressOffSubtitle]),
SettingSearchEntry('Media Controls', l.sectionMediaControls, l.lockSeekBar, [l.lockSeekBarOnSubtitle, l.lockSeekBarOffSubtitle]),
- SettingSearchEntry(
- 'Media Controls',
- l.sectionMediaControls,
- Platform.isIOS ? l.carConnectAutoplayIos : l.carConnectAutoplay,
- [l.carConnectAutoplayOnSubtitle, l.carConnectAutoplayOffSubtitle]),
if (Platform.isAndroid) ...[
SettingSearchEntry('Media Controls', l.sectionMediaControls, 'Duck brief interruptions', const ['Notifications and prompts lower the volume instead of pausing', 'Notifications and prompts pause playback']),
SettingSearchEntry('Media Controls', l.sectionMediaControls, l.speedBookmarkInControls, [l.speedBookmarkOnSubtitle, l.speedBookmarkOffSubtitle]),
],
+ // ── Car ──
+ SettingSearchEntry('Car', Platform.isIOS ? l.sectionCarIos : l.sectionCar,
+ Platform.isIOS ? l.carConnectAutoplayIos : l.carConnectAutoplay,
+ [l.carConnectAutoplayOnSubtitle, l.carConnectAutoplayOffSubtitle]),
+ SettingSearchEntry('Car', Platform.isIOS ? l.sectionCarIos : l.sectionCar, l.carBookOrder, [l.title, l.author, l.dateAdded]),
+ SettingSearchEntry('Car', Platform.isIOS ? l.sectionCarIos : l.sectionCar, l.carBookOrderReverse, [l.carBookOrderReverseSubtitle]),
+ SettingSearchEntry('Car', Platform.isIOS ? l.sectionCarIos : l.sectionCar, l.carPodcastOrder, [l.title, l.dateAdded]),
+ SettingSearchEntry('Car', Platform.isIOS ? l.sectionCarIos : l.sectionCar, l.carEpisodesOldestFirst, [l.carEpisodesOldestFirstSubtitle]),
+
// ── Sleep Timer ──
SettingSearchEntry('Sleep Timer', l.sectionSleepTimer, l.shakeDuringSleepTimer, [l.shakeOff, l.shakeAddTime, l.shakeReset]),
SettingSearchEntry('Sleep Timer', l.sectionSleepTimer, l.shakeSensitivity, [l.shakeSensitivityVeryLow, l.shakeSensitivityLow, l.shakeSensitivityMedium, l.shakeSensitivityHigh, l.shakeSensitivityVeryHigh]),
diff --git a/lib/services/android_auto_service.dart b/lib/services/android_auto_service.dart
index 4c1782a0..50499865 100644
--- a/lib/services/android_auto_service.dart
+++ b/lib/services/android_auto_service.dart
@@ -52,6 +52,8 @@ class AutoMediaIds {
static const seriesPrefix = 'series:';
static const authorPrefix = 'author:';
static const showPrefix = 'show:';
+ static const collectionPrefix = 'collection:';
+ static const playlistPrefix = 'playlist:';
// Build IDs
static String itemId(String absId) => '$itemPrefix$absId';
@@ -60,6 +62,10 @@ class AutoMediaIds {
static String libSeries(String libraryId) => '$libPrefix$libraryId:series';
static String libAuthors(String libraryId) => '$libPrefix$libraryId:authors';
static String libBookPrefix(String libraryId, String prefix) => '$libPrefix$libraryId:p:$prefix';
+ static String libCollections(String libraryId) => '$libPrefix$libraryId:collections';
+ static String libPlaylists(String libraryId) => '$libPrefix$libraryId:playlists';
+ static String collectionId(String cId, String libId) => '$collectionPrefix$cId@$libId';
+ static String playlistId(String pId, String libId) => '$playlistPrefix$pId@$libId';
static String seriesId(String sId, String libId) => '$seriesPrefix$sId@$libId';
static String authorId(String aId, String libId) => '$authorPrefix$aId@$libId';
static String showId(String sId, String libId) => '$showPrefix$sId@$libId';
@@ -95,6 +101,15 @@ class AutoMediaIds {
return (showId: rest.substring(0, at), libId: rest.substring(at + 1));
}
+ /// Parse "collection:<id>@<libId>" or "playlist:<id>@<libId>".
+ static ({String id, String libId})? parseGroup(String mediaId, String prefix) {
+ if (!mediaId.startsWith(prefix)) return null;
+ final rest = mediaId.substring(prefix.length);
+ final at = rest.indexOf('@');
+ if (at < 0) return null;
+ return (id: rest.substring(0, at), libId: rest.substring(at + 1));
+ }
+
/// Parse "lib:<libraryId>" or "lib:<libraryId>:books" etc.
static String? parseLibId(String mediaId) {
if (!mediaId.startsWith(libPrefix)) return null;
@@ -282,6 +297,7 @@ class AndroidAutoService {
_isRefreshing = false;
_childrenCache.clear();
_childrenInFlight.clear();
+ _groupEntries.clear();
debugPrint('[AutoBrowse] Cache cleared (user switch/logout)');
}
@@ -961,6 +977,16 @@ class AndroidAutoService {
title: l?.androidAutoCatAuthors ?? 'Authors',
playable: false,
),
+ MediaItem(
+ id: AutoMediaIds.libCollections(libraryId),
+ title: l?.androidAutoCatCollections ?? 'Collections',
+ playable: false,
+ ),
+ MediaItem(
+ id: AutoMediaIds.libPlaylists(libraryId),
+ title: l?.androidAutoCatPlaylists ?? 'Playlists',
+ playable: false,
+ ),
];
}
@@ -1087,9 +1113,40 @@ class AndroidAutoService {
return _fetchLibrarySeries(libId);
case 'authors':
return _fetchLibraryAuthors(libId);
+ case 'collections':
+ final collections = await fetchCollectionsData(libId);
+ return collections
+ .map((c) => MediaItem(
+ id: AutoMediaIds.collectionId(c.id, libId),
+ title: c.name,
+ playable: false,
+ ))
+ .toList();
+ case 'playlists':
+ final playlists = await fetchPlaylistsData(libId);
+ return playlists
+ .map((p) => MediaItem(
+ id: AutoMediaIds.playlistId(p.id, libId),
+ title: p.name,
+ playable: false,
+ ))
+ .toList();
}
}
+ final collection =
+ AutoMediaIds.parseGroup(parentMediaId, AutoMediaIds.collectionPrefix);
+ if (collection != null) {
+ final books = await fetchCollectionBooksData(collection.id);
+ return books.map((e) => e.toMediaItem()).toList();
+ }
+ final playlist =
+ AutoMediaIds.parseGroup(parentMediaId, AutoMediaIds.playlistPrefix);
+ if (playlist != null) {
+ final items = await fetchPlaylistItemsData(playlist.id);
+ return items.map((e) => e.toMediaItem()).toList();
+ }
+
// ── Show drilldown (podcast episodes) ──
final show = AutoMediaIds.parseShow(parentMediaId);
if (show != null) {
@@ -1646,6 +1703,110 @@ class AndroidAutoService {
return [];
}
+ // Collections and playlists come back with their books already expanded,
+ // so the list fetch holds everything a drilldown needs. Keyed 'c:<id>' and
+ // 'p:<id>'.
+ final Map<String, List<AutoBookEntry>> _groupEntries = {};
+
+ /// Collections in a library, in server order, with how many playable books
+ /// each holds.
+ Future<List<({String id, String name, int count})>> fetchCollectionsData(
+ String libraryId) async {
+ final api = await getApi();
+ if (api == null) return [];
+ final list = await api.getLibraryCollections(libraryId) ?? const [];
+ final out = <({String id, String name, int count})>[];
+ for (final c in list.whereType<Map<String, dynamic>>()) {
+ final id = c['id'] as String?;
+ if (id == null) continue;
+ final books = _collectionEntries(c, api);
+ _groupEntries['c:$id'] = books;
+ out.add((id: id, name: c['name'] as String? ?? 'Collection', count: books.length));
+ }
+ return out;
+ }
+
+ Future<List<AutoBookEntry>> fetchCollectionBooksData(String collectionId) async {
+ final cached = _groupEntries['c:$collectionId'];
+ if (cached != null) return cached;
+ final api = await getApi();
+ if (api == null) return [];
+ final collection = await api.getCollection(collectionId);
+ if (collection == null) return [];
+ return _groupEntries['c:$collectionId'] = _collectionEntries(collection, api);
+ }
+
+ List<AutoBookEntry> _collectionEntries(Map<String, dynamic> c, ApiService api) =>
+ ((c['books'] as List<dynamic>?) ?? const [])
+ .whereType<Map<String, dynamic>>()
+ .map((b) => _libraryItemToEntry(b, api))
+ .whereType<AutoBookEntry>()
+ .toList();
+
+ /// The user's playlists in a library, in server order.
+ Future<List<({String id, String name, int count})>> fetchPlaylistsData(
+ String libraryId) async {
+ final api = await getApi();
+ if (api == null) return [];
+ final list = await api.getLibraryPlaylists(libraryId) ?? const [];
+ final out = <({String id, String name, int count})>[];
+ for (final p in list.whereType<Map<String, dynamic>>()) {
+ final id = p['id'] as String?;
+ if (id == null) continue;
+ final items = _playlistEntries(p, api);
+ _groupEntries['p:$id'] = items;
+ out.add((id: id, name: p['name'] as String? ?? 'Playlist', count: items.length));
+ }
+ return out;
+ }
+
+ Future<List<AutoBookEntry>> fetchPlaylistItemsData(String playlistId) async {
+ final cached = _groupEntries['p:$playlistId'];
+ if (cached != null) return cached;
+ final api = await getApi();
+ if (api == null) return [];
+ final playlist = await api.getPlaylist(playlistId);
+ if (playlist == null) return [];
+ return _groupEntries['p:$playlistId'] = _playlistEntries(playlist, api);
+ }
+
+ /// Playlist entries can be whole books or single podcast episodes.
+ List<AutoBookEntry> _playlistEntries(Map<String, dynamic> p, ApiService api) {
+ final out = <AutoBookEntry>[];
+ for (final item in ((p['items'] as List<dynamic>?) ?? const [])
+ .whereType<Map<String, dynamic>>()) {
+ final libraryItem = item['libraryItem'] as Map<String, dynamic>?;
+ if (libraryItem == null) continue;
+ final episode = item['episode'] as Map<String, dynamic>?;
+ if (episode == null) {
+ final entry = _libraryItemToEntry(libraryItem, api);
+ if (entry != null) out.add(entry);
+ continue;
+ }
+ final showId = libraryItem['id'] as String?;
+ final episodeId = episode['id'] as String? ?? item['episodeId'] as String?;
+ if (showId == null || episodeId == null) continue;
+ final media = libraryItem['media'] as Map<String, dynamic>?;
+ final metadata = media?['metadata'] as Map<String, dynamic>? ?? {};
+ final audioFile = episode['audioFile'] as Map<String, dynamic>?;
+ out.add(AutoBookEntry(
+ id: '$showId-$episodeId',
+ title: episode['title'] as String? ?? 'Episode',
+ author: metadata['title'] as String? ?? '',
+ duration: ((episode['duration'] ?? audioFile?['duration']) as num?)
+ ?.toDouble() ??
+ 0,
+ coverUrl: localCoverUri(showId),
+ chapters: episode['chapters'] as List<dynamic>? ?? const [],
+ episodeId: episodeId,
+ showId: showId,
+ mediaType: 'podcast',
+ libraryId: libraryItem['libraryId'] as String?,
+ ));
+ }
+ return out;
+ }
+
/// Fetch books in a series, returning raw entries.
Future<List<AutoBookEntry>> fetchSeriesBooksData(String seriesId, String libraryId) async {
final api = await getApi();
diff --git a/lib/services/carplay_service.dart b/lib/services/carplay_service.dart
index 1774fb47..1d863874 100644
--- a/lib/services/carplay_service.dart
+++ b/lib/services/carplay_service.dart
@@ -414,6 +414,34 @@ class CarPlayService {
complete();
},
),
+ CPListItem(
+ text: 'Collections',
+ accessoryType: CPListItemAccessoryTypes.disclosureIndicator,
+ onPress: (complete, self) async {
+ final template = await _buildGroupList(
+ title: 'Collections',
+ icon: 'square.stack.fill',
+ groups: await _autoService.fetchCollectionsData(libraryId),
+ entries: _autoService.fetchCollectionBooksData,
+ );
+ _pushTemplate(template);
+ complete();
+ },
+ ),
+ CPListItem(
+ text: 'Playlists',
+ accessoryType: CPListItemAccessoryTypes.disclosureIndicator,
+ onPress: (complete, self) async {
+ final template = await _buildGroupList(
+ title: 'Playlists',
+ icon: 'music.note.list',
+ groups: await _autoService.fetchPlaylistsData(libraryId),
+ entries: _autoService.fetchPlaylistItemsData,
+ );
+ _pushTemplate(template);
+ complete();
+ },
+ ),
];
return CPListTemplate(
@@ -479,6 +507,40 @@ class CarPlayService {
);
}
+ /// Collections or playlists: a list of groups, each opening its books.
+ Future<CPListTemplate> _buildGroupList({
+ required String title,
+ required String icon,
+ required List<({String id, String name, int count})> groups,
+ required Future<List<AutoBookEntry>> Function(String id) entries,
+ }) async {
+ final items = groups.map((g) {
+ return CPListItem(
+ text: g.name,
+ detailText: '${g.count}',
+ accessoryType: CPListItemAccessoryTypes.disclosureIndicator,
+ onPress: (complete, self) async {
+ final api = await _autoService.getApi();
+ final books = await entries(g.id);
+ _pushTemplate(CPListTemplate(
+ sections: [
+ CPListSection(
+ items: books.map((e) => _playableListItem(e, api)).toList()),
+ ],
+ title: g.name,
+ systemIcon: icon,
+ ));
+ complete();
+ },
+ );
+ }).toList();
+ return CPListTemplate(
+ sections: [CPListSection(items: items)],
+ title: title,
+ systemIcon: icon,
+ );
+ }
+
// ─── Series list ───────────────────────────────────────────────────
Future<CPListTemplate> _buildSeriesList(String libraryId) async {