Skip to content

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.arb
index 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.dart
index 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.dart
index 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 {
@override
String get librarySearchAuthors => 'Autoren';
+ @override
+ String get librarySearchTags => 'Tags';
+
+ @override
+ String get librarySearchGenres => 'Genres';
+
@override
String librarySeriesCount(int count) {
return '$count Serien';
diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart
index 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 {
@override
String get librarySearchAuthors => 'Authors';
+ @override
+ String get librarySearchTags => 'Tags';
+
+ @override
+ String get librarySearchGenres => 'Genres';
+
@override
String librarySeriesCount(int count) {
return '$count series';
diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart
index 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 {
@override
String get librarySearchAuthors => '作者';
+ @override
+ String get librarySearchTags => 'Tags';
+
+ @override
+ String get librarySearchGenres => 'Genres';
+
@override
String librarySeriesCount(int count) {
return '$count 个系列';
diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dart
index 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 TickerProviderStateMi
List<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 TickerProviderStateMi
slivers: [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.dart
index 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),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}