Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Swipe to expand/collapse cards, paginate series books

Nathan Poulsonce79874d7061
diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dart
index 0eaa0e50..cf7cea5e 100644
--- a/lib/screens/absorbing_screen.dart
+++ b/lib/screens/absorbing_screen.dart
@@ -45,13 +45,6 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
return _cardKeys.putIfAbsent(absorbingKey, () => GlobalKey<AbsorbingCardState>());
}
- void _expandCurrentCard() {
- final books = _getAbsorbingBooks(context.read<LibraryProvider>());
- if (books.isEmpty) return;
- final idx = books.length == 1 ? 0 : (_pageController.hasClients ? (_pageController.page ?? 0).round().clamp(0, books.length - 1) : 0);
- final key = _absorbingKey(books[idx]);
- _cardKeys[key]?.currentState?.expandCard(context);
- }
final _cast = ChromecastService();
@@ -565,20 +558,6 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
padding: const EdgeInsets.only(top: 4, bottom: 2),
child: _PageDots(count: books.length, controller: _pageController),
),
- // ── Expand button ──
- if (books.isNotEmpty)
- Align(
- alignment: Alignment.centerRight,
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: _expandCurrentCard,
- child: Padding(
- padding: const EdgeInsets.only(right: 28),
- child: Icon(Icons.open_in_full_rounded, size: 15,
- color: cs.onSurface.withValues(alpha: 0.4)),
- ),
- ),
- ),
// ── Cards (refreshable) ──
Expanded(
child: showBlockingLoader
diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart
index 8ef4c919..717518a0 100644
--- a/lib/services/api_service.dart
+++ b/lib/services/api_service.dart
@@ -778,13 +778,13 @@ class ApiService {
return null;
}
- /// Get a single series with its books.
- Future<Map<String, dynamic>?> getSeries(String seriesId, {String? libraryId}) async {
+ /// Get a single series with its books (paginated).
+ Future<Map<String, dynamic>?> getSeries(String seriesId, {String? libraryId, int page = 0, int limit = 50}) async {
try {
Map<String, dynamic>? seriesMeta;
-
- // Get series metadata
- if (libraryId != null) {
+
+ // Get series metadata (only on first page)
+ if (libraryId != null && page == 0) {
final metaResp = await http.get(
Uri.parse('$_cleanBaseUrl/api/libraries/$libraryId/series/$seriesId'),
headers: _headers,
@@ -793,12 +793,12 @@ class ApiService {
seriesMeta = jsonDecode(metaResp.body) as Map<String, dynamic>;
}
}
-
+
// Get books in the series via library items filter
// ABS filter format: series.<base64(seriesId)>
if (libraryId != null) {
final filterValue = base64Encode(utf8.encode(seriesId));
- final url = '$_cleanBaseUrl/api/libraries/$libraryId/items?filter=series.$filterValue&sort=media.metadata.series.sequence&limit=100&collapseseries=0';
+ final url = '$_cleanBaseUrl/api/libraries/$libraryId/items?filter=series.$filterValue&sort=media.metadata.series.sequence&limit=$limit&page=$page&collapseseries=0';
final itemsResp = await http.get(
Uri.parse(url),
headers: _headers,
@@ -806,10 +806,12 @@ class ApiService {
if (itemsResp.statusCode == 200) {
final data = jsonDecode(itemsResp.body) as Map<String, dynamic>;
final results = data['results'] as List<dynamic>? ?? [];
+ final total = (data['total'] as num?)?.toInt() ?? results.length;
return {
'id': seriesId,
'name': seriesMeta?['name'] ?? '',
'books': results,
+ 'total': total,
};
}
}
diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dart
index f3402acd..91a15e23 100644
--- a/lib/widgets/absorbing_card.dart
+++ b/lib/widgets/absorbing_card.dart
@@ -382,7 +382,12 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
}
final showBookBar = (!_isPodcastEpisode || _chapters.isNotEmpty) && (!lib.isPodcastLibrary || _chapters.isNotEmpty);
- return Container(
+ return GestureDetector(
+ onVerticalDragEnd: (details) {
+ final vy = details.primaryVelocity ?? 0;
+ if (vy < -300) expandCard(context); // swipe up to expand
+ },
+ child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24),
border: Border.all(color: accent.withValues(alpha: 0.15), width: 1),
@@ -762,6 +767,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
],
),
),
+ ),
);
}
diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dart
index 2b65614a..6d6efd5f 100644
--- a/lib/widgets/expanded_card.dart
+++ b/lib/widgets/expanded_card.dart
@@ -498,7 +498,12 @@ class _ExpandedCardState extends State<ExpandedCard> {
bookProgress = progress;
}
- return Scaffold(
+ return GestureDetector(
+ onVerticalDragEnd: (details) {
+ final vy = details.primaryVelocity ?? 0;
+ if (vy > 300) _dismissExpanded(); // swipe down to collapse
+ },
+ child: Scaffold(
backgroundColor: cs.surface,
body: Stack(
fit: StackFit.expand,
@@ -549,15 +554,6 @@ class _ExpandedCardState extends State<ExpandedCard> {
shadows: [Shadow(color: isDark ? Colors.black.withValues(alpha: 0.6) : Colors.white.withValues(alpha: 0.6), blurRadius: 4)],
)),
const Spacer(),
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: _dismissExpanded,
- child: Padding(
- padding: const EdgeInsets.all(8),
- child: Icon(Icons.close_fullscreen_rounded, size: 17,
- color: isDark ? Colors.white.withValues(alpha: 0.6) : Colors.black.withValues(alpha: 0.5)),
- ),
- ),
],
),
),
@@ -805,6 +801,7 @@ class _ExpandedCardState extends State<ExpandedCard> {
),
],
),
+ ),
);
}
diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dart
index cc8d65f5..ca09d6e0 100644
--- a/lib/widgets/series_books_sheet.dart
+++ b/lib/widgets/series_books_sheet.dart
@@ -73,6 +73,13 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
bool _didAutoScroll = false;
+ // Pagination
+ int _currentPage = 0;
+ int _totalBooks = 0;
+ bool _isLoadingMore = false;
+ bool _hasMore = true;
+ static const int _pageSize = 50;
+
@override
void initState() {
super.initState();
@@ -87,14 +94,24 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
_fetchFromApi();
_loadAutoDownloadState();
context.read<LibraryProvider>().addListener(_onLibraryChanged);
+ widget.scrollController.addListener(_onScroll);
}
@override
void dispose() {
+ widget.scrollController.removeListener(_onScroll);
context.read<LibraryProvider>().removeListener(_onLibraryChanged);
super.dispose();
}
+ void _onScroll() {
+ if (_isLoadingMore || !_hasMore) return;
+ final pos = widget.scrollController.position;
+ if (pos.pixels >= pos.maxScrollExtent - 300) {
+ _loadMoreBooks();
+ }
+ }
+
void _onLibraryChanged() {
// Re-fetch to pick up cover changes, metadata updates, etc.
_fetchFromApi();
@@ -220,15 +237,19 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
return;
}
final lib = context.read<LibraryProvider>();
- final data = await api.getSeries(seriesId, libraryId: widget.libraryId ?? lib.selectedLibraryId);
+ final data = await api.getSeries(seriesId, libraryId: widget.libraryId ?? lib.selectedLibraryId, page: 0, limit: _pageSize);
if (data != null && mounted) {
final rawBooks = data['books'] ?? data['libraryItems'] ?? [];
+ final total = (data['total'] as num?)?.toInt() ?? 0;
if (rawBooks is List && rawBooks.isNotEmpty) {
final fetched = _unwrapBooks(rawBooks);
setState(() {
_books = fetched;
_sortBooks();
_isLoading = false;
+ _currentPage = 0;
+ _totalBooks = total;
+ _hasMore = _books.length < total;
});
_scrollToUpNext();
return;
@@ -237,6 +258,34 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
if (mounted) setState(() => _isLoading = false);
}
+ Future<void> _loadMoreBooks() async {
+ if (_isLoadingMore || !_hasMore) return;
+ final seriesId = widget.seriesId;
+ if (seriesId == null || seriesId.isEmpty) return;
+ final auth = context.read<AuthProvider>();
+ final api = auth.apiService;
+ if (api == null) return;
+ setState(() => _isLoadingMore = true);
+ final nextPage = _currentPage + 1;
+ final lib = context.read<LibraryProvider>();
+ final data = await api.getSeries(seriesId, libraryId: widget.libraryId ?? lib.selectedLibraryId, page: nextPage, limit: _pageSize);
+ if (data != null && mounted) {
+ final rawBooks = data['books'] ?? data['libraryItems'] ?? [];
+ if (rawBooks is List && rawBooks.isNotEmpty) {
+ final fetched = _unwrapBooks(rawBooks);
+ setState(() {
+ _books.addAll(fetched);
+ _sortBooks();
+ _currentPage = nextPage;
+ _hasMore = _books.length < _totalBooks;
+ _isLoadingMore = false;
+ });
+ return;
+ }
+ }
+ if (mounted) setState(() { _isLoadingMore = false; _hasMore = false; });
+ }
+
bool get _allFinished {
final lib = context.read<LibraryProvider>();
if (_books.isEmpty) return false;
@@ -508,7 +557,7 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
TextSpan(
children: [
TextSpan(
- text: '${_books.length} book${_books.length != 1 ? 's' : ''} in this series'
+ text: '${_totalBooks > 0 ? _totalBooks : _books.length} book${(_totalBooks > 0 ? _totalBooks : _books.length) != 1 ? 's' : ''} in this series'
'${totalDuration > 0 ? ' · ${_formatDuration(totalDuration)}' : ''}',
),
if (_autoDownloadEnabled) ...[
@@ -568,8 +617,15 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
builder: (context, _) => ListView.builder(
controller: widget.scrollController,
padding: EdgeInsets.fromLTRB(16, 0, 16, 24 + MediaQuery.of(context).viewPadding.bottom),
- itemCount: _books.length,
+ itemCount: _books.length + (_hasMore ? 1 : 0),
itemBuilder: (context, index) {
+ if (index >= _books.length) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 16),
+ child: Center(child: SizedBox(width: 24, height: 24,
+ child: CircularProgressIndicator(strokeWidth: 2, color: cs.primary))),
+ );
+ }
final book = _books[index];
final bookId = book['id'] as String? ?? '';
final media = book['media'] as Map<String, dynamic>? ?? {};