Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix hide-ebook-only filter, sleep timer foreground ticks

Nathan Poulson427abf1af23f
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart
index 69863946..c218d27e 100644
--- a/lib/screens/home_screen.dart
+++ b/lib/screens/home_screen.dart
@@ -123,8 +123,12 @@ class HomeScreenState extends State<HomeScreen> {
});
}
- List<dynamic> _filterEbookOnly(List<dynamic> items) {
+ List<dynamic> _filterEbookOnly(List<dynamic> items, {String? sectionType}) {
if (!_hideEbookOnly) return items;
+ // Only book shelves can contain ebook-only entries. Series/author/
+ // episode/playlist/collection shelves hold aggregate objects that have
+ // no audio metadata and would all be incorrectly filtered out.
+ if (sectionType != null && sectionType != 'book') return items;
return items.where((e) {
if (e is! Map<String, dynamic>) return true;
// Personalized view entities may nest the item under 'libraryItem'
@@ -165,8 +169,9 @@ class HomeScreenState extends State<HomeScreen> {
List<dynamic> clItems = [];
for (final section in sections) {
if (section['id'] == 'continue-listening') {
- clItems =
- _filterEbookOnly((section['entities'] as List<dynamic>?) ?? []);
+ clItems = _filterEbookOnly(
+ (section['entities'] as List<dynamic>?) ?? [],
+ sectionType: section['type'] as String?);
break;
}
}
@@ -603,7 +608,8 @@ class HomeScreenState extends State<HomeScreen> {
_sectionLabels[id] ??
_titleCase(id);
final entities = _filterEbookOnly(
- (section['entities'] as List<dynamic>?) ?? []);
+ (section['entities'] as List<dynamic>?) ?? [],
+ sectionType: section['type'] as String?);
final type = isPlaylist ? 'playlist'
: isCollection ? 'collection'
: (section['type'] ?? 'book');
diff --git a/lib/services/sleep_timer_service.dart b/lib/services/sleep_timer_service.dart
index ffda3aa2..589e7229 100644
--- a/lib/services/sleep_timer_service.dart
+++ b/lib/services/sleep_timer_service.dart
@@ -179,9 +179,13 @@ class SleepTimerService extends ChangeNotifier {
void _scheduleNextTick() {
_timer?.cancel();
- // Tick every 1s during fade period, every 5s otherwise
+ // Tick every 1s when the app is foregrounded (so the UI countdown looks
+ // smooth) or during the fade period (volume ramp needs per-second resolution).
+ // Only slow down to 5s when backgrounded and far from the fade - no UI to
+ // update, so we save a handful of wake-ups.
final nearFade = _timeRemaining <= _fadeThreshold + const Duration(seconds: 5);
- _tickIntervalSeconds = nearFade ? 1 : 5;
+ final fastTick = nearFade || !_player.isBackgrounded;
+ _tickIntervalSeconds = fastTick ? 1 : 5;
_timer = Timer.periodic(Duration(seconds: _tickIntervalSeconds), _onTimerTick);
}
@@ -599,6 +603,10 @@ class SleepTimerService extends ChangeNotifier {
_accelSub = null;
debugPrint('[SleepTimer] Paused shake detection (backgrounded, not playing)');
}
+ // Switch the countdown to 5s ticks - no UI to update while backgrounded.
+ if (_mode == SleepTimerMode.time && (_timer?.isActive ?? false)) {
+ _scheduleNextTick();
+ }
}
/// Resume operations when app is foregrounded.
@@ -607,6 +615,10 @@ class SleepTimerService extends ChangeNotifier {
_startShakeDetection();
debugPrint('[SleepTimer] Resumed shake detection (foregrounded)');
}
+ // Switch the countdown back to 1s ticks so the UI countdown is smooth.
+ if (_mode == SleepTimerMode.time && (_timer?.isActive ?? false)) {
+ _scheduleNextTick();
+ }
}
@override