Skip to content

fix tv provider sync and sorting - #2129

Open
BastianLo wants to merge 3 commits into
damontecres:mainfrom
BastianLo:main
Open

BastianLo wants to merge 3 commits into
damontecres:mainfrom
BastianLo:main

Conversation

@BastianLo

Copy link
Copy Markdown

Description

Currently there is only a "add" and "remove" operation in the TvProviderWorker.
This PR adds a "update" functionality, which rewrites the playback entry on every sync. This makes sure that the displayed progress the tv provider (in my case projectivy) stays consistent with the actual progress in wholphin/jellyfin.
Also the items are grouped by the internalProviderId. This fixes the issue of duplicate entries in the tv provider.

Lastly the sorting by datetime was fixed.
setLastEngagementTimeUtcMillis requires milis, but seconds were provided.

Related issues

#2128

Testing

Testing was done with the following setting:

TCL C7K, Google TV / Android 14, armeabi-v7a, Jellyfin 12.2.0
TvProvider: Projectivy Launcher

I have done manual testing for this PR by installing a release build with R8/minify. I added/removed and changed the progress of the watched items to check if they were correctly displayed. All previous problems were fixed and the progress in the tv provider is now correctly synced and equal to the items in the app.

Screenshots

/

AI or LLM usage

The code written in this PR is by AI.
The changes were tested manually by me, like written in the testing-chapter

BastianLo and others added 3 commits October 25, 2026 17:06
TvProviderWorker only ever deleted rows that left resume/next up and
inserted rows for items that had none. Rows that already existed were
skipped, so everything they carry - playback position, title, artwork,
description - stayed frozen at whatever it was when the row was first
created, since convert() only ran for new items.

Split the items the server still wants shown into toAdd and toUpdate,
and write the current values onto the existing rows via
ContentResolver.update().

While grouping the existing rows by internalProviderId, also collapse
duplicates: nothing else ever removed them. Two rows sharing one item id
are both considered valid by the delete pass and both suppress the
insert, so once a duplicate existed it survived every sync forever.
Keep the first row and delete the rest.
Launchers order the watch next row by LAST_ENGAGEMENT_TIME_UTC_MILLIS,
and convert() computed that field itself instead of reusing what the row
was already sorted by. Two things went wrong with it:

  setLastEngagementTimeUtcMillis(
      dto.userData?.lastPlayedDate?.atZone(...)?.toEpochSecond()
          ?: Date().time,
  )

toEpochSecond() returns seconds where the field expects milliseconds, so
every played item collapsed into early 1970. Items without a last played
date - every next up episode that was never started - fell through to
Date().time and were stamped with "now", which put them ahead of
everything the user had actually been watching.

buildCombined() already resolves the right timestamp for each item: the
item's own last played date for resume items, the series' last played
date (via DatePlayedService) for next up items, and sorts by it. Add
buildCombinedWithLastPlayed() which returns those timestamps alongside
the items, and have buildCombined() delegate to it, so existing callers
are unaffected. TvProviderWorker passes the timestamp into convert() and
writes it as epoch millis.

Unknown timestamps now sort last (0L) rather than first, matching what
sortedByDescending does with them in the app.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant