mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-16 04:52:39 +02:00
Working watchlater sync
This commit is contained in:
@@ -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); }),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+1
-5
@@ -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}]")
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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}]");
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -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}]");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()))
|
||||
))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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 -> {
|
||||
|
||||
Reference in New Issue
Block a user