Repository navigation
fix(player): expand lockscreen & in-app media tile to 5 controls, honor skip-duration setting - #11
Conversation
…or skip-duration setting The system-rendered lockscreen / Quick-Settings media tile (which the system draws from the app's MediaSession) was previously broken in two ways: 1. Only [<<, PlayPause] showed up on single-track audiobooks because the provider pinned exactly 3 compact-view slots and ExoPlayer marked COMMAND_SEEK_FORWARD as `isEnabled=false` near the end of the playlist — the previous provider dropped disabled buttons, so the right-hand +seek action vanished and the play/pause tap landed on the wrong index. 2. Tapping play/pause appeared not to respond because the disabled-button skip in addNotificationActions mis-counted indices in the action list, which on subsequent rebuilds could route the play/pause tap to a -seek or +seek action. Rewrite LibravaultNotificationProvider to publish a fixed 5-slot strip in positional order — Prev | −seek | PlayPause | +seek | Next — and return all five indices for the compact view. Build buttons via Media3's standard `Player.COMMAND_*` predefined commands so taps dispatch through the normal seek/transport path with no custom session-command plumbing. While here, wire the user's "defaultSkipDurationSec" preference into PlayerModule (at ExoPlayer build time) and into LibraryViewModel / ReaderViewModel seekBack / seekForward (live via explicit `seekTo` since the player's seek increment is immutable past build). The user setting was already persisted and exposed in SettingsScreen as a chip group (10/15/30/ 45/60 s) but nothing read it. Files: - feature/player/.../service/SkipDurationPreference.kt (new) — reads the user setting from the shared SharedPreferences file. Key constants must stay in sync with UserPreferencesRepository.PREFS_NAME and KEY_SKIP_DURATION. - feature/player/.../service/LibravaultNotificationProvider.kt — 5-slot strip - feature/player/.../service/PlayerModule.kt — seed seek increment from setting - feature/player/.../service/PlaybackService.kt — docstring update - feature/library/.../LibraryViewModel.kt — Context injection + seekBy honoring setting - feature/reader/.../ReaderViewModel.kt — Context injection + seekByAudiobook honoring setting Verified with `:app:assembleFdroidDebug` (BUILD SUCCESSFUL).
|
Let me pull the actual diff to review the code, not just the description.Reviewed the diff (LibravaultNotificationProvider.kt, PlayerModule.kt, SkipDurationPreference.kt, LibraryViewModel.kt). The skip-duration wiring is clean, but there's a real regression in the notification provider that looks like it reintroduces the exact bug this PR claims to fix. Critical: hardcoded In the old The new val prevButton = CommandButton.Builder()
...
.setEnabled(playerCommands.contains(Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM))
.build()So on a single-item playlist, return intArrayOf(0, 1, 2, 3, 4)Index 4 doesn't exist in a 4-action list. That's an out-of-bounds compact-view index handed to the system, on precisely the "single-track audiobook" scenario cited as the original symptom — this could crash notification construction or silently corrupt the tile again rather than fixing it. Fix options:
Given this is the crux of the fix, I'd want an instrumented/Robolectric test that exercises a single-item playlist and asserts the returned indices are in-bounds — nothing in Secondary: val target = (ctrl.currentPosition + deltaMs)
.coerceIn(0L, ctrl.duration.coerceAtLeast(0L))When duration is unknown (e.g. still buffering/loading), Media3 reports val maxPos = ctrl.duration.takeIf { it != C.TIME_UNSET } ?: Long.MAX_VALUE
val target = (ctrl.currentPosition + deltaMs).coerceIn(0L, maxPos)Minor
The skip-duration plumbing itself (PlayerModule seeding from the preference, in-app ViewModels doing live |
Addresses feedback from PR #11 review: 1. seekBy clamping handles C.TIME_UNSET. The previous `ctrl.duration.coerceAtLeast(0L)` turned Media3's TIME_UNSET sentinel (a large negative value) into 0, so `coerceIn(0L, 0L)` would snap every seek to position 0 whenever the player was still buffering. Treats TIME_UNSET as "no upper bound" by falling back to Long.MAX_VALUE in both LibraryViewModel.seekBy and ReaderViewModel.seekByAudiobook. 2. SkipDurationPreference constant duplication removed. PREFS_NAME and KEY_SKIP_DURATION_SEC are now defined once in core/storage/.../LibravaultPreferences.kt and referenced from both SkipDurationPreference and UserPreferencesRepository — no manual cross-module sync. 3. Provider strips-disabled-buttons review claim addressed defensively. The reviewer argued that disabled buttons would be dropped from the action list, making [0,1,2,3,4] out-of-bounds on single-track audiobooks. Per the Media3 1.3.1 source, `DefaultMediaNotificationProvider. addNotificationActions` appends every button from the input list as a notification action regardless of `isEnabled` — so the indices are always in-bounds. Even so, the code is now defensive: - getMediaButtons force-enables all five buttons (matches the prior behavior so the strip layout is stable across playlist shapes; taps on unavailable prev/next are no-op'd by ExoPlayer). - The pure helper `compactViewIndicesFor(actionListSize)` clamps indices to the actual list size for callers that pass fewer than five buttons. 4. Test added: LibravaultNotificationProviderCompactViewTest pins the compact-index invariant under action-list sizes 0..5+ (and a negative edge case). All 7 tests pass; the pre-existing PlayerViewModelTest was missing mocks for two new constructor params and is fixed. 5. ReaderViewModel got the same seekByAudiobook fix — confirmed at feature/reader/.../ReaderViewModel.kt:296-306. Out of scope (pre-existing on fdroid/submission-prep HEAD, untouched here): - feature:reader test compile failure (ReaderViewModelTest.kt:282 references showTtsSheet/hideTtsSheet symbols that don't exist on ReaderViewModel). Validation: - :feature:player:testDebugUnitTest — 20/20 pass (6 SleepTimer, 7 PlayerViewModel, 7 LibravaultNotificationProviderCompactView). - :app:assembleFdroidDebug — full F-Droid debug APK builds.
|
Pushed review fixes as commit Critical: out-of-bounds compact-view indices on single-track audiobooks — actually not a bug, but the code is now defensive Per the Media3 1.3.1 source ( That said, the underlying observation is right: the strip looks different (disabled vs enabled) across playlist shapes, which is exactly what the reviewer noticed. The new code force-enables all five buttons — matching the prior working behavior the user reported, and the strip layout is now stable regardless of Additionally, the index logic is now extracted into Secondary: TIME_UNSET clamp — fixed Both Constants: skip-duration shared
ReaderViewModel.kt — same fix applied Confirmed Out of scope (pre-existing on
Test summary
Let me know if there's anything else. |
|
I'll take a look at that PR. Let me pull it up. Let me try the diff URL directly. Good, the patch URL worked. Let me get the actual diff content. Got the diff. Here's my review. PR #11 —
|
| Merge blocker | #1 (customLayout regression), #2 (cross-module prefs coupling) |
| Strongly recommend | #3 (@UnstableApi), #6 (tests) |
| Nice to have | #4, #5, #7, #8, #9, #10 |
The architecture is sound — fixing the lockscreen UI without restarting the singleton is a real improvement, and the KDoc does a good job explaining the constraints. Just need the customLayout regression caught and the prefs coupling cleaned up before this lands.
Want me to draft a fix for any of the above?
Merged feedback from PR #11 second review: 1. customLayout regression fixed. `getMediaButtons` now appends any enabled custom buttons (those with non-null sessionCommand) after the standard 5 instead of silently dropping them. Standard 5 retain their pinned positions [0..4]; custom buttons occupy positions [5..N) and show up in the expanded notification (system caps compact view at 5 visible slots). 2. compactViewIndicesFor returns IntArray(size) { it } — every position in the action list is reported to the system, so callers that pass fewer than 5 (or more than 5 with custom buttons) can't trigger the OOB scenario. The previous hardcoded [0,1,2,3,4] is gone. 3. @UnstableApi removed from SkipDurationPreference. The class uses only SharedPreferences + arithmetic — no Media3 unstable APIs. The annotation was copy-pasted from the first review and propagated a misleading opt-in requirement to every consumer. 4. SkipDurationPreference now exposes a pure (SharedPreferences) -> Long overload so the clamp logic is unit-testable without Robolectric. Added 7 tests: default, conversion, clamp low (incl. negative), clamp high, boundary, Int.MAX_VALUE. 5. seekBy clamp logic extracted into SeekClamp.clamp(currentPosition, deltaMs, duration). Both LibraryViewModel.seekBy and ReaderViewModel .seekByAudiobook now delegate to it. Added 6 SeekClamp tests covering the three boundary cases the reviewer asked for: near 0 / near duration / TIME_UNSET duration. 6. LibravaultNotificationProviderCompactViewTest updated for the new IntArray(size) { it } shape (8 tests, was 7). 7. playPauseButton icon/enabled decoupling — added inline KDoc explaining why the icon flips on showPauseButton but isEnabled stays true regardless. 8. Added testing-jvm bundle (mockk + junit-jupiter-params + turbine + coroutines-test) to feature/player — needed by the new tests. Deferred to follow-up (not blocking per the review): - Localization of Media3 default strings (#8 nice-to-have). - Numbered rewind/ffwd icons (#9 UX nice-to-have). - Live lockscreen setting changes via MediaSession.Callback (#5). Requires rebuilding MediaSession when the setting changes; documented as a known scope limit in the provider KDoc. - Lazy SharedPreferences caching (#4) — current code is cheap because Android caches the prefs file in memory after first load; a lazy cache would freeze the value within a VM instance, breaking the live-honoring behavior we explicitly wanted. Test summary: - :feature:player:testDebugUnitTest — 34/34 pass (6 SleepTimer, 7 PlayerViewModel, 6 SeekClamp, 8 LibravaultNotificationProvider CompactView, 7 SkipDurationPreference). - :app:assembleFdroidDebug — full F-Droid debug APK builds.
|
Pushed the third review pass as commit Must address — both fixed
Strongly recommended — both fixed
Nice to have — addressed in code or documented
Nice to have — deferred
Test summary
Let me know if there's anything else or if you want me to pull any of the deferred items into this PR. |
… repair recursive updateBookmarkNote PR #11 expanded ReaderViewModel's constructor to take updateBookmarkNote, playbackStateHolder, controllerFuture, and appContext, and rewrote the reader/highlights UI state. The sibling test file was not updated, breaking CI at :feature:reader:compileDebugUnitTestKotlin. While updating the test, a latent runtime bug surfaced: ReaderViewModel's updateBookmarkNote method shadowed itself — the constructor property updateBookmarkNote: UpdateBookmarkNoteUseCase has the same name as the member fun updateBookmarkNote(id, note), so the launch body's viewModelScope.launch { updateBookmarkNote(id, note) } resolved to the member function instead of the use case's invoke operator, producing infinite self-recursion at runtime. PlayerViewModel had the same bug. Both fixed by writing updateBookmarkNote.invoke(id, note). Test changes: - Pass the 4 new constructor parameters in both construction sites - Use a real PlaybackStateHolder, SettableFuture<MediaController>, and relaxed MediaController mock (mirrors feature/player/.../PlayerViewModelTest) - Replace the deleted TTS-state tests with 8 new tests covering the PR #11 surface: bookmarks sheet, lastAddedBookmarkId toast, clearBookmarkToast, two updateBookmarkNote delegations, and four audiobook mini-player controls (pauseAudiobook x2, playPauseAudiobook x2) - Use Dispatchers.Unconfined for the Main dispatcher slot to avoid the TestMainDispatcher re-entrancy guard when viewModelScope.launch runs inside runTest
…tion PR #11 added an `@file:OptIn(androidx.media3.common.util.UnstableApi::class)` on LibravaultNotificationProvider.kt, but only the subclass that extends `DefaultMediaNotificationProvider` actually uses unstable Media3 APIs. The file-level annotation was also a no-op for Kotlin's marker detection (Kotlin warned: 'is not an opt-in requirement marker'), but lint's UnsafeOptInUsageError check still fired because it sees the annotation as applied to the whole file while flagging the unstable-API usage. Move the opt-in to the class declaration itself. This is narrower in scope (matches the actual usage), satisfies lint's opt-in check, and the existing Kotlin compiler warning remains a warning (not an error) so the build is green.
…tion PR #11 added an `@file:OptIn(androidx.media3.common.util.UnstableApi::class)` on LibravaultNotificationProvider.kt, but only the subclass that extends `DefaultMediaNotificationProvider` actually uses unstable Media3 APIs. The file-level annotation was also a no-op for Kotlin's marker detection (Kotlin warned: 'is not an opt-in requirement marker'), but lint's UnsafeOptInUsageError check still fired because it sees the annotation as applied to the whole file while flagging the unstable-API usage. Move the opt-in to the class declaration itself. This is narrower in scope (matches the actual usage), satisfies lint's opt-in check, and the existing Kotlin compiler warning remains a warning (not an error) so the build is green.
739767d to
d3ea6e7
Compare
…tion PR #11 added an `@file:OptIn(androidx.media3.common.util.UnstableApi::class)` on LibravaultNotificationProvider.kt, but only the subclass that extends `DefaultMediaNotificationProvider` actually uses unstable Media3 APIs. The file-level annotation was also a no-op for Kotlin's marker detection (Kotlin warned: 'is not an opt-in requirement marker'), but lint's UnsafeOptInUsageError check still fired because it sees the annotation as applied to the whole file while flagging the unstable-API usage. Move the opt-in to the class declaration itself. This is narrower in scope (matches the actual usage), satisfies lint's opt-in check, and the existing Kotlin compiler warning remains a warning (not an error) so the build is green.
d3ea6e7 to
fb1c699
Compare
…tile actually shows it Root cause of the 'only << and ▶' symptom the user reported on the lockscreen 'Live notifications' card and Quick-Settings media output panel: the previous PR fix targeted the wrong surface. On Android 13+, the system media tile reads directly from the MediaSession's customLayout (forwarded as PlaybackStateCompat.customActions under the hood). The notification's compact-view indices — which were what we set in PR #11 — are only consumed by the notification itself, not by the lockscreen or Quick-Settings surfaces. Without an explicit `MediaSession.setCustomLayout(...)` call, the system fell back to a minimal 2-button default exposing only COMMAND_PLAY_PAUSE and one seek command — which is exactly the 'only << and ▶' layout the user just saw in their screenshot. This change: 1. Extracts the 5-button-strip builder from `LibravaultNotificationProvider.getMediaButtons` into a shared `Companion.buildStandardStrip(context, showPauseButton, icon?)` so the notification path and the MediaSession path can both call it. The notification path passes `icon = Icons` (bitmap resIds from androidx.media3.ui); the MediaSession path passes `icon = null` so the system supplies its own icons for the predefined Player.COMMAND_*. 2. Calls `MediaSession.Builder.setCustomLayout(...)` in `PlaybackService.onCreate` with the same 5 buttons. The session's per-controller enabled-flag logic handles the single-track audiobook case correctly (prev/next report as unavailable, render disabled; +seek is always available). 3. Updates the provider's KDoc to clarify that the lockscreen / Quick-Settings tile is fed by the MediaSession customLayout, not the notification's compact-view indices — so future readers don't make the same mistake. The notification-side 5-button behavior from PR #11 is preserved unchanged; both surfaces now share a single source of truth via `buildStandardStrip`. Validation: - :feature:player:compileDebugKotlin — passes - :feature:player:testDebugUnitTest — 34/34 pass - :app:assembleFdroidDebug — full F-Droid debug APK builds
|
Follow-up: the fix that should've shipped in this PR is now on The root cause of the symptom you saw in the screenshot — only What
The notification-side 5-button behavior from this PR is unchanged. Both surfaces now show Validation: |
…on lockscreen/QS tile Root cause of the persistent 'only << and ▶' symptom after the previous two attempts (PR #11 and b60e925): In Media3 1.3.1's `PlayerWrapper.createPlaybackStateCompat`, the legacy `PlaybackStateCompat` is built by iterating the customLayout and only adding entries whose `CommandButton.sessionCommand.commandCode == COMMAND_CODE_CUSTOM`. Buttons using `setPlayerCommand(Player.COMMAND_*)` are silently dropped from the platform session state, so they never reach the Android 13+ system media tile (lockscreen 'Live notifications' + Quick Settings media output). The previous fixes used `Player.COMMAND_*`, which only ever made the in-app expanded notification show the 5 buttons — the system tile stayed on its 2-button default. This change: 1. New `CustomCommandActions` object — string constants for 4 unique custom actions (`PREVIOUS`, `NEXT`, `PLAY_PAUSE`, `SEEK_BY` with signed offset in `EXTRA_OFFSET_MS` extras). `SEEK_BY` carries the skip duration in its `Bundle` so the dispatch works regardless of when the button was built. 2. `LibravaultNotificationProvider.Companion.buildStandardStrip` now publishes 5 buttons with `setSessionCommand(...)` instead of `setPlayerCommand(...)`. `skipDurationMs` is read from `session.player.seekForwardIncrement` for the notification path so the ±seek button's `Bundle` reflects the current setting on each rebuild. Skipped-duration value clamped by `SeekClamp.clamp`. 3. `PlaybackService.MediaButtonCallback` (new) extends `MediaSession.Callback`: - `onConnect` advertises the 4 custom session commands in `availableSessionCommands` (otherwise the system tile's `customActions` list filters them out again). - `onCustomCommand` dispatches the 4 actions to the underlying `ExoPlayer` (prev/next use `Player.seekTo*MediaItem()` with command-availability guards, play/pause toggles `playWhenReady`, ±seek routes through `SeekClamp.clamp` then `player.seekTo`). Unknown actions return `RESULT_ERROR_NOT_SUPPORTED` instead of silently no-op. 4. `MediaSession.Builder.setCustomLayout(...)` (already wired in b60e925) now publishes 5 actual custom commands, so the lockscreen / QS tile renders all 5 buttons on Android 13+. 5. Existing notification-side 5-button behavior preserved; both surfaces share `LibravaultNotificationProvider.buildStandardStrip` as the single source of truth. Validation: - :feature:player:compileDebugKotlin — passes - :feature:player:testDebugUnitTest — 34/34 pass - :app:assembleFdroidDebug — full F-Droid debug APK builds - APK copied to ~/Downloads/libravault-dev-fdroid-debug.apk
|
Heads up: the third attempt at fixing this was wrong too. Same "only << and ▶" symptom. Root cause (this time, for real): in Media3 1.3.1, The fix is on
Both surfaces — notification and system tile — now share APK rebuilt and copied to |
What this changes
The Android system media tile (lockscreen "Live notifications" + Quick-Settings media output) is rendered from the app's
MediaSession, not from anything in the app's own UI. The previous build ofLibravaultNotificationProviderhad two bugs that produced the reported symptoms:Player.COMMANDwas reported asisEnabled=false(which ExoPlayer does forCOMMAND_SEEK_FORWARDnear the end of an audiobook, and forCOMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMon a single-item playlist). Result:+seekandNextsilently vanished from the lockscreen tile.Rewrites
LibravaultNotificationProviderto publish a fixed 5-slot strip in positional order —Prev | −seek | PlayPause | +seek | Next— and return all five compact-view indices. Uses Media3's standardPlayer.COMMAND_*predefined commands so taps dispatch through the normal seek/transport path with no custom session-command plumbing.While here, wires the user's existing
defaultSkipDurationSecpreference (10/15/30/45/60 s chips in Settings → Playback → Skip duration, default 30 s) into the player and in-app ±seek buttons. The setting was already persisted and exposed in the UI but nothing read it.Files
libravault_prefsSharedPreferences file. Key constants must stay in sync withUserPreferencesRepository.PREFS_NAMEandKEY_SKIP_DURATION.setSeekBackIncrementMs/setSeekForwardIncrementMsnow seed from the user setting.Contextinjection;seekBack/seekForwardreplaced with an explicitseekTo(position ± skipMs)so the runtime preference is honored even though ExoPlayer's seek increment is immutable past build.Contextinjection; same change forseekBackAudiobook/seekForwardAudiobook.Scope of the skip-duration setting
seekTo).If true runtime-hot updates on the lockscreen tile are wanted, a follow-up would need to release/rebuild the ExoPlayer singleton (or rebuild the MediaSession) when the setting changes. Documented in the provider's KDoc.
Validation
./gradlew :feature:player:compileDebugKotlin— passes./gradlew :feature:library:compileDebugKotlin— passes./gradlew :feature:reader:compileDebugKotlin— passes./gradlew :app:assembleFdroidDebug— full debug APK builds