A cross platform Audiobookshelf client for Android and iOS
Dart
Add tag and genre results to library search
Barnabasd4487ac47c97
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 3ca99cec..232a88e1 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -112,6 +112,8 @@"librarySearchEpisodes": "Episodes","librarySearchSeries": "Series","librarySearchAuthors": "Authors",+ "librarySearchTags": "Tags",+ "librarySearchGenres": "Genres","librarySeriesCount": "{count} series","@librarySeriesCount": { "placeholders": { "count": { "type": "int" } } },"libraryAuthorsCount": "{count} authors",diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex 899e43c5..9aeb4578 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -712,6 +712,18 @@ abstract class AppLocalizations {/// **'Authors'**String get librarySearchAuthors;+ /// No description provided for @librarySearchTags.+ ///+ /// In en, this message translates to:+ /// **'Tags'**+ String get librarySearchTags;++ /// No description provided for @librarySearchGenres.+ ///+ /// In en, this message translates to:+ /// **'Genres'**+ String get librarySearchGenres;+/// No description provided for @librarySeriesCount.////// In en, this message translates to:diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex 8c0e2536..cf7e727d 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -335,6 +335,12 @@ class AppLocalizationsDe extends AppLocalizations {@overrideString get librarySearchAuthors => 'Autoren';+ @override+ String get librarySearchTags => 'Tags';++ @override+ String get librarySearchGenres => 'Genres';+@overrideString librarySeriesCount(int count) {return '$count Serien';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 01d05e7b..1911e215 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -332,6 +332,12 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get librarySearchAuthors => 'Authors';+ @override+ String get librarySearchTags => 'Tags';++ @override+ String get librarySearchGenres => 'Genres';+@overrideString librarySeriesCount(int count) {return '$count series';diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex 90fba31e..b3dd44f8 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -326,6 +326,12 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get librarySearchAuthors => '作者';+ @override+ String get librarySearchTags => 'Tags';++ @override+ String get librarySearchGenres => 'Genres';+@overrideString librarySeriesCount(int count) {return '$count 个系列';diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dartindex 9bd9f589..b0f48810 100644--- a/lib/screens/library_screen.dart+++ b/lib/screens/library_screen.dart@@ -104,6 +104,8 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMiList<dynamic> _searchSeriesResults = [];List<dynamic> _searchAuthorResults = [];List<String> _searchNarratorResults = [];+ List<String> _searchTagResults = [];+ List<String> _searchGenreResults = [];List<Map<String, dynamic>> _searchEpisodeResults = [];List<String>? _allNarratorsCache;String? _allNarratorsCacheLibraryId;@@ -1129,6 +1131,18 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi_loadPage();}+ void _applyTagFilter(String tag) {+ clearSearch();+ _tabController?.animateTo(0);+ _changeFilter(LibraryFilter.tag, tag: tag);+ }++ void _applyGenreFilter(String genre) {+ clearSearch();+ _tabController?.animateTo(0);+ _changeFilter(LibraryFilter.genre, genre: genre);+ }+// ── Search ──void _onSearchChanged(String query) {_debounce?.cancel();@@ -1140,6 +1154,8 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi_searchSeriesResults = [];_searchAuthorResults = [];_searchNarratorResults = [];+ _searchTagResults = [];+ _searchGenreResults = [];_searchEpisodeResults = [];_hasSearched = false;_isSearching = false;@@ -1176,6 +1192,18 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi}_searchSeriesResults = (result['series'] as List<dynamic>?) ?? [];_searchAuthorResults = (result['authors'] as List<dynamic>?) ?? [];+ if (!isPodcast) {+ final q = query.toLowerCase();+ _searchTagResults = _availableTags+ .where((t) => t.toLowerCase().contains(q))+ .toList();+ _searchGenreResults = _availableGenres+ .where((g) => g.toLowerCase().contains(q))+ .toList();+ } else {+ _searchTagResults = [];+ _searchGenreResults = [];+ }_isSearching = false;_hasSearched = true;});@@ -2118,7 +2146,7 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMislivers: [injector, const SliverToBoxAdapter(child: SizedBox.shrink())],);}- if (_searchBookResults.isEmpty && _searchSeriesResults.isEmpty && _searchAuthorResults.isEmpty && _searchNarratorResults.isEmpty && _searchEpisodeResults.isEmpty) {+ if (_searchBookResults.isEmpty && _searchSeriesResults.isEmpty && _searchAuthorResults.isEmpty && _searchNarratorResults.isEmpty && _searchEpisodeResults.isEmpty && _searchTagResults.isEmpty && _searchGenreResults.isEmpty) {return CustomScrollView(physics: const AlwaysScrollableScrollPhysics(),slivers: [@@ -2249,6 +2277,53 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi),..._searchNarratorResults.map((name) => NarratorResultTile(name: name)),],++ // ─── GENRES ───+ if (_searchGenreResults.isNotEmpty) ...[+ Padding(+ padding: EdgeInsets.fromLTRB(+ 4,+ (_searchBookResults.isNotEmpty ||+ _searchSeriesResults.isNotEmpty ||+ _searchAuthorResults.isNotEmpty ||+ _searchNarratorResults.isNotEmpty)+ ? 20+ : 8,+ 4,+ 8),+ child: Text(l.librarySearchGenres,+ style: tt.titleMedium?.copyWith(+ fontWeight: FontWeight.w600, color: cs.primary)),+ ),+ ..._searchGenreResults.map((name) => GenreResultTile(+ name: name,+ onTap: () => _applyGenreFilter(name),+ )),+ ],++ // ─── TAGS ───+ if (_searchTagResults.isNotEmpty) ...[+ Padding(+ padding: EdgeInsets.fromLTRB(+ 4,+ (_searchBookResults.isNotEmpty ||+ _searchSeriesResults.isNotEmpty ||+ _searchAuthorResults.isNotEmpty ||+ _searchNarratorResults.isNotEmpty ||+ _searchGenreResults.isNotEmpty)+ ? 20+ : 8,+ 4,+ 8),+ child: Text(l.librarySearchTags,+ style: tt.titleMedium?.copyWith(+ fontWeight: FontWeight.w600, color: cs.primary)),+ ),+ ..._searchTagResults.map((name) => TagResultTile(+ name: name,+ onTap: () => _applyTagFilter(name),+ )),+ ],];return CustomScrollView(diff --git a/lib/widgets/library_search_results.dart b/lib/widgets/library_search_results.dartindex 571f8250..76c92226 100644--- a/lib/widgets/library_search_results.dart+++ b/lib/widgets/library_search_results.dart@@ -559,3 +559,119 @@ class NarratorResultTile extends StatelessWidget {);}}++class GenreResultTile extends StatelessWidget {+ final String name;+ final VoidCallback onTap;++ const GenreResultTile({super.key, required this.name, required this.onTap});++ @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: onTap,+ 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.secondaryContainer,+ ),+ child: Center(+ child: Icon(Icons.category_outlined,+ size: 22,+ color: cs.onSecondaryContainer.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),+ ],+ ),+ ),+ ),+ ),+ );+ }+}++class TagResultTile extends StatelessWidget {+ final String name;+ final VoidCallback onTap;++ const TagResultTile({super.key, required this.name, required this.onTap});++ @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: onTap,+ 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.label_outline_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),+ ],+ ),+ ),+ ),+ ),+ );+ }+}