A cross platform Audiobookshelf client for Android and iOS
Dart
Mark as not finished also forgets the old position in the app so play starts over like it does on the server
Barnabas1dad32b5a116
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex aa7a886c..f3a31e58 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -1557,7 +1557,7 @@"markedAsFinishedNiceWork": "Marked as finished - nice work!","failedToUpdateCheckConnection": "Failed to update - check your connection","markAsNotFinishedQuestion": "Mark as Not Finished?",- "markAsNotFinishedContent": "This will clear the finished status but keep your current position.",+ "markAsNotFinishedContent": "This will clear the finished status and put your position back at the start.","unmark": "Unmark","markedAsNotFinishedBackAtIt": "Marked as not finished - back at it!","resetProgressQuestion": "Reset Progress?",diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex a57043a6..5b0af6d8 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -5695,7 +5695,7 @@ abstract class AppLocalizations {/// No description provided for @markAsNotFinishedContent.////// In en, this message translates to:- /// **'This will clear the finished status but keep your current position.'**+ /// **'This will clear the finished status and put your position back at the start.'**String get markAsNotFinishedContent;/// No description provided for @unmark.diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dartindex 3f684c64..166630ec 100644--- a/lib/l10n/app_localizations_el.dart+++ b/lib/l10n/app_localizations_el.dart@@ -3129,7 +3129,7 @@ class AppLocalizationsEl extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 5db9e1a3..0c749873 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -3129,7 +3129,7 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dartindex 3cfadb01..2aa86062 100644--- a/lib/l10n/app_localizations_es.dart+++ b/lib/l10n/app_localizations_es.dart@@ -3131,7 +3131,7 @@ class AppLocalizationsEs extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dartindex a4895282..3157223b 100644--- a/lib/l10n/app_localizations_it.dart+++ b/lib/l10n/app_localizations_it.dart@@ -3129,7 +3129,7 @@ class AppLocalizationsIt extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dartindex 9701f791..f8959eb2 100644--- a/lib/l10n/app_localizations_ja.dart+++ b/lib/l10n/app_localizations_ja.dart@@ -3129,7 +3129,7 @@ class AppLocalizationsJa extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dartindex b5713278..25915686 100644--- a/lib/l10n/app_localizations_no.dart+++ b/lib/l10n/app_localizations_no.dart@@ -3129,7 +3129,7 @@ class AppLocalizationsNo extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dartindex ce3039ab..cb12d042 100644--- a/lib/l10n/app_localizations_pt.dart+++ b/lib/l10n/app_localizations_pt.dart@@ -3129,7 +3129,7 @@ class AppLocalizationsPt extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dartindex 54f4254e..dc6c04e9 100644--- a/lib/l10n/app_localizations_ro.dart+++ b/lib/l10n/app_localizations_ro.dart@@ -3129,7 +3129,7 @@ class AppLocalizationsRo extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dartindex 4ceaf0c9..b18fd9c6 100644--- a/lib/l10n/app_localizations_ru.dart+++ b/lib/l10n/app_localizations_ru.dart@@ -3133,7 +3133,7 @@ class AppLocalizationsRu extends AppLocalizations {@overrideString get markAsNotFinishedContent =>- 'This will clear the finished status but keep your current position.';+ 'This will clear the finished status and put your position back at the start.';@overrideString get unmark => 'Unmark';diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dartindex a7e4dc02..2bb2c15c 100644--- a/lib/providers/_lp_core.dart+++ b/lib/providers/_lp_core.dart@@ -875,10 +875,32 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {notifyListeners();}+ /// After "mark as not finished" lands on the server, which clears the+ /// position there, drop the local copy too so the card and the next play+ /// don't carry on from the old spot.+ Future<void> markNotFinishedLocally(String itemId) async {+ // A loaded player still holds the old position in memory and would sync+ // it straight back on the next play, so let it go the way reset does.+ final player = AudioPlayerService();+ final loadedKey = player.currentEpisodeId != null+ ? '${player.currentItemId}-${player.currentEpisodeId}'+ : player.currentItemId;+ if (loadedKey == itemId) await player.stopWithoutSaving();+ await ProgressSyncService().deleteLocal(itemId);+ resetProgressFor(itemId);+ }+void resetProgressFor(String itemId) {if (itemId.length > 36 && _progressMap[itemId]?['isFinished'] == true) {nudgeUnfinishedEpisodeCount(itemId.substring(0, 36), 1);}+ // The widget stash is a third copy of the position, outside the scoped+ // prefs. Left alone it wins the resume race and the first sync writes the+ // old spot back to the server.+ unawaited(HomeWidgetService().clearStashedNowPlayingPosition(+ itemId.length > 36 ? itemId.substring(0, 36) : itemId,+ itemId.length > 36 ? itemId.substring(37) : null,+ ));_progressMap.remove(itemId);_localProgressOverrides.remove(itemId);_locallyFinishedItems.remove(itemId);diff --git a/lib/services/home_widget_service.dart b/lib/services/home_widget_service.dartindex 6f9c3420..01d189f3 100644--- a/lib/services/home_widget_service.dart+++ b/lib/services/home_widget_service.dart@@ -240,6 +240,28 @@ class HomeWidgetService {}}+ /// Forget the stashed position for [itemId] when progress is reset or the+ /// item is marked not finished. Otherwise the next play resumes from the+ /// stash and the first sync writes the old spot straight back to the server.+ Future<void> clearStashedNowPlayingPosition(+ String itemId,+ String? episodeId,+ ) async {+ if (!supportsStashedNowPlayingPosition(defaultTargetPlatform)) return;+ try {+ await _ensureAppGroupId();+ final stashedItem = await HomeWidget.getWidgetData<String>('np_item_id');+ if (stashedItem != itemId) return;+ final stashedEpisode =+ await HomeWidget.getWidgetData<String>('np_episode_id');+ if (stashedEpisode != episodeId) return;+ await HomeWidget.saveWidgetData<double>('np_position_s', 0.0);+ debugPrint('[WidgetDebug] Cleared stashed position for $itemId ep=$episodeId');+ } catch (e) {+ debugPrint('[WidgetDebug] clearStashedNowPlayingPosition failed: $e');+ }+ }+void dispose() {_progressTimer?.cancel();_statsTimer?.cancel();diff --git a/lib/widgets/book_detail_sheet.dart b/lib/widgets/book_detail_sheet.dartindex 39e8fe2d..ff33647d 100644--- a/lib/widgets/book_detail_sheet.dart+++ b/lib/widgets/book_detail_sheet.dart@@ -2321,10 +2321,9 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {if (api == null) return;try {await api.markNotFinished(widget.itemId, currentTime: currentTime, duration: duration);- await ProgressSyncService().deleteLocal(widget.itemId);if (context.mounted) {final lib = context.read<LibraryProvider>();- lib.resetProgressFor(widget.itemId);+ await lib.markNotFinishedLocally(widget.itemId);lib.unblockFromAbsorbing(widget.itemId);await _loadItem();await lib.refresh();diff --git a/lib/widgets/episode_detail_sheet.dart b/lib/widgets/episode_detail_sheet.dartindex b1ad3f3c..0ac0257f 100644--- a/lib/widgets/episode_detail_sheet.dart+++ b/lib/widgets/episode_detail_sheet.dart@@ -249,6 +249,7 @@ class _EpisodeDetailSheetState extends State<EpisodeDetailSheet> {duration: _duration,isFinished: false,);+ await lib.markNotFinishedLocally(key);await lib.refresh();if (mounted) {showOverlayToast(diff --git a/lib/widgets/episode_list_sheet.dart b/lib/widgets/episode_list_sheet.dartindex e4787877..dabff157 100644--- a/lib/widgets/episode_list_sheet.dart+++ b/lib/widgets/episode_list_sheet.dart@@ -450,6 +450,7 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {duration: duration,isFinished: false,);+ await lib.markNotFinishedLocally(key);}}diff --git a/lib/widgets/playlist_detail_sheet.dart b/lib/widgets/playlist_detail_sheet.dartindex 8041e83d..1b7ea44a 100644--- a/lib/widgets/playlist_detail_sheet.dart+++ b/lib/widgets/playlist_detail_sheet.dart@@ -142,6 +142,7 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {final ct = (pd?['currentTime'] as num?)?.toDouble() ?? 0;await api.updateEpisodeProgress(libraryItemId, episodeId,currentTime: ct, duration: duration, isFinished: false);+ await lib.markNotFinishedLocally('$libraryItemId-$episodeId');}} else {if (finished) {@@ -151,6 +152,7 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {final pd = lib.getProgressData(libraryItemId);final ct = (pd?['currentTime'] as num?)?.toDouble() ?? 0;await api.markNotFinished(libraryItemId, currentTime: ct, duration: duration);+ await lib.markNotFinishedLocally(libraryItemId);}}}diff --git a/lib/widgets/podcast_episode_feed.dart b/lib/widgets/podcast_episode_feed.dartindex b8a0711c..52fc8a08 100644--- a/lib/widgets/podcast_episode_feed.dart+++ b/lib/widgets/podcast_episode_feed.dart@@ -542,6 +542,7 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {duration: duration,isFinished: false,);+ await lib.markNotFinishedLocally('$showId-$epId');await lib.refreshProgressOnly();} else {await api.updateEpisodeProgress(diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dartindex 7f10a744..0ee4a0e1 100644--- a/lib/widgets/series_books_sheet.dart+++ b/lib/widgets/series_books_sheet.dart@@ -691,7 +691,7 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {? (media['duration'] as num).toDouble(): 0.0;await api.markNotFinished(bookId, currentTime: 0, duration: duration);- lib.resetProgressFor(bookId);+ await lib.markNotFinishedLocally(bookId);lib.clearAbsorbingBlock(bookId);}