Working watchlater sync

This commit is contained in:
Kelvin 2024-11-22 21:51:06 +01:00
parent e989590c08
commit 102e2c54bb
7 changed files with 19 additions and 17 deletions

View file

@ -959,7 +959,7 @@ class UISlideOverlays {
"${container.context.getString(R.string.add_to)} " + StatePlayer.TYPE_WATCHLATER + "",
"${watchLater.size} " + container.context.getString(R.string.videos),
tag = "watch later",
call = { StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(video)); }),
call = { StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(video), true); }),
SlideUpMenuItem(container.context,
R.drawable.ic_history,
container.context.getString(R.string.add_to_history),
@ -1040,7 +1040,7 @@ class UISlideOverlays {
StatePlayer.TYPE_WATCHLATER,
"${watchLater.size} " + container.context.getString(R.string.videos),
tag = "watch later",
call = { StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(video)); }),
call = { StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(video), true); }),
)
);

View file

@ -237,11 +237,7 @@ class ChannelFragment : MainFragment() {
}
adapter.onAddToWatchLaterClicked.subscribe { content ->
if (content is IPlatformVideo) {
StatePlaylists.instance.addToWatchLater(
SerializedPlatformVideo.fromVideo(
content
)
)
StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(content), true)
UIDialogs.toast("Added to watch later\n[${content.name}]")
}
}

View file

@ -89,7 +89,7 @@ abstract class ContentFeedView<TFragment> : FeedView<TFragment, IPlatformContent
};
adapter.onAddToWatchLaterClicked.subscribe(this) {
if(it is IPlatformVideo) {
StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(it));
StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(it), true);
UIDialogs.toast("Added to watch later\n[${it.name}]");
}
};

View file

@ -2480,7 +2480,7 @@ class VideoDetailView : ConstraintLayout {
onAddToWatchLaterClicked.subscribe(this) {
if(it is IPlatformVideo) {
StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(it));
StatePlaylists.instance.addToWatchLater(SerializedPlatformVideo.fromVideo(it), true);
UIDialogs.toast("Added to watch later\n[${it.name}]");
}
}

View file

@ -100,7 +100,7 @@ class WatchLaterFragment : MainFragment() {
}
override fun onVideoRemoved(video: IPlatformVideo) {
if (video is SerializedPlatformVideo) {
StatePlaylists.instance.removeFromWatchLater(video);
StatePlaylists.instance.removeFromWatchLater(video, true);
}
}

View file

@ -87,15 +87,19 @@ class StatePlaylists {
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(tryParse), ZoneOffset.UTC);
}
private fun setWatchLaterReorderTime() {
val now = OffsetDateTime.now().toEpochSecond();
_watchLaterReorderTime.setAndSave(now.toString());
val now = OffsetDateTime.now(ZoneOffset.UTC);
val nowEpoch = now.toEpochSecond();
_watchLaterReorderTime.setAndSave(nowEpoch.toString());
}
fun getWatchLaterOrdering() = _watchlistOrderStore.getAllValues().toList();
fun updateWatchLaterOrdering(order: List<String>) {
fun updateWatchLaterOrdering(order: List<String>, notify: Boolean = false) {
_watchlistOrderStore.set(*smartMerge(order, getWatchLaterOrdering()).toTypedArray());
_watchlistOrderStore.save();
if(notify) {
onWatchLaterChanged.emit();
}
}
fun toMigrateCheck(): List<ManagedStore<*>> {
@ -245,8 +249,8 @@ class StatePlaylists {
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
StateSync.instance.broadcastJsonData(GJSyncOpcodes.syncWatchLater, SyncWatchLaterPackage(
listOf(),
mapOf(Pair(url, time.toEpochSecond())),
mapOf()
mapOf(),
mapOf(Pair(url, time.toEpochSecond()))
))
};
}

View file

@ -330,8 +330,10 @@ class SyncSession : IAuthorizable {
}
val packReorderTime = OffsetDateTime.ofInstant(Instant.ofEpochSecond(pack.reorderTime), ZoneOffset.UTC);
if(StatePlaylists.instance.getWatchLaterLastReorderTime() < packReorderTime && pack.ordering != null)
StatePlaylists.instance.updateWatchLaterOrdering(smartMerge(pack.ordering!!, StatePlaylists.instance.getWatchLaterOrdering()));
val localReorderTime = StatePlaylists.instance.getWatchLaterLastReorderTime();
if(localReorderTime < packReorderTime && pack.ordering != null) {
StatePlaylists.instance.updateWatchLaterOrdering(smartMerge(pack.ordering!!, StatePlaylists.instance.getWatchLaterOrdering()), true);
}
}
GJSyncOpcodes.syncHistory -> {