Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add reverse position sort option for bookmarks

Nathan Poulson73f5088c2da3
diff --git a/lib/screens/bookmarks_screen.dart b/lib/screens/bookmarks_screen.dart
index 90619593..80a5b553 100644
--- a/lib/screens/bookmarks_screen.dart
+++ b/lib/screens/bookmarks_screen.dart
@@ -360,10 +360,19 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
else ...[
if (_allBookmarks.isNotEmpty) ...[
IconButton(
- icon: Icon(_sort == 'newest' ? Icons.schedule_rounded : Icons.sort_rounded, color: cs.onSurfaceVariant),
- tooltip: _sort == 'newest' ? 'Sorted by newest' : 'Sorted by position',
+ icon: Icon(
+ _sort == 'newest' ? Icons.schedule_rounded
+ : _sort == 'position' ? Icons.arrow_upward_rounded
+ : Icons.arrow_downward_rounded,
+ color: cs.onSurfaceVariant,
+ ),
+ tooltip: _sort == 'newest' ? 'Sorted by newest'
+ : _sort == 'position' ? 'Sorted by position'
+ : 'Sorted by position (reversed)',
onPressed: () {
- final next = _sort == 'newest' ? 'position' : 'newest';
+ final next = _sort == 'newest' ? 'position'
+ : _sort == 'position' ? 'position_desc'
+ : 'newest';
setState(() => _sort = next);
PlayerSettings.setBookmarkSort(next);
_load();
diff --git a/lib/services/bookmark_service.dart b/lib/services/bookmark_service.dart
index f9c0f908..8bebf9d1 100644
--- a/lib/services/bookmark_service.dart
+++ b/lib/services/bookmark_service.dart
@@ -102,6 +102,8 @@ class BookmarkService {
if (sort == 'position') {
bookmarks.sort((a, b) => a.positionSeconds.compareTo(b.positionSeconds));
+ } else if (sort == 'position_desc') {
+ bookmarks.sort((a, b) => b.positionSeconds.compareTo(a.positionSeconds));
} else {
bookmarks.sort((a, b) => b.created.compareTo(a.created));
}
@@ -325,6 +327,8 @@ class BookmarkService {
if (bookmarks.isNotEmpty) {
if (sort == 'position') {
bookmarks.sort((a, b) => a.positionSeconds.compareTo(b.positionSeconds));
+ } else if (sort == 'position_desc') {
+ bookmarks.sort((a, b) => b.positionSeconds.compareTo(a.positionSeconds));
} else {
bookmarks.sort((a, b) => b.created.compareTo(a.created));
}
diff --git a/lib/widgets/card_buttons.dart b/lib/widgets/card_buttons.dart
index 75cc82bc..47bd1d21 100644
--- a/lib/widgets/card_buttons.dart
+++ b/lib/widgets/card_buttons.dart
@@ -589,7 +589,9 @@ class _SimpleBookmarkSheetState extends State<SimpleBookmarkSheet> {
Padding(padding: const EdgeInsets.symmetric(horizontal: 20), child: Row(children: [
GestureDetector(
onTap: () {
- final next = _sort == 'newest' ? 'position' : 'newest';
+ final next = _sort == 'newest' ? 'position'
+ : _sort == 'position' ? 'position_desc'
+ : 'newest';
setState(() => _sort = next);
PlayerSettings.setBookmarkSort(next);
_load();
@@ -597,7 +599,12 @@ class _SimpleBookmarkSheetState extends State<SimpleBookmarkSheet> {
child: Container(
width: 36, height: 36,
decoration: BoxDecoration(color: cs.onSurface.withValues(alpha: 0.06), borderRadius: BorderRadius.circular(10)),
- child: Icon(_sort == 'newest' ? Icons.schedule_rounded : Icons.sort_rounded, color: cs.onSurfaceVariant, size: 20),
+ child: Icon(
+ _sort == 'newest' ? Icons.schedule_rounded
+ : _sort == 'position' ? Icons.arrow_upward_rounded
+ : Icons.arrow_downward_rounded,
+ color: cs.onSurfaceVariant, size: 20,
+ ),
),
),
const Spacer(),