From 5a6a13cd5e3470ec2f4295d71767d9ea273f6f76 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 29 Jan 2025 16:07:24 +0100 Subject: [PATCH] fix: add offline played videos to watch history too --- .../libretube/services/OfflinePlayerService.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt index ca5d4472a..62a18d260 100644 --- a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt @@ -47,6 +47,15 @@ open class OfflinePlayerService : AbstractPlayerService() { if (playbackState == Player.STATE_ENDED && PlayerHelper.isAutoPlayEnabled()) { playNextVideo(PlayingQueue.getNext() ?: return) } + + if (playbackState == Player.STATE_READY) { + scope.launch(Dispatchers.IO) { + val watchHistoryItem = downloadWithItems?.download?.toStreamItem()?.toWatchHistoryItem(videoId) + if (watchHistoryItem != null) { + DatabaseHelper.addToWatchHistory(watchHistoryItem) + } + } + } } } @@ -95,7 +104,11 @@ open class OfflinePlayerService : AbstractPlayerService() { if (watchPositionsEnabled) { DatabaseHelper.getWatchPosition(videoId)?.let { - if (!DatabaseHelper.isVideoWatched(it, downloadWithItems.download.duration)) exoPlayer?.seekTo(it) + if (!DatabaseHelper.isVideoWatched( + it, + downloadWithItems.download.duration + ) + ) exoPlayer?.seekTo(it) } } }