Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Inactive card speed display, chapter barrier setting, info dialog fix

Nathan Poulsond3e2a2dc6553
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 2859c169..d749db51 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -1024,9 +1024,19 @@ class _SettingsScreenState extends State<SettingsScreen> {
SwitchListTile(
title: Row(children: [
const Expanded(child: Text('Chapter barrier on rewind')),
- Tooltip(
- message: 'When skipping back, snap to the chapter start instead of crossing it.\nDouble-tap within 2 seconds to break through.',
- child: Icon(Icons.info_outline_rounded, size: 18, color: cs.onSurfaceVariant.withValues(alpha: 0.5)),
+ GestureDetector(
+ onTap: () => showDialog(
+ context: context,
+ builder: (_) => AlertDialog(
+ title: const Text('Chapter barrier'),
+ content: const Text('When skipping back, the playback will snap to the start of the current chapter instead of crossing into the previous one.\n\nDouble-tap the skip back button within 2 seconds to break through the barrier.'),
+ actions: [TextButton(onPressed: () => Navigator.pop(context), child: const Text('Got it'))],
+ ),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.all(4),
+ child: Icon(Icons.info_outline_rounded, size: 18, color: cs.onSurfaceVariant.withValues(alpha: 0.5)),
+ ),
),
]),
subtitle: Text(
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index 2979eebf..0fb39b7f 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -62,6 +62,8 @@ class PlayerSettings {
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
settingsChanged.notifyListeners();
}
+ /// Public trigger for external callers that save settings directly.
+ static void notifySettingsChanged() => _notify();
// ── Private helpers to eliminate boilerplate ──
diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dart
index 54047f3b..73d2ec64 100644
--- a/lib/widgets/absorbing_card.dart
+++ b/lib/widgets/absorbing_card.dart
@@ -48,6 +48,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
bool _rectangleCovers = false;
bool _coverPlayButton = false;
bool _speedAdjustedTime = true;
+ double _savedSpeed = 1.0; // per-book or default speed for inactive display
final ValueNotifier<bool> _edgeBarExpanded = ValueNotifier(false);
@override
@@ -125,6 +126,14 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
_reloadButtonOrder();
}
+ void _onSpeedMaybeChanged() => _loadSavedSpeed();
+
+ Future<void> _loadSavedSpeed() async {
+ final bookSpeed = await PlayerSettings.getBookSpeed(_itemId);
+ final speed = bookSpeed ?? await PlayerSettings.getDefaultSpeed();
+ if (mounted && speed != _savedSpeed) setState(() => _savedSpeed = speed);
+ }
+
void _reloadButtonOrder() {
PlayerSettings.getCardButtonOrder().then((o) {
if (mounted && o.join(',') != _buttonOrder.join(',')) setState(() => _buttonOrder = o);
@@ -141,6 +150,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
PlayerSettings.getSpeedAdjustedTime().then((v) {
if (mounted && v != _speedAdjustedTime) setState(() => _speedAdjustedTime = v);
});
+ _loadSavedSpeed();
}
void _onDownloadChanged() { if (mounted) setState(() {}); }
@@ -263,6 +273,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
PlayerSettings.settingsChanged.removeListener(_reloadButtonOrder);
ChromecastService().removeListener(_onCastChanged);
DownloadService().removeListener(_onDownloadChanged);
+ widget.player.removeListener(_onSpeedMaybeChanged);
_chapterTrackSub?.cancel();
_blurredCover?.dispose();
_edgeBarExpanded.dispose();
@@ -489,7 +500,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
final ct = (pd?['currentTime'] as num?)?.toDouble();
pos = (ct != null && ct > 0) ? ct : bookProgress * _effectiveDuration;
}
- final speed = _speedAdjustedTime && _isActive ? widget.player.speed : 1.0;
+ final speed = _speedAdjustedTime ? (_isActive ? widget.player.speed : _savedSpeed) : 1.0;
final elapsed = pos / speed;
final remaining = (_effectiveDuration - pos) / speed;
final timeStyle = tt.labelSmall?.copyWith(
@@ -641,7 +652,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
child: Center(
child: coverLoading
? Container(
- width: 56, height: 56,
+ width: 65, height: 65,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black.withValues(alpha: 0.5),
@@ -655,14 +666,14 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
opacity: coverPlaying ? 0.2 : 0.9,
duration: const Duration(milliseconds: 200),
child: Container(
- width: 64, height: 64,
+ width: 72, height: 72,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black.withValues(alpha: 0.45),
),
child: Icon(
coverPlaying ? Icons.pause_rounded : Icons.play_arrow_rounded,
- size: 38, color: accent,
+ size: 42, color: accent,
),
),
),
@@ -1049,7 +1060,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
case 'speed':
return MoreMenuItem(
icon: Icons.speed_rounded, label: 'Speed', accent: accent,
- enabled: _isPlaybackActive,
+ enabled: true,
onTap: () {
Navigator.pop(ctx);
showModalBottomSheet(context: context, backgroundColor: Colors.transparent, useSafeArea: true,
@@ -1284,7 +1295,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
Text('$pct%', style: tt.labelSmall?.copyWith(
color: isCurrent ? accent.withValues(alpha: 0.7) : cs.onSurface.withValues(alpha: 0.24), fontSize: 10, fontWeight: FontWeight.w600)),
const SizedBox(width: 8),
- Text(_fmtDur((end - start) / (_speedAdjustedTime && _isActive ? widget.player.speed : 1.0)), style: tt.labelSmall?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant)),
+ Text(_fmtDur((end - start) / (_speedAdjustedTime ? (_isActive ? widget.player.speed : _savedSpeed) : 1.0)), style: tt.labelSmall?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant)),
]),
onTap: _isPlaybackActive ? () {
final seekDur = Duration(seconds: start.round());
diff --git a/lib/widgets/card_buttons.dart b/lib/widgets/card_buttons.dart
index 91fbc9f7..a29b1ae2 100644
--- a/lib/widgets/card_buttons.dart
+++ b/lib/widgets/card_buttons.dart
@@ -308,7 +308,7 @@ class _CardBookmarkButtonInlineState extends State<CardBookmarkButtonInline> {
}
/// Speed button as wide card — opens the full speed sheet with slider
-class CardSpeedButtonInline extends StatelessWidget {
+class CardSpeedButtonInline extends StatefulWidget {
final AudioPlayerService player;
final Color accent;
final bool isActive;
@@ -317,25 +317,50 @@ class CardSpeedButtonInline extends StatelessWidget {
final String? itemId;
const CardSpeedButtonInline({super.key, required this.player, required this.accent, required this.isActive, this.large = false, this.compact = false, this.itemId});
+ @override State<CardSpeedButtonInline> createState() => _CardSpeedButtonInlineState();
+}
+
+class _CardSpeedButtonInlineState extends State<CardSpeedButtonInline> {
+ double _savedSpeed = 1.0;
+
+ @override
+ void initState() {
+ super.initState();
+ _loadSavedSpeed();
+ PlayerSettings.settingsChanged.addListener(_loadSavedSpeed);
+ }
+
+ @override
+ void dispose() {
+ PlayerSettings.settingsChanged.removeListener(_loadSavedSpeed);
+ super.dispose();
+ }
+
+ Future<void> _loadSavedSpeed() async {
+ if (widget.itemId == null) return;
+ final bookSpeed = await PlayerSettings.getBookSpeed(widget.itemId!);
+ final speed = bookSpeed ?? await PlayerSettings.getDefaultSpeed();
+ if (mounted && speed != _savedSpeed) setState(() => _savedSpeed = speed);
+ }
+
@override Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
final cast = ChromecastService();
- final h = compact ? 30.0 : (large ? 48.0 : 36.0);
- final iconSz = compact ? 13.0 : (large ? 20.0 : 16.0);
- final fontSize = compact ? 10.0 : (large ? 15.0 : 13.0);
- final radius = compact ? 10.0 : (large ? 16.0 : 14.0);
+ final h = widget.compact ? 30.0 : (widget.large ? 48.0 : 36.0);
+ final iconSz = widget.compact ? 13.0 : (widget.large ? 20.0 : 16.0);
+ final fontSize = widget.compact ? 10.0 : (widget.large ? 15.0 : 13.0);
+ final radius = widget.compact ? 10.0 : (widget.large ? 16.0 : 14.0);
return ListenableBuilder(
- listenable: Listenable.merge([cast, player]),
+ listenable: Listenable.merge([cast, widget.player]),
builder: (context, _) {
- final castNow = itemId != null && cast.isCasting && cast.castingItemId == itemId;
- final enabledNow = isActive || castNow;
- final speedNow = castNow ? cast.castSpeed : player.speed;
+ final castNow = widget.itemId != null && cast.isCasting && cast.castingItemId == widget.itemId;
+ final speedNow = castNow ? cast.castSpeed : (widget.isActive ? widget.player.speed : _savedSpeed);
return GestureDetector(
- onTap: enabledNow ? () {
+ onTap: () {
showModalBottomSheet(context: context, backgroundColor: Colors.transparent,
useSafeArea: true,
- builder: (ctx) => CardSpeedSheet(player: player, accent: accent, itemId: itemId));
- } : () => showInactiveToast(context),
+ builder: (ctx) => CardSpeedSheet(player: widget.player, accent: widget.accent, itemId: widget.itemId));
+ },
child: Container(
height: h,
decoration: BoxDecoration(
@@ -343,18 +368,18 @@ class CardSpeedButtonInline extends StatelessWidget {
borderRadius: BorderRadius.circular(radius),
border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),
),
- child: compact
+ child: widget.compact
? Center(child: Text('${speedNow.toStringAsFixed(1)}x', style: TextStyle(
- color: enabledNow ? accent : cs.onSurface.withValues(alpha: 0.24),
+ color: widget.accent,
fontSize: fontSize, fontWeight: FontWeight.w700)))
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.speed_rounded, size: iconSz,
- color: enabledNow ? accent : cs.onSurface.withValues(alpha: 0.24)),
+ color: widget.accent),
const SizedBox(width: 8),
Text('${speedNow.toStringAsFixed(2)}x', style: TextStyle(
- color: enabledNow ? accent : cs.onSurface.withValues(alpha: 0.24),
+ color: widget.accent,
fontSize: fontSize, fontWeight: FontWeight.w700)),
],
),
@@ -386,15 +411,28 @@ class _CardSpeedSheetState extends State<CardSpeedSheet> {
super.initState();
final initialSpeed = _isCasting ? ChromecastService().castSpeed : widget.player.speed;
_speed = (initialSpeed * 20).round() / 20.0;
+ if (!widget.player.hasBook && !_isCasting) _loadSavedSpeed();
+ }
+
+ Future<void> _loadSavedSpeed() async {
+ if (widget.itemId == null) return;
+ final bookSpeed = await PlayerSettings.getBookSpeed(widget.itemId!);
+ final speed = bookSpeed ?? await PlayerSettings.getDefaultSpeed();
+ if (mounted) setState(() => _speed = (speed * 20).round() / 20.0);
}
void _setSpeed(double v) {
final s = (v * 20).round() / 20.0;
setState(() => _speed = s.clamp(0.5, 3.0));
if (_isCasting) {
ChromecastService().setSpeed(_speed);
- } else {
+ } else if (widget.player.hasBook) {
widget.player.setSpeed(_speed);
}
+ // Always save per-book speed so inactive cards pick it up
+ if (widget.itemId != null) {
+ PlayerSettings.setBookSpeed(widget.itemId!, _speed);
+ PlayerSettings.notifySettingsChanged();
+ }
}
@override Widget build(BuildContext context) {
diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dart
index 81cb3c66..e9fb8d21 100644
--- a/lib/widgets/expanded_card.dart
+++ b/lib/widgets/expanded_card.dart
@@ -658,7 +658,7 @@ class _ExpandedCardState extends State<ExpandedCard> {
child: Center(
child: coverLoading
? Container(
- width: 56, height: 56,
+ width: 70, height: 70,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black.withValues(alpha: 0.5),
@@ -672,14 +672,14 @@ class _ExpandedCardState extends State<ExpandedCard> {
opacity: coverPlaying ? 0.2 : 0.9,
duration: const Duration(milliseconds: 200),
child: Container(
- width: 64, height: 64,
+ width: 76, height: 76,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black.withValues(alpha: 0.45),
),
child: Icon(
coverPlaying ? Icons.pause_rounded : Icons.play_arrow_rounded,
- size: 38, color: accent,
+ size: 44, color: accent,
),
),
),
@@ -753,6 +753,7 @@ class _ExpandedCardState extends State<ExpandedCard> {
onStart: _startPlayback,
itemId: _itemId,
showPlayButton: !_coverPlayButton,
+ playButtonSize: 70,
),
SizedBox(height: compact ? 8 : 24),
// ── Button grid ──
@@ -1104,7 +1105,7 @@ class _ExpandedCardState extends State<ExpandedCard> {
case 'speed':
return MoreMenuItem(
icon: Icons.speed_rounded, label: 'Speed', accent: accent,
- enabled: _isPlaybackActive,
+ enabled: true,
onTap: () {
Navigator.pop(ctx);
showModalBottomSheet(context: context, backgroundColor: Colors.transparent, useSafeArea: true,