diff --git a/app/src/main/java/com/futo/platformplayer/Settings.kt b/app/src/main/java/com/futo/platformplayer/Settings.kt index 916594e9..d9a6e459 100644 --- a/app/src/main/java/com/futo/platformplayer/Settings.kt +++ b/app/src/main/java/com/futo/platformplayer/Settings.kt @@ -505,6 +505,9 @@ class Settings : FragmentedStorageFileJson() { @FormField(R.string.autoplay, FieldForm.TOGGLE, R.string.autoplay, 21) var autoplay: Boolean = false; + + @FormField(R.string.delete_watchlist_on_finish, FieldForm.TOGGLE, R.string.delete_watchlist_on_finish_description, 22) + var deleteFromWatchLaterAuto: Boolean = true; } @FormField(R.string.comments, "group", R.string.comments_description, 6) diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt index 9c926575..7ab6dd25 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt @@ -735,6 +735,7 @@ class VideoDetailView : ConstraintLayout { }; onClose.subscribe { + checkAndRemoveWatchLater(); _lastVideoSource = null; _lastAudioSource = null; _lastSubtitleSource = null; @@ -1834,6 +1835,8 @@ class VideoDetailView : ConstraintLayout { fun prevVideo(withoutRemoval: Boolean = false) { Logger.i(TAG, "prevVideo") + checkAndRemoveWatchLater(); + val next = StatePlayer.instance.prevQueueItem(withoutRemoval || _player.duration < 100 || (_player.position.toFloat() / _player.duration) < 0.9); if(next != null) { setVideoOverview(next, true, 0, true); @@ -1842,6 +1845,8 @@ class VideoDetailView : ConstraintLayout { fun nextVideo(forceLoop: Boolean = false, withoutRemoval: Boolean = false, bypassVideoLoop: Boolean = false): Boolean { Logger.i(TAG, "nextVideo") + checkAndRemoveWatchLater(); + var next = StatePlayer.instance.nextQueueItem(withoutRemoval || _player.duration < 100 || (_player.position.toFloat() / _player.duration) < 0.9, bypassVideoLoop); val autoplayVideo = _autoplayVideo if (next == null && autoplayVideo != null && StatePlayer.instance.autoplay) { @@ -1850,7 +1855,8 @@ class VideoDetailView : ConstraintLayout { next = autoplayVideo } _autoplayVideo = null - Logger.i(TAG, "Autoplay video cleared (nextVideo)") + Logger.i(TAG, "Autoplay video cleared (nextVideo)"); + if(next == null && forceLoop) next = StatePlayer.instance.restartQueue(); if(next != null) { @@ -1862,6 +1868,20 @@ class VideoDetailView : ConstraintLayout { return false; } + fun checkAndRemoveWatchLater(){ + val watchCurrent = video ?: videoLocal ?: _searchVideo; + if(Settings.instance.playback.deleteFromWatchLaterAuto) { + if(watchCurrent?.duration != null && + watchCurrent.duration > 0 && + (lastPositionMilliseconds / 1000) > watchCurrent.duration * 0.7) { + if(!watchCurrent.url.isNullOrEmpty()) { + StatePlaylists.instance.removeFromWatchLater(watchCurrent.url); + } + } + } + } + + //Quality Selector data private fun updateQualityFormatsOverlay(liveStreamVideoFormats : List?, liveStreamAudioFormats : List?) { val v = video ?: return; diff --git a/app/src/main/java/com/futo/platformplayer/states/StatePlaylists.kt b/app/src/main/java/com/futo/platformplayer/states/StatePlaylists.kt index b5ed8ea4..2826cb91 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StatePlaylists.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StatePlaylists.kt @@ -90,6 +90,18 @@ class StatePlaylists { StateDownloads.instance.checkForOutdatedPlaylistVideos(VideoDownload.GROUP_WATCHLATER); } } + fun getWatchLaterFromUrl(url: String): SerializedPlatformVideo?{ + synchronized(_watchlistStore) { + val order = _watchlistOrderStore.getAllValues(); + return _watchlistStore.getItems().firstOrNull { it.url == url }; + } + } + fun removeFromWatchLater(url: String) { + val item = getWatchLaterFromUrl(url); + if(item != null){ + removeFromWatchLater(item); + } + } fun removeFromWatchLater(video: SerializedPlatformVideo) { synchronized(_watchlistStore) { _watchlistStore.delete(video); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 886dc80a..32015d9f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -399,6 +399,8 @@ Allow video to go underneath the screen cutout in full-screen.\nMay require restart Enable autoplay by default Autoplay will be enabled by default whenever you watch a video + Delete from WatchLater when watched + After you leave a video that you mostly watched, it will be removed from watch later. Allow fullscreen portrait Switch to Audio in Background Optimize bandwidth usage by switching to audio-only stream in background if available, may cause stutter