From 0fc966a77d79b23641ab4304fcd1ba42c211d444 Mon Sep 17 00:00:00 2001
From: Kelvin <kelvin@futo.org>
Date: Wed, 14 Feb 2024 19:18:35 +0100
Subject: [PATCH] Subscription watched filter

---
 .../mainactivity/main/SubscriptionsFeedFragment.kt        | 8 +++++++-
 .../java/com/futo/platformplayer/states/StateHistory.kt   | 3 +++
 app/src/main/res/values/strings.xml                       | 1 +
 app/src/unstable/assets/sources/youtube                   | 2 +-
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt
index 76c60e1f..3099638f 100644
--- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt
+++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt
@@ -25,6 +25,7 @@ import com.futo.platformplayer.models.SearchType
 import com.futo.platformplayer.models.SubscriptionGroup
 import com.futo.platformplayer.states.StateApp
 import com.futo.platformplayer.states.StateCache
+import com.futo.platformplayer.states.StateHistory
 import com.futo.platformplayer.states.StatePlatform
 import com.futo.platformplayer.states.StateSubscriptions
 import com.futo.platformplayer.stores.FragmentedStorage
@@ -197,6 +198,7 @@ class SubscriptionsFeedFragment : MainFragment() {
             val allowContentTypes: MutableList<ContentType> = mutableListOf(ContentType.MEDIA, ContentType.POST);
             var allowLive: Boolean = true;
             var allowPlanned: Boolean = false;
+            var allowWatched: Boolean = true;
             override fun encode(): String {
                 return Json.encodeToString(this);
             }
@@ -304,7 +306,8 @@ class SubscriptionsFeedFragment : MainFragment() {
                     SubscriptionBar.Toggle(context.getString(R.string.videos), _filterSettings.allowContentTypes.contains(ContentType.MEDIA)) { toggleFilterContentTypes(listOf(ContentType.MEDIA, ContentType.NESTED_VIDEO), it);  },
                     SubscriptionBar.Toggle(context.getString(R.string.posts),  _filterSettings.allowContentTypes.contains(ContentType.POST)) { toggleFilterContentType(ContentType.POST, it); },
                     SubscriptionBar.Toggle(context.getString(R.string.live), _filterSettings.allowLive) { _filterSettings.allowLive = it; _filterSettings.save(); loadResults(false); },
-                    SubscriptionBar.Toggle(context.getString(R.string.planned), _filterSettings.allowPlanned) { _filterSettings.allowPlanned = it; _filterSettings.save(); loadResults(false); }
+                    SubscriptionBar.Toggle(context.getString(R.string.planned), _filterSettings.allowPlanned) { _filterSettings.allowPlanned = it; _filterSettings.save(); loadResults(false); },
+                    SubscriptionBar.Toggle(context.getString(R.string.watched), _filterSettings.allowWatched) { _filterSettings.allowWatched = it; _filterSettings.save(); loadResults(false); }
                 );
             }
 
@@ -336,6 +339,9 @@ class SubscriptionsFeedFragment : MainFragment() {
             return results.filter {
                 val allowedContentType = _filterSettings.allowContentTypes.contains(if(it.contentType == ContentType.NESTED_VIDEO || it.contentType == ContentType.LOCKED) ContentType.MEDIA else it.contentType);
 
+                if(it is IPlatformVideo && it.duration > 0 && !_filterSettings.allowWatched && StateHistory.instance.isHistoryWatched(it.url, it.duration))
+                    return@filter false;
+
                 //TODO: Check against a sub cache
                 if(filterGroup != null && !filterGroup.urls.contains(it.author.url))
                     return@filter false;
diff --git a/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt b/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt
index 9f9ef81f..d61b8ab3 100644
--- a/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt
+++ b/app/src/main/java/com/futo/platformplayer/states/StateHistory.kt
@@ -50,6 +50,9 @@ class StateHistory {
     fun getHistoryPosition(url: String): Long {
         return historyIndex[url]?.position ?: 0;
     }
+    fun isHistoryWatched(url: String, duration: Long): Boolean {
+        return getHistoryPosition(url) > duration * 0.7;
+    }
 
 
     fun updateHistoryPosition(liveObj: IPlatformVideo, index: DBHistory.Index, updateExisting: Boolean, position: Long = -1L): Long {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 274feb82..5dc24aef 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -625,6 +625,7 @@
     <string name="you_have_too_many_subscriptions_for_the_following_plugins">\n\nYou have too many subscriptions for the following plugins:\n</string>
     <string name="posts">Posts</string>
     <string name="planned">Planned</string>
+    <string name="watched">Watched</string>
     <string name="no_results_found_swipe_down_to_refresh">No results found\nSwipe down to refresh</string>
     <string name="overlay">Overlay</string>
     <string name="reload">Reload</string>
diff --git a/app/src/unstable/assets/sources/youtube b/app/src/unstable/assets/sources/youtube
index c86c73db..83cccf8b 160000
--- a/app/src/unstable/assets/sources/youtube
+++ b/app/src/unstable/assets/sources/youtube
@@ -1 +1 @@
-Subproject commit c86c73db0cdde3371c7944dd82c34ea4e5c725d9
+Subproject commit 83cccf8ba5ae87d8a437775d9b341a9e3be07e74
-- 
GitLab