Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add mono audio toggle, home tab status badges, and contrast fixes

Nathan Poulsonca1bfaf694f6
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
index 0c609909..4bacb12f 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
@@ -12,6 +12,7 @@ import android.os.Environment
import android.os.StatFs
import android.util.Log
import com.ryanheise.audioservice.AudioServiceActivity
+import com.ryanheise.just_audio.AudioPlayer
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
@@ -64,6 +65,11 @@ class MainActivity : AudioServiceActivity() {
val gain = call.argument<Int>("gain") ?: 0
handleSetLoudness(gain, result)
}
+ "setMono" -> {
+ val enabled = call.argument<Boolean>("enabled") ?: false
+ AudioPlayer.setMonoEnabled(enabled)
+ result.success(true)
+ }
else -> result.notImplemented()
}
}
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 5b6d4671..8d13e9a7 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -81,7 +81,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
Future.delayed(const Duration(milliseconds: 350), () {
final ctx = _keyFor(section).currentContext;
if (ctx != null && mounted) {
- Scrollable.ensureVisible(ctx, duration: const Duration(milliseconds: 250), curve: Curves.easeOut, alignment: 0.0);
+ Scrollable.ensureVisible(ctx, duration: const Duration(milliseconds: 250), curve: Curves.easeOut, alignment: 0.3);
}
});
}
diff --git a/lib/services/equalizer_service.dart b/lib/services/equalizer_service.dart
index 50d22499..a2b59245 100644
--- a/lib/services/equalizer_service.dart
+++ b/lib/services/equalizer_service.dart
@@ -23,6 +23,7 @@ class EqualizerService extends ChangeNotifier {
double _bassBoost = 0.0; // 0.0–1.0
double _virtualizer = 0.0; // 0.0–1.0
double _loudnessGain = 0.0; // 0.0–1.0
+ bool _mono = false;
// Built-in presets (EQ curve shapes)
static const Map<String, List<double>> presets = {
@@ -47,6 +48,7 @@ class EqualizerService extends ChangeNotifier {
double get bassBoost => _bassBoost;
double get virtualizer => _virtualizer;
double get loudnessGain => _loudnessGain;
+ bool get mono => _mono;
/// Initialize — try to connect to platform EQ, fall back to software presets.
Future<void> init() async {
@@ -154,6 +156,16 @@ class EqualizerService extends ChangeNotifier {
notifyListeners();
}
+ /// Toggle mono audio mixing.
+ Future<void> setMono(bool value) async {
+ _mono = value;
+ try {
+ await _channel.invokeMethod('setMono', {'enabled': _mono});
+ } catch (_) {}
+ await _saveSettings();
+ notifyListeners();
+ }
+
/// Set loudness enhancer gain (0.0–1.0).
Future<void> setLoudnessGain(double value) async {
_loudnessGain = value.clamp(0.0, 1.0);
@@ -173,6 +185,7 @@ class EqualizerService extends ChangeNotifier {
_bassBoost = 0.0;
_virtualizer = 0.0;
_loudnessGain = 0.0;
+ _mono = false;
if (_enabled) {
_applyCurrentSettings();
}
@@ -204,6 +217,7 @@ class EqualizerService extends ChangeNotifier {
await _channel.invokeMethod('setVirtualizer', {'strength': (_virtualizer * 1000).round()});
await _channel.invokeMethod('setLoudness', {'gain': (_loudnessGain * 1500).round()});
await _channel.invokeMethod('setEnabled', {'enabled': _enabled});
+ await _channel.invokeMethod('setMono', {'enabled': _mono});
} catch (_) {}
}
@@ -219,6 +233,7 @@ class EqualizerService extends ChangeNotifier {
Future<void> _resetPlatform() async {
try {
await _channel.invokeMethod('setEnabled', {'enabled': false});
+ await _channel.invokeMethod('setMono', {'enabled': _mono});
} catch (_) {}
}
@@ -230,6 +245,7 @@ class EqualizerService extends ChangeNotifier {
_bassBoost = await ScopedPrefs.getDouble('eq_bassBoost') ?? 0.0;
_virtualizer = await ScopedPrefs.getDouble('eq_virtualizer') ?? 0.0;
_loudnessGain = await ScopedPrefs.getDouble('eq_loudnessGain') ?? 0.0;
+ _mono = await ScopedPrefs.getBool('eq_mono') ?? false;
final bandStr = await ScopedPrefs.getString('eq_bands');
if (bandStr != null) {
@@ -245,6 +261,7 @@ class EqualizerService extends ChangeNotifier {
await ScopedPrefs.setDouble('eq_bassBoost', _bassBoost);
await ScopedPrefs.setDouble('eq_virtualizer', _virtualizer);
await ScopedPrefs.setDouble('eq_loudnessGain', _loudnessGain);
+ await ScopedPrefs.setBool('eq_mono', _mono);
await ScopedPrefs.setString('eq_bands', _bandLevels.map((l) => l.toStringAsFixed(1)).join(','));
}
diff --git a/lib/widgets/book_card.dart b/lib/widgets/book_card.dart
index 0ed57913..0720158d 100644
--- a/lib/widgets/book_card.dart
+++ b/lib/widgets/book_card.dart
@@ -34,17 +34,16 @@ class BookCard extends StatelessWidget {
final coverUrl = lib.getCoverUrl(itemId);
// Progress from LibraryProvider (fetched via /api/me, same source as book detail)
- double progress = 0;
- if (showProgress) {
- progress = lib.getProgress(itemId);
- }
+ final progress = lib.getProgress(itemId);
+ final isFinished = lib.getProgressData(itemId)?['isFinished'] == true;
+ final isDownloaded = DownloadService().isDownloaded(itemId ?? '');
final headers = lib.mediaHeaders;
if (isWide) {
return _buildWideCard(context, cs, tt, title, authorName, coverUrl, progress, headers);
}
- return _buildCompactCard(context, cs, tt, title, authorName, coverUrl, progress, headers);
+ return _buildCompactCard(context, cs, tt, title, authorName, coverUrl, progress, headers, isFinished: isFinished, isDownloaded: isDownloaded);
}
void _navigateToDetail(BuildContext context) {
@@ -181,8 +180,10 @@ class BookCard extends StatelessWidget {
String authorName,
String? coverUrl,
double progress,
- Map<String, String> headers,
- ) {
+ Map<String, String> headers, {
+ bool isFinished = false,
+ bool isDownloaded = false,
+ }) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
@@ -205,20 +206,7 @@ class BookCard extends StatelessWidget {
fit: StackFit.expand,
children: [
_CoverImage(coverUrl: coverUrl, cs: cs, httpHeaders: headers),
- if (DownloadService().isDownloaded(item['id'] as String? ?? ''))
- Positioned(
- top: 4, right: 4,
- child: Container(
- padding: const EdgeInsets.all(3),
- decoration: BoxDecoration(
- color: Colors.black54,
- borderRadius: BorderRadius.circular(6),
- ),
- child: Icon(Icons.download_done_rounded,
- size: 14, color: cs.primary),
- ),
- ),
- if (showProgress && progress > 0)
+ if (progress > 0 && !isFinished)
Positioned(
left: 0,
right: 0,
@@ -229,12 +217,60 @@ class BookCard extends StatelessWidget {
),
child: LinearProgressIndicator(
value: progress.clamp(0, 1),
- minHeight: 4,
+ minHeight: 3,
backgroundColor: Colors.transparent,
valueColor: AlwaysStoppedAnimation(cs.primary),
),
),
),
+ if (isFinished || isDownloaded)
+ Positioned(
+ left: 0,
+ right: 0,
+ bottom: 0,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
+ decoration: BoxDecoration(
+ borderRadius: const BorderRadius.vertical(bottom: Radius.circular(12)),
+ gradient: LinearGradient(
+ begin: Alignment.bottomCenter,
+ end: Alignment.topCenter,
+ colors: [
+ Colors.black.withValues(alpha: 0.85),
+ Colors.black.withValues(alpha: 0.0),
+ ],
+ ),
+ ),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (isFinished) ...[
+ Icon(Icons.check_circle_rounded,
+ size: 10, color: Theme.of(context).brightness == Brightness.dark ? Colors.greenAccent[400] : Colors.green.shade700),
+ const SizedBox(width: 3),
+ Text('Done',
+ style: TextStyle(
+ fontSize: 9,
+ fontWeight: FontWeight.w600,
+ color: Theme.of(context).brightness == Brightness.dark ? Colors.greenAccent[400] : Colors.green.shade700)),
+ ],
+ if (isFinished && isDownloaded)
+ const SizedBox(width: 6),
+ if (isDownloaded) ...[
+ Icon(Icons.download_done_rounded,
+ size: 10, color: cs.primary),
+ const SizedBox(width: 3),
+ Text('Saved',
+ style: TextStyle(
+ fontSize: 9,
+ fontWeight: FontWeight.w600,
+ color: cs.primary)),
+ ],
+ ],
+ ),
+ ),
+ ),
],
),
),
diff --git a/lib/widgets/book_detail_sheet.dart b/lib/widgets/book_detail_sheet.dart
index b14f1683..d82c8610 100644
--- a/lib/widgets/book_detail_sheet.dart
+++ b/lib/widgets/book_detail_sheet.dart
@@ -269,7 +269,7 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
return FilledButton.icon(
onPressed: showAbsorbingState
- ? null
+ ? () {}
: () {
setState(() => _isAbsorbing = true);
_startAbsorb(
diff --git a/lib/widgets/card_progress_bar.dart b/lib/widgets/card_progress_bar.dart
index f0583eed..8b3afe86 100644
--- a/lib/widgets/card_progress_bar.dart
+++ b/lib/widgets/card_progress_bar.dart
@@ -274,12 +274,12 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPr
)),
] else ...[
Row(children: [
- Text(_fmt(_bookDragValue != null ? _bookDragValue! * totalDur : posS), style: tt.labelSmall?.copyWith(color: _bookDragValue != null ? cs.onSurface.withValues(alpha: 0.6) : cs.onSurface.withValues(alpha: 0.38), fontSize: 11, fontWeight: FontWeight.w500)),
+ Text(_fmt(_bookDragValue != null ? _bookDragValue! * totalDur : posS), style: tt.labelSmall?.copyWith(color: _bookDragValue != null ? cs.onSurface.withValues(alpha: 0.6) : cs.onSurface.withValues(alpha: 0.5), fontSize: 11, fontWeight: FontWeight.w500, shadows: [Shadow(color: Theme.of(context).brightness == Brightness.dark ? Colors.black.withValues(alpha: 0.5) : Colors.white.withValues(alpha: 0.5), blurRadius: 3)])),
const SizedBox(width: 8),
Expanded(child: ClipRRect(borderRadius: BorderRadius.circular(4),
child: LinearProgressIndicator(value: bookProgress, minHeight: 3, backgroundColor: cs.onSurface.withValues(alpha: 0.08), valueColor: AlwaysStoppedAnimation(widget.accent.withValues(alpha: 0.5))))),
const SizedBox(width: 8),
- Text('-${_fmt(_bookDragValue != null ? (1.0 - _bookDragValue!) * totalDur : bookRemaining)}', style: tt.labelSmall?.copyWith(color: _bookDragValue != null ? cs.onSurface.withValues(alpha: 0.6) : cs.onSurface.withValues(alpha: 0.38), fontSize: 11, fontWeight: FontWeight.w500)),
+ Text('-${_fmt(_bookDragValue != null ? (1.0 - _bookDragValue!) * totalDur : bookRemaining)}', style: tt.labelSmall?.copyWith(color: _bookDragValue != null ? cs.onSurface.withValues(alpha: 0.6) : cs.onSurface.withValues(alpha: 0.5), fontSize: 11, fontWeight: FontWeight.w500, shadows: [Shadow(color: Theme.of(context).brightness == Brightness.dark ? Colors.black.withValues(alpha: 0.5) : Colors.white.withValues(alpha: 0.5), blurRadius: 3)])),
]),
const SizedBox(height: 10),
],
@@ -338,12 +338,14 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPr
style: tt.labelSmall?.copyWith(
color: _chapterDragValue != null ? widget.accent : cs.onSurface.withValues(alpha: 0.54),
fontSize: 11, fontWeight: FontWeight.w600,
- fontFeatures: const [FontFeature.tabularFigures()])),
+ fontFeatures: const [FontFeature.tabularFigures()],
+ shadows: [Shadow(color: Theme.of(context).brightness == Brightness.dark ? Colors.black.withValues(alpha: 0.5) : Colors.white.withValues(alpha: 0.5), blurRadius: 3)])),
Text('-${_fmt(_chapterDragValue != null ? ((1.0 - _chapterDragValue!) * chapterDur) / speedDiv : chapterRemaining)}',
style: tt.labelSmall?.copyWith(
- color: _chapterDragValue != null ? widget.accent : cs.onSurface.withValues(alpha: 0.38),
+ color: _chapterDragValue != null ? widget.accent : cs.onSurface.withValues(alpha: 0.5),
fontSize: 11, fontWeight: FontWeight.w500,
- fontFeatures: const [FontFeature.tabularFigures()])),
+ fontFeatures: const [FontFeature.tabularFigures()],
+ shadows: [Shadow(color: Theme.of(context).brightness == Brightness.dark ? Colors.black.withValues(alpha: 0.5) : Colors.white.withValues(alpha: 0.5), blurRadius: 3)])),
],
)),
], // end showChapterBar
diff --git a/lib/widgets/equalizer_sheet.dart b/lib/widgets/equalizer_sheet.dart
index 4b4deb3c..5d14bf2f 100644
--- a/lib/widgets/equalizer_sheet.dart
+++ b/lib/widgets/equalizer_sheet.dart
@@ -213,6 +213,36 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
enabled: _eq.enabled,
onChanged: (v) => _eq.setLoudnessGain(v),
),
+ const SizedBox(height: 8),
+
+ // Mono toggle
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
+ decoration: BoxDecoration(
+ color: cs.onSurface.withValues(alpha: 0.04),
+ borderRadius: BorderRadius.circular(14),
+ ),
+ child: Row(
+ children: [
+ Icon(Icons.headphones_rounded, size: 18,
+ color: _eq.mono ? accent.withValues(alpha: 0.7) : cs.onSurface.withValues(alpha: 0.2)),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Text('Mono Audio', style: TextStyle(
+ color: _eq.mono ? cs.onSurface.withValues(alpha: 0.7) : cs.onSurface.withValues(alpha: 0.24),
+ fontSize: 12, fontWeight: FontWeight.w500)),
+ ),
+ Transform.scale(
+ scale: 0.8,
+ child: Switch(
+ value: _eq.mono,
+ activeTrackColor: accent,
+ onChanged: (v) => _eq.setMono(v),
+ ),
+ ),
+ ],
+ ),
+ ),
const SizedBox(height: 20),
diff --git a/packages/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java b/packages/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java
index fa49de27..932dfe04 100644
--- a/packages/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java
+++ b/packages/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java
@@ -105,6 +105,8 @@ public class AudioPlayer implements MethodCallHandler, Player.Listener, Metadata
private Map<String, Object> pendingPlaybackEvent;
private ExoPlayer player;
+ private androidx.media3.exoplayer.audio.ChannelMixingAudioProcessor monoProcessor;
+ private static androidx.media3.exoplayer.audio.ChannelMixingAudioProcessor sMonoProcessor;
private Integer audioSessionId;
private MediaSource mediaSource;
private Integer currentIndex;
@@ -451,6 +453,10 @@ public class AudioPlayer implements MethodCallHandler, Player.Listener, Metadata
setSkipSilenceEnabled((Boolean) call.argument("enabled"));
result.success(new HashMap<String, Object>());
break;
+ case "setMono":
+ setMonoEnabled((Boolean) call.argument("enabled"));
+ result.success(new HashMap<String, Object>());
+ break;
case "setLoopMode":
setLoopMode((Integer) call.argument("loopMode"));
result.success(new HashMap<String, Object>());
@@ -770,17 +776,19 @@ public class AudioPlayer implements MethodCallHandler, Player.Listener, Metadata
private void ensurePlayerInitialized() {
if (player == null) {
androidx.media3.common.audio.SonicAudioProcessor sonicAudioProcessor = new androidx.media3.common.audio.SonicAudioProcessor();
+ monoProcessor = new androidx.media3.exoplayer.audio.ChannelMixingAudioProcessor();
+ sMonoProcessor = monoProcessor;
RenderersFactory renderersFactory = new DefaultRenderersFactory(context) {
@Override
protected AudioSink buildAudioSink(
Context context,
boolean enableFloatOutput,
boolean enableAudioTrackPlaybackParams) {
- Log.i(TAG, "PATCH ACTIVE: buildAudioSink with SonicAudioProcessor, AudioTrack speed DISABLED");
+ Log.i(TAG, "PATCH ACTIVE: buildAudioSink with SonicAudioProcessor + MonoProcessor, AudioTrack speed DISABLED");
return new DefaultAudioSink.Builder(context)
.setEnableFloatOutput(enableFloatOutput)
.setEnableAudioTrackPlaybackParams(false)
- .setAudioProcessors(new androidx.media3.common.audio.AudioProcessor[]{sonicAudioProcessor})
+ .setAudioProcessors(new androidx.media3.common.audio.AudioProcessor[]{sonicAudioProcessor, monoProcessor})
.build();
}
};
@@ -1007,6 +1015,19 @@ public class AudioPlayer implements MethodCallHandler, Player.Listener, Metadata
player.setSkipSilenceEnabled(enabled);
}
+ public static void setMonoEnabled(final boolean enabled) {
+ if (sMonoProcessor == null) return;
+ if (enabled) {
+ // Mix both input channels equally into both output channels
+ sMonoProcessor.putChannelMixingMatrix(
+ new androidx.media3.exoplayer.audio.ChannelMixingMatrix(2, 2, new float[]{0.5f, 0.5f, 0.5f, 0.5f}));
+ } else {
+ // Identity matrix - passthrough
+ sMonoProcessor.putChannelMixingMatrix(
+ new androidx.media3.exoplayer.audio.ChannelMixingMatrix(2, 2, new float[]{1f, 0f, 0f, 1f}));
+ }
+ }
+
public void setLoopMode(final int mode) {
player.setRepeatMode(mode);
}