Repository navigation
The Nine Lives widget: your rank, your current book and your next Lives on the home screen #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
50957fc
Home's rank card numbers come from one shared source, and Glance join…
StaticHumStudio a89509a
The Nine Lives widget knows what to show at every size, matching Home…
StaticHumStudio a390d55
The Nine Lives widget: your rank, your book with play and pause, and …
StaticHumStudio db37e5c
The Nine Lives widget redraws on play, pause, chapter and book change…
StaticHumStudio b38d7de
The Nine Lives picker preview loads (no plain View in a widget layout)
StaticHumStudio 454938e
A widget tap for a book opens that book, even when another book's pag…
StaticHumStudio a539c54
The Nine Lives widget fits a 2x2: cover and play on top, title below,…
StaticHumStudio 695f359
The large widget redraws when a book load ends, so a failed load no l…
StaticHumStudio 8df9be6
The large widget fills its space: rank at the top, Lives along the bo…
StaticHumStudio 3f9d7e5
A stale widget play button no longer pauses or resumes the new librar…
StaticHumStudio 397cc97
Pausing from the widget no longer waits on the server reachability check
StaticHumStudio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/ninelivesaudio/app/ui/home/ListeningTimeFormat.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.ninelivesaudio.app.ui.home | ||
|
|
||
| /* | ||
| * The altar card's numbers, shared by Home and the Nine Lives home screen | ||
| * widget so the two always say the same thing. | ||
| */ | ||
|
|
||
| /** How many recent books Home shows as Lives, and sums into "Total time given". */ | ||
| internal const val RECENT_LIVES_LIMIT = 9 | ||
|
|
||
| /** Formats seconds as compact listening time: "< 1m", "45m", "3h 22m". */ | ||
| internal fun formatListeningTime(totalSeconds: Double): String { | ||
| val totalMinutes = totalSeconds / 60.0 | ||
| if (totalMinutes < 1) return "< 1m" | ||
| val totalHours = totalSeconds / 3600.0 | ||
| if (totalHours < 1) return "${totalMinutes.toInt()}m" | ||
| val hours = totalHours.toInt() | ||
| val mins = ((totalSeconds % 3600) / 60).toInt() | ||
| return "${hours}h ${mins}m" | ||
| } | ||
|
|
||
| /** | ||
| * "Total time given": the saved positions of the recent Lives, added up. | ||
| * This is Home's long standing math, not lifetime listening. | ||
| */ | ||
| internal fun totalTimeGivenSeconds(currentTimesSeconds: List<Double>): Double = currentTimesSeconds.sum() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a streamed book is still playing or buffering after its server becomes unreachable, the new widget's pause tap calls
toggleOwned, which eagerly awaitsisPlayable(shown)beforetogglePlancan selectPAUSE. That check can wait up to eight seconds for a server probe, leaving audio playing despite the pause tap even though pausing requires no network access. After validating entitlement and the active library, select the pause action before performing the playability check; reserve that check for actions that actually need to load media.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 397cc97. Playability is now asked lazily, only when the tap would load a book. A pause while audio is playing or buffering returns PAUSE without the server probe. The test uses a probe that hangs if called.