Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add nav bar fade transition, podcast episode sort toggle, and episode numbers

Nathan Poulsonaab508bb32f7
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt
index a431e1c0..5a5acac6 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt
@@ -16,6 +16,7 @@ import android.graphics.RectF
import android.view.KeyEvent
import android.view.View
import android.net.Uri
+import android.os.Build
import android.widget.RemoteViews
import es.antonborri.home_widget.HomeWidgetLaunchIntent
import es.antonborri.home_widget.HomeWidgetPlugin
@@ -105,6 +106,12 @@ class NowPlayingWidget : AppWidgetProvider() {
val widgetData = HomeWidgetPlugin.getData(context)
val views = RemoteViews(context.packageName, R.layout.now_playing_widget)
+ // OnePlus launchers add their own generous widget padding,
+ // so zero ours out to avoid double-padding.
+ if (Build.MANUFACTURER.equals("OnePlus", ignoreCase = true)) {
+ views.setViewPadding(R.id.widget_outer, 0, 0, 0, 0)
+ }
+
val hasBook = widgetData.getBoolean("widget_has_book", false)
val title = widgetData.getString("widget_title", null)
val author = widgetData.getString("widget_author", null)
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt
index cb188221..813cd58e 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt
@@ -16,6 +16,7 @@ import android.graphics.RectF
import android.view.KeyEvent
import android.view.View
import android.net.Uri
+import android.os.Build
import android.widget.RemoteViews
import es.antonborri.home_widget.HomeWidgetLaunchIntent
import es.antonborri.home_widget.HomeWidgetPlugin
@@ -102,6 +103,12 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {
val widgetData = HomeWidgetPlugin.getData(context)
val views = RemoteViews(context.packageName, R.layout.now_playing_widget_compact)
+ // OnePlus launchers add their own generous widget padding,
+ // so zero ours out to avoid double-padding.
+ if (Build.MANUFACTURER.equals("OnePlus", ignoreCase = true)) {
+ views.setViewPadding(R.id.widget_outer, 0, 0, 0, 0)
+ }
+
val hasBook = widgetData.getBoolean("widget_has_book", false)
val title = widgetData.getString("widget_title", null)
val author = widgetData.getString("widget_author", null)
diff --git a/android/app/src/main/res/layout/now_playing_widget.xml b/android/app/src/main/res/layout/now_playing_widget.xml
index fdfc51ac..c3cbf2a5 100644
--- a/android/app/src/main/res/layout/now_playing_widget.xml
+++ b/android/app/src/main/res/layout/now_playing_widget.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Outer wrapper: padding creates space between widget cell and the card -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/widget_outer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="5dp"
@@ -16,14 +17,17 @@
android:background="@drawable/widget_background"
android:clipToOutline="true">
- <!-- Cover art: fixed square, small left margin, centered vertically -->
+ <!-- Cover art: square, scales to fill card height minus small margin -->
<ImageView
android:id="@+id/widget_cover"
- android:layout_width="130dp"
- android:layout_height="130dp"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:adjustViewBounds="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="6dp"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="6dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"
android:contentDescription="Cover art" />
diff --git a/android/app/src/main/res/layout/now_playing_widget_compact.xml b/android/app/src/main/res/layout/now_playing_widget_compact.xml
index 26e2c8b2..b5781d4a 100644
--- a/android/app/src/main/res/layout/now_playing_widget_compact.xml
+++ b/android/app/src/main/res/layout/now_playing_widget_compact.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Compact 4x1 now-playing widget -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/widget_outer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="5dp"
diff --git a/lib/main.dart b/lib/main.dart
index d7172456..9e6573a8 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -4,6 +4,8 @@ import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:permission_handler/permission_handler.dart';
+import 'package:flutter_native_splash/flutter_native_splash.dart';
+
import 'package:device_info_plus/device_info_plus.dart';
import 'providers/auth_provider.dart';
@@ -40,27 +42,11 @@ ThemeMode parseThemeMode(String value) {
}
void main() async {
- WidgetsFlutterBinding.ensureInitialized();
-
- // Register the audio handler FIRST — Android Auto's MediaBrowserService
- // blocks until the handler exists. On cold start (app force-closed,
- // AA launches it), every millisecond of delay here is time the user
- // stares at a loading spinner. Downloads must be loaded before the
- // handler so getChildren() can serve the browse tree immediately.
- try {
- await DownloadService().init().timeout(const Duration(seconds: 8));
- } catch (e) {
- debugPrint('[Main] DownloadService.init timed out or failed: $e');
- }
- // Timeout guards against AudioService.init() hanging when Android killed
- // the app process but kept the MediaBrowserService alive (e.g. Bluetooth
- // or Android Auto was connected). If it times out the app still launches
- // and _initServices() in AuthGate will retry.
- try {
- await AudioPlayerService.init().timeout(const Duration(seconds: 8));
- } catch (e) {
- debugPrint('[Main] AudioPlayerService.init timed out or failed: $e');
- }
+ final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
+ FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
+
+ // Only do the bare minimum before runApp() so the UI appears fast.
+ // Everything else moves to AuthGate._initServices().
// Lock to portrait — no landscape support
await SystemChrome.setPreferredOrientations([
@@ -68,27 +54,10 @@ void main() async {
DeviceOrientation.portraitDown,
]);
- // Load saved theme preference
+ // Load saved theme preference so we render the correct theme immediately
final savedTheme = await PlayerSettings.getThemeMode();
themeNotifier.value = parseThemeMode(savedTheme);
- // Migrate old auto-play booleans → unified queueMode (one-time, no-op after first run)
- await PlayerSettings.migrateQueueMode();
-
- // Load device info for server identification
- await ApiService.initDeviceId();
- await ApiService.initVersion();
- try {
- final info = await DeviceInfoPlugin().androidInfo;
- ApiService.deviceManufacturer = info.manufacturer;
- ApiService.deviceModel = info.model;
- ApiService.deviceSdkInt = info.version.sdkInt;
- } catch (_) {}
-
- // Initialize log service (must be before other services so debugPrint is captured)
- final loggingEnabled = await PlayerSettings.getLoggingEnabled();
- await LogService().init(loggingEnabled);
-
// Capture Flutter framework errors (widget build failures, etc.)
FlutterError.onError = (details) {
FlutterError.presentError(details);
@@ -101,8 +70,8 @@ void main() async {
return true;
};
- // Initialize download notification service
- await DownloadNotificationService().init();
+ // Remove native splash — Flutter will render the AuthGate splash immediately
+ FlutterNativeSplash.remove();
runApp(
MultiProvider(
@@ -315,41 +284,72 @@ class _AuthGateState extends State<AuthGate> {
context.read<AuthProvider>().tryRestoreSession();
}
- // Audio handler already initialized in main() — this is a no-op
- // but kept for safety in case main() init failed.
+ // Migrate old auto-play booleans → unified queueMode (one-time, no-op after first run)
+ await PlayerSettings.migrateQueueMode();
+
+ // Load device info for server identification
+ await ApiService.initDeviceId();
+ await ApiService.initVersion();
+ try {
+ final info = await DeviceInfoPlugin().androidInfo;
+ ApiService.deviceManufacturer = info.manufacturer;
+ ApiService.deviceModel = info.model;
+ ApiService.deviceSdkInt = info.version.sdkInt;
+ } catch (_) {}
+
+ // Initialize log service (must be before other services so debugPrint is captured)
+ try {
+ final loggingEnabled = await PlayerSettings.getLoggingEnabled();
+ await LogService().init(loggingEnabled);
+ } catch (_) {}
+
+ // Downloads must be loaded before the audio handler so getChildren()
+ // can serve the Android Auto browse tree immediately.
+ try {
+ await DownloadService().init().timeout(const Duration(seconds: 8));
+ } catch (e) {
+ debugPrint('[Init] DownloadService.init timed out or failed: $e');
+ }
+
+ // Timeout guards against AudioService.init() hanging when Android killed
+ // the app process but kept the MediaBrowserService alive.
+ try {
+ await AudioPlayerService.init().timeout(const Duration(seconds: 8));
+ } catch (e) {
+ debugPrint('[Init] AudioPlayerService.init timed out or failed: $e');
+ }
+
try {
- await AudioPlayerService.init();
+ await DownloadNotificationService().init();
} catch (e) {
- debugPrint('AudioService init failed: $e');
+ debugPrint('[Init] DownloadNotificationService failed: $e');
}
try {
await Permission.notification.request();
} catch (e) {
- debugPrint('Permission request failed: $e');
+ debugPrint('[Init] Permission request failed: $e');
}
// Initialize Chromecast
try {
await ChromecastService().init();
} catch (e) {
- debugPrint('Chromecast init failed: $e');
+ debugPrint('[Init] Chromecast init failed: $e');
}
// Initialize download tracker and progress sync
try {
await UserAccountService().init();
- await DownloadService().init();
await ProgressSyncService().init();
await EqualizerService().init();
await SleepTimerService().loadAutoSleepSettings();
// Pre-populate Android Auto browse tree in background.
- // Do not block app startup on Android Auto server refresh.
Future.microtask(() => AndroidAutoService().refresh());
// Initialize homescreen widget
await HomeWidgetService().init();
} catch (e) {
- debugPrint('Service init failed: $e');
+ debugPrint('[Init] Service init failed: $e');
}
}
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dart
index 883a7fbc..d2d1209f 100644
--- a/lib/screens/app_shell.dart
+++ b/lib/screens/app_shell.dart
@@ -38,7 +38,7 @@ class AppShell extends StatefulWidget {
State<AppShell> createState() => _AppShellState();
}
-class _AppShellState extends State<AppShell> with WidgetsBindingObserver {
+class _AppShellState extends State<AppShell> with WidgetsBindingObserver, TickerProviderStateMixin {
static _AppShellState? _instance;
// Tabs: 0=Home, 1=Library, 2=Absorbing (default), 3=Stats, 4=Settings
@@ -77,8 +77,12 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver {
return;
}
_ensurePageBuilt(index);
- setState(() {
- _currentIndex = index;
+ _fadeController.reverse().then((_) {
+ if (!mounted) return;
+ setState(() {
+ _currentIndex = index;
+ });
+ _fadeController.forward();
});
}
@@ -103,6 +107,12 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver {
}
}
+ late final AnimationController _fadeController = AnimationController(
+ vsync: this,
+ duration: const Duration(milliseconds: 200),
+ value: 1.0,
+ );
+
@override
void initState() {
super.initState();
@@ -120,6 +130,7 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver {
@override
void dispose() {
+ _fadeController.dispose();
_player.removeListener(_onPlayerChanged);
_cast.removeListener(_onCastChanged);
if (_instance == this) _instance = null;
@@ -267,11 +278,14 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver {
_switchToAbsorbing();
},
child: Scaffold(
- body: IndexedStack(
- index: _currentIndex,
- children: List<Widget>.generate(
- _pages.length,
- (i) => _pages[i] ?? const SizedBox.shrink(),
+ body: FadeTransition(
+ opacity: _fadeController,
+ child: IndexedStack(
+ index: _currentIndex,
+ children: List<Widget>.generate(
+ _pages.length,
+ (i) => _pages[i] ?? const SizedBox.shrink(),
+ ),
),
),
bottomNavigationBar: Column(
diff --git a/lib/widgets/episode_list_sheet.dart b/lib/widgets/episode_list_sheet.dart
index 3ae4a826..f5b73724 100644
--- a/lib/widgets/episode_list_sheet.dart
+++ b/lib/widgets/episode_list_sheet.dart
@@ -54,6 +54,7 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {
bool _isLoading = true;
bool _isDownloadingAll = false;
bool _autoDownloadEnabled = false;
+ bool _newestFirst = true;
String get _itemId => widget.podcastItem['id'] as String? ?? '';
@@ -114,17 +115,24 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {
}
}
- /// Sort episodes newest first by publishedAt.
+ /// Sort episodes by publishedAt according to current sort order.
List<dynamic> _sortEpisodes(List<dynamic> episodes) {
final sorted = List<dynamic>.from(episodes);
sorted.sort((a, b) {
final aTime = (a['publishedAt'] as num?)?.toInt() ?? 0;
final bTime = (b['publishedAt'] as num?)?.toInt() ?? 0;
- return bTime.compareTo(aTime); // newest first
+ return _newestFirst ? bTime.compareTo(aTime) : aTime.compareTo(bTime);
});
return sorted;
}
+ void _toggleSortOrder() {
+ setState(() {
+ _newestFirst = !_newestFirst;
+ _episodes = _sortEpisodes(_episodes);
+ });
+ }
+
Future<void> _playEpisode(Map<String, dynamic> episode) async {
final auth = context.read<AuthProvider>();
final api = auth.apiService;
@@ -398,9 +406,24 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {
// Episodes section header
const SizedBox(height: 16),
- Align(
- alignment: Alignment.centerLeft,
- child: Text('Episodes', style: tt.titleSmall?.copyWith(color: cs.onSurfaceVariant, fontWeight: FontWeight.w600)),
+ Row(
+ children: [
+ Text('Episodes', style: tt.titleSmall?.copyWith(color: cs.onSurfaceVariant, fontWeight: FontWeight.w600)),
+ const Spacer(),
+ GestureDetector(
+ onTap: _toggleSortOrder,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(_newestFirst ? 'Newest' : 'Oldest',
+ style: TextStyle(fontSize: 11, color: cs.onSurfaceVariant.withValues(alpha: 0.6))),
+ const SizedBox(width: 2),
+ Icon(_newestFirst ? Icons.arrow_downward_rounded : Icons.arrow_upward_rounded,
+ size: 14, color: cs.onSurfaceVariant.withValues(alpha: 0.6)),
+ ],
+ ),
+ ),
+ ],
),
const SizedBox(height: 4),
])),
@@ -1052,6 +1075,8 @@ class _EpisodeRowState extends State<_EpisodeRow> {
final episodeId = ep['id'] as String? ?? '';
final duration = (ep['duration'] as num?)?.toDouble() ?? 0;
final publishedAt = (ep['publishedAt'] as num?)?.toInt() ?? 0;
+ final episodeNumber = ep['episode'] as String?;
+ final season = ep['season'] as String?;
// Progress
final progress = lib.getEpisodeProgress(widget.itemId, episodeId);
@@ -1139,6 +1164,16 @@ class _EpisodeRowState extends State<_EpisodeRow> {
),
maxLines: 2, overflow: TextOverflow.ellipsis,
),
+ if (episodeNumber != null || season != null) ...[
+ const SizedBox(height: 2),
+ Text(
+ [
+ if (season != null) 'S$season',
+ if (episodeNumber != null) 'E$episodeNumber',
+ ].join(' '),
+ style: TextStyle(fontSize: 11, color: cs.onSurfaceVariant.withValues(alpha: 0.5)),
+ ),
+ ],
const SizedBox(height: 4),
Row(
children: [
diff --git a/pubspec.yaml b/pubspec.yaml
index e03296ab..f636172a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,7 +1,7 @@
name: absorb
description: A Material 3 Audiobookshelf client for Android.
publish_to: 'none'
-version: 1.8.2+35
+version: 1.8.4+35
environment:
sdk: '>=3.1.0 <4.0.0'