A cross platform Audiobookshelf client for Android and iOS
Dart
Fix timeListened reporting, card layout spacing, expanded card button size
Nathan Poulsone4660c3aa293
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dartindex 986db9a1..41f952c5 100644--- a/lib/screens/home_screen.dart+++ b/lib/screens/home_screen.dart@@ -763,7 +763,7 @@ class _ContinueListeningCardState extends State<_ContinueListeningCard> {const Spacer(),Text.rich(TextSpan(children: [TextSpan(- text: '${(progress * 100).round()}%',+ text: '${(totalDuration > 0 ? (currentTime / totalDuration * 100).round() : (progress * 100).round())}%',style: tt.labelSmall?.copyWith(fontWeight: FontWeight.w700, color: cs.primary, fontSize: 11)),if (totalDuration > 0)@@ -782,7 +782,7 @@ class _ContinueListeningCardState extends State<_ContinueListeningCard> {ClipRRect(borderRadius: const BorderRadius.vertical(bottom: Radius.circular(14)),child: LinearProgressIndicator(- value: progress.clamp(0.0, 1.0), minHeight: 3,+ value: (totalDuration > 0 ? currentTime / totalDuration : progress).clamp(0.0, 1.0), minHeight: 3,backgroundColor: Colors.transparent,valueColor: AlwaysStoppedAnimation(cs.primary),),diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dartindex 2bd8ab48..24725647 100644--- a/lib/screens/login_screen.dart+++ b/lib/screens/login_screen.dart@@ -3,6 +3,7 @@ import 'dart:convert';import 'dart:io';import 'dart:ui';import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:file_picker/file_picker.dart';import 'package:package_info_plus/package_info_plus.dart';import 'package:provider/provider.dart';@@ -245,6 +246,7 @@ class _LoginScreenState extends State<LoginScreen>_loginError = auth.errorMessage ?? 'Login failed';});} else {+ TextInput.finishAutofillContext();FocusManager.instance.primaryFocus?.unfocus();if (Navigator.of(context).canPop()) {// If pushed as a route (e.g. Add Account), pop back@@ -890,6 +892,7 @@ class _LoginScreenState extends State<LoginScreen>bool obscureText = false,void Function(String)? onFieldSubmitted,String? Function(String?)? validator,+ Iterable<String>? autofillHints,}) {final isUrl = keyboardType == TextInputType.url;return TextFormField(@@ -900,6 +903,7 @@ class _LoginScreenState extends State<LoginScreen>obscureText: obscureText,autocorrect: !isUrl,enableSuggestions: !isUrl,+ autofillHints: autofillHints,onFieldSubmitted: onFieldSubmitted,validator: validator,style: TextStyle(color: cs.onSurface),@@ -987,7 +991,8 @@ class _LoginScreenState extends State<LoginScreen>}Widget _buildCredentialFields(ColorScheme cs, TextTheme tt) {- return Column(+ return AutofillGroup(+ child: Column(children: [const SizedBox(height: 16),@@ -1025,6 +1030,7 @@ class _LoginScreenState extends State<LoginScreen>label: 'Username',cs: cs,textInputAction: TextInputAction.next,+ autofillHints: const [AutofillHints.username],prefixIcon: Icon(Icons.person_outline_rounded, size: 20,color: cs.onSurfaceVariant.withValues(alpha: 0.5)),validator: (v) {@@ -1043,6 +1049,7 @@ class _LoginScreenState extends State<LoginScreen>cs: cs,obscureText: _obscurePassword,textInputAction: TextInputAction.done,+ autofillHints: const [AutofillHints.password],onFieldSubmitted: (_) => _handleLogin(),prefixIcon: Icon(Icons.lock_outline_rounded, size: 20,color: cs.onSurfaceVariant.withValues(alpha: 0.5)),@@ -1102,6 +1109,7 @@ class _LoginScreenState extends State<LoginScreen>],+ ),);}}diff --git a/lib/services/api_service.dart b/lib/services/api_service.dartindex 45ce3637..8ef4c919 100644--- a/lib/services/api_service.dart+++ b/lib/services/api_service.dart@@ -476,6 +476,7 @@ class ApiService {String sessionId, {required double currentTime,required double duration,+ int timeListened = 60,}) async {try {await http.post(@@ -483,7 +484,7 @@ class ApiService {headers: _headers,body: jsonEncode({'currentTime': currentTime,- 'timeListened': 15,+ 'timeListened': timeListened,'duration': duration,}),).timeout(const Duration(seconds: 10));diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex f2c48fd5..921d8e28 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -1828,6 +1828,7 @@ class AudioPlayerService extends ChangeNotifier {}_playbackSessionId = sessionData['id'] as String?;+ _lastServerSync = DateTime.now();var audioTracks = sessionData['audioTracks'] as List<dynamic>?;if (audioTracks == null || audioTracks.isEmpty) {_clearState();@@ -2404,16 +2405,21 @@ class AudioPlayerService extends ChangeNotifier {// _logEvent(PlaybackEventType.syncLocal); // too noisy for history}+ DateTime _lastServerSync = DateTime.now();+Future<void> _syncToServer(Duration pos) async {if (_api == null || _playbackSessionId == null) return;final ct = pos.inMilliseconds / 1000.0;+ final now = DateTime.now();+ final elapsed = now.difference(_lastServerSync).inSeconds.clamp(0, 120);+ _lastServerSync = now;try {await _api!.syncPlaybackSession(_playbackSessionId!,currentTime: ct,duration: _totalDuration,+ timeListened: elapsed,);- // _logEvent(PlaybackEventType.syncServer); // too noisy for history} catch (_) {}}diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dartindex b08e079b..82755a35 100644--- a/lib/widgets/absorbing_card.dart+++ b/lib/widgets/absorbing_card.dart@@ -489,16 +489,15 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli),SizedBox(height: compact ? 2 : 6),// ── Cover with title/author/chapter overlaid + download badge ──- Expanded(- child: Center(- child: Padding(+ const Spacer(),+ Padding(padding: const EdgeInsets.symmetric(horizontal: 4),child: ListenableBuilder(listenable: ChromecastService(),builder: (context, _) => LayoutBuilder(builder: (context, constraints) {- final maxW = constraints.maxWidth * 0.60;- final maxH = constraints.maxHeight;+ final maxW = constraints.maxWidth * 0.75;+ final maxH = constraints.maxHeight.isFinite ? constraints.maxHeight : maxW;double coverW, coverH;if (_rectangleCovers) {coverW = maxW;@@ -650,17 +649,15 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli},),),- ),- ),),- SizedBox(height: compact ? 8 : 16),+ const Spacer(),// ── Chapter pill-scrubber ──Padding(padding: const EdgeInsets.symmetric(horizontal: 20),child: CardDualProgressBar(player: widget.player, accent: accent, isActive: _isActive, staticProgress: (_isPodcastEpisode && _chapters.isEmpty) ? 0.0 : progress, staticDuration: (_isPodcastEpisode && _chapters.isEmpty) ? widget.player.totalDuration : _effectiveDuration, chapters: _chapters, showBookBar: false, showChapterBar: true, chapterName: (_isPodcastEpisode && _chapters.isEmpty) ? (widget.player.currentEpisodeTitle ?? widget.player.currentTitle ?? _title) : (_episodeId != null && !_isActive ? (_recentEpisode?['title'] as String? ?? _title) : _chapterName(chapterIdx)), chapterIndex: chapterIdx, totalChapters: totalChapters, itemId: _itemId, compact: compact),),// ── Controls ──- SizedBox(height: compact ? 6 : 12),+ const Spacer(),Padding(padding: const EdgeInsets.symmetric(horizontal: 20),child: CardPlaybackControls(@@ -673,7 +670,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveClishowPlayButton: !_coverPlayButton,),),- SizedBox(height: compact ? 6 : 12),+ const Spacer(),// ── Button grid + more menu ──Padding(padding: const EdgeInsets.symmetric(horizontal: 20),diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dartindex d073c96b..79df58f3 100644--- a/lib/widgets/expanded_card.dart+++ b/lib/widgets/expanded_card.dart@@ -742,15 +742,10 @@ class _ExpandedCardState extends State<ExpandedCard> {),// ── Controls + buttons ──Expanded(- child: LayoutBuilder(- builder: (context, lc) {- return FittedBox(- fit: BoxFit.scaleDown,- alignment: Alignment.center,- child: SizedBox(- width: lc.maxWidth - 56,- child: Column(- mainAxisSize: MainAxisSize.min,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 28),+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,children: [const SizedBox(height: 18),CardPlaybackControls(@@ -803,9 +798,6 @@ class _ExpandedCardState extends State<ExpandedCard> {const SizedBox(height: 12),],),- ),- );- },),),],