A cross platform Audiobookshelf client for Android and iOS
Dart
Add narrators to library search
Nathan Poulsonda8b1bccf030
diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arbindex e49bad16..e10b26b0 100644--- a/lib/l10n/app_de.arb+++ b/lib/l10n/app_de.arb@@ -86,7 +86,7 @@"loginSavedAccounts": "gespeicherte Konten","libraryTitle": "Bibliothek",- "librarySearchBooksHint": "Bücher, Serien und Autoren suchen...",+ "librarySearchBooksHint": "Bücher, Serien, Autoren, Sprecher suchen...","librarySearchShowsHint": "Sendungen und Episoden suchen...","libraryTabLibrary": "Bibliothek","libraryTabSeries": "Serien",diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 9e7c0a5d..0b27549b 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -86,7 +86,7 @@"loginSavedAccounts": "saved accounts","libraryTitle": "Library",- "librarySearchBooksHint": "Search books, series, and authors...",+ "librarySearchBooksHint": "Search books, series, authors, narrators...","librarySearchShowsHint": "Search shows and episodes...","libraryTabLibrary": "Library","libraryTabSeries": "Series",diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex a9daabc0..68ed169d 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -259,7 +259,7 @@ class AppLocalizationsDe extends AppLocalizations {String get libraryTitle => 'Bibliothek';@override- String get librarySearchBooksHint => 'Bücher, Serien und Autoren suchen...';+ String get librarySearchBooksHint => 'Bücher, Serien, Autoren, Sprecher suchen...';@overrideString get librarySearchShowsHint => 'Sendungen und Episoden suchen...';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 9558d88c..94deb490 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -256,7 +256,7 @@ class AppLocalizationsEn extends AppLocalizations {String get libraryTitle => 'Library';@override- String get librarySearchBooksHint => 'Search books, series, and authors...';+ String get librarySearchBooksHint => 'Search books, series, authors, narrators...';@overrideString get librarySearchShowsHint => 'Search shows and episodes...';diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex cf353aa1..9ddb23e4 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -251,7 +251,7 @@ class AppLocalizationsZh extends AppLocalizations {String get libraryTitle => '媒体库';@override- String get librarySearchBooksHint => '搜索书籍、系列和作者...';+ String get librarySearchBooksHint => '搜索书籍、系列、作者、旁白...';@overrideString get librarySearchShowsHint => '搜索播客和单集...';diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arbindex 99bc0c37..e5ea38d2 100644--- a/lib/l10n/app_zh.arb+++ b/lib/l10n/app_zh.arb@@ -86,7 +86,7 @@"loginSavedAccounts": "已保存账户","libraryTitle": "媒体库",- "librarySearchBooksHint": "搜索书籍、系列和作者...",+ "librarySearchBooksHint": "搜索书籍、系列、作者、旁白...","librarySearchShowsHint": "搜索播客和单集...","libraryTabLibrary": "媒体库","libraryTabSeries": "系列",diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dartindex f2d9e8a4..3b624498 100644--- a/lib/screens/library_screen.dart+++ b/lib/screens/library_screen.dart@@ -89,7 +89,10 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMiList<dynamic> _searchBookResults = [];List<dynamic> _searchSeriesResults = [];List<dynamic> _searchAuthorResults = [];+ List<String> _searchNarratorResults = [];List<Map<String, dynamic>> _searchEpisodeResults = [];+ List<String>? _allNarratorsCache;+ String? _allNarratorsCacheLibraryId;bool _isSearching = false;bool _hasSearched = false;bool get _isInSearchMode => _searchController.text.trim().isNotEmpty;@@ -291,6 +294,9 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi_narrators.clear();_narratorsLoaded = false;_isLoadingNarrators = false;+ _allNarratorsCache = null;+ _allNarratorsCacheLibraryId = null;+ _searchNarratorResults = [];});if (_scrollController.hasClients) _scrollController.jumpTo(0);if (_seriesScrollController.hasClients) _seriesScrollController.jumpTo(0);@@ -1032,6 +1038,7 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi_searchBookResults = [];_searchSeriesResults = [];_searchAuthorResults = [];+ _searchNarratorResults = [];_searchEpisodeResults = [];_hasSearched = false;_isSearching = false;@@ -1072,6 +1079,11 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi_hasSearched = true;});+ // Client-side narrator filter (ABS search endpoint doesn't return narrators)+ if (!isPodcast) {+ _searchNarrators(query, lib.selectedLibraryId!, api);+ }+// For podcast libraries, also search episode titles client-sideif (isPodcast) {_searchEpisodes(query, lib.selectedLibraryId!, api);@@ -1084,6 +1096,21 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi}}+ Future<void> _searchNarrators(String query, String libraryId, dynamic api) async {+ final lowerQuery = query.toLowerCase();+ if (_allNarratorsCache == null || _allNarratorsCacheLibraryId != libraryId) {+ final all = await api.getLibraryNarrators(libraryId);+ _allNarratorsCache = (all as List).cast<String>();+ _allNarratorsCacheLibraryId = libraryId;+ }+ final matches = _allNarratorsCache!+ .where((n) => n.toLowerCase().contains(lowerQuery))+ .toList();+ if (mounted && _searchController.text.trim().toLowerCase() == lowerQuery) {+ setState(() => _searchNarratorResults = matches);+ }+ }+List<Map<String, dynamic>>? _cachedShowsWithEpisodes;String? _cachedShowsLibraryId;@@ -1804,7 +1831,7 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMiif (!_hasSearched) {return const SizedBox.shrink();}- if (_searchBookResults.isEmpty && _searchSeriesResults.isEmpty && _searchAuthorResults.isEmpty && _searchEpisodeResults.isEmpty) {+ if (_searchBookResults.isEmpty && _searchSeriesResults.isEmpty && _searchAuthorResults.isEmpty && _searchNarratorResults.isEmpty && _searchEpisodeResults.isEmpty) {return Center(child: Column(mainAxisSize: MainAxisSize.min,@@ -1916,6 +1943,18 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi);}),],++ // ─── NARRATORS ───+ if (_searchNarratorResults.isNotEmpty) ...[+ Padding(+ padding: EdgeInsets.fromLTRB(+ 4, (_searchBookResults.isNotEmpty || _searchSeriesResults.isNotEmpty || _searchAuthorResults.isNotEmpty) ? 20 : 8, 4, 8),+ child: Text(l.libraryTabNarrators,+ style: tt.titleMedium?.copyWith(+ fontWeight: FontWeight.w600, color: cs.primary)),+ ),+ ..._searchNarratorResults.map((name) => NarratorResultTile(name: name)),+ ],],);}diff --git a/lib/widgets/library_search_results.dart b/lib/widgets/library_search_results.dartindex 3ebf0f4b..571f8250 100644--- a/lib/widgets/library_search_results.dart+++ b/lib/widgets/library_search_results.dart@@ -8,6 +8,7 @@ import '../services/download_service.dart';import 'author_books_sheet.dart';import 'book_detail_sheet.dart';import 'episode_list_sheet.dart';+import 'narrator_books_sheet.dart';import 'series_books_sheet.dart';class BookResultTile extends StatelessWidget {@@ -501,3 +502,60 @@ class AuthorResultTile extends StatelessWidget {showAuthorDetailSheet(context, authorId: authorId, authorName: authorName);}}++class NarratorResultTile extends StatelessWidget {+ final String name;++ const NarratorResultTile({super.key, required this.name});++ @override+ Widget build(BuildContext context) {+ final cs = Theme.of(context).colorScheme;+ final tt = Theme.of(context).textTheme;++ return Padding(+ padding: const EdgeInsets.only(bottom: 6),+ child: Card(+ elevation: 0,+ color: cs.surfaceContainerHigh,+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),+ clipBehavior: Clip.antiAlias,+ child: InkWell(+ onTap: () => showNarratorBooksSheet(context, narratorName: name),+ borderRadius: BorderRadius.circular(12),+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),+ child: Row(+ children: [+ Container(+ width: 44,+ height: 44,+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ color: cs.tertiaryContainer,+ ),+ child: Center(+ child: Icon(Icons.mic_rounded,+ size: 22,+ color: cs.onTertiaryContainer.withValues(alpha: 0.7)),+ ),+ ),+ const SizedBox(width: 12),+ Expanded(+ child: Text(name,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: tt.bodyMedium?.copyWith(+ fontWeight: FontWeight.w600,+ color: cs.onSurface)),+ ),+ Icon(Icons.chevron_right_rounded,+ color: cs.onSurfaceVariant, size: 20),+ ],+ ),+ ),+ ),+ ),+ );+ }+}