-
Notifications
You must be signed in to change notification settings - Fork 153
fix(playlist): make catalogue refresh reachable, and stop it wiping watch history #415
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
Open
Pierroons
wants to merge
4
commits into
oxyroid:master
Choose a base branch
from
Pierroons:fix/unreachable-refresh
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ac66d8c
fix(ui): surface screen actions the top bar never renders
Pierroons b866337
fix(playlist): keep watch history and favourites across a refresh
Pierroons 1702e80
feat(foryou): refresh every playlist from the home screen
Pierroons 8580bb8
refactor(ui): take the actions as a parameter instead of reading Meta…
Pierroons 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| /build | ||
| /src/test |
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
59 changes: 59 additions & 0 deletions
59
data/src/main/java/com/m3u/data/database/model/ChannelUserState.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,59 @@ | ||
| package com.m3u.data.database.model | ||
|
|
||
| import androidx.room.ColumnInfo | ||
|
|
||
| /** | ||
| * What a viewer built up on a channel, as opposed to what the provider says | ||
| * about it. | ||
| * | ||
| * Refreshing a catalogue deletes every channel and imports them anew, so rows | ||
| * come back with their id regenerated and these columns reset — the Continue | ||
| * watching row empties, favourites are lost. Carried across the import, none of | ||
| * that is. | ||
| */ | ||
| data class ChannelUserState( | ||
| /** Stable across imports when the provider gives one; M3U often does not. */ | ||
| @ColumnInfo(name = "relation_id") | ||
| val relationId: String?, | ||
| @ColumnInfo(name = "url") | ||
| val url: String, | ||
| @ColumnInfo(name = "seen") | ||
| val seen: Long, | ||
| @ColumnInfo(name = "favourite") | ||
| val favourite: Boolean, | ||
| @ColumnInfo(name = "hidden") | ||
| val hidden: Boolean, | ||
| ) | ||
|
|
||
| /** | ||
| * Looks a channel up by whichever identity survived the import. | ||
| * | ||
| * Xtream channels keep a relation id; an M3U playlist without tvg-id has none, | ||
| * and only its URL to go on. Falling back to the URL keeps both kinds covered | ||
| * without the callers having to know which is which. | ||
| */ | ||
| class PreservedUserStates(states: List<ChannelUserState>) { | ||
| private val byRelationId: Map<String, ChannelUserState> = states | ||
| .mapNotNull { state -> | ||
| state.relationId?.takeIf(String::isNotBlank)?.let { id -> id to state } | ||
| } | ||
| .toMap() | ||
|
|
||
| private val byUrl: Map<String, ChannelUserState> = states.associateBy(ChannelUserState::url) | ||
|
|
||
| val isEmpty: Boolean get() = byRelationId.isEmpty() && byUrl.isEmpty() | ||
|
|
||
| fun of(relationId: String?, url: String): ChannelUserState? = | ||
| relationId?.takeIf(String::isNotBlank)?.let(byRelationId::get) ?: byUrl[url] | ||
| } | ||
|
|
||
| /** | ||
| * Hands a freshly imported channel back what its predecessor had earned. | ||
| * | ||
| * Returns the channel untouched when nothing was preserved for it, which is the | ||
| * case for all but a handful of a catalogue. | ||
| */ | ||
| fun Channel.restoring(states: PreservedUserStates?, relationId: String?): Channel { | ||
| val state = states?.of(relationId ?: this.relationId, url) ?: return this | ||
| return copy(seen = state.seen, favourite = state.favourite, hidden = state.hidden) | ||
| } |
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.
Maybe it would be better to do these in a single database transaction?
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.
Good question, but I don't think there's anything to wrap here — please tell me if I misread you.
The loop doesn't write to the database.
PlaylistRepository.refreshenqueues aSubscriptionWorkerper playlist and returns; the only read is the initialgetAll(). A transaction would enclose no writes, and holding one open acrossenqueuecalls would keep it open for the WorkManager round-trips.If your concern was that a playlist added while the loop runs could be missed — that's real, and a snapshot read would fix it. Happy to do that if it's what you had in mind.