Merge pull request #4950 from Bnyro/master

feat: hide watched videos from featured in homepage when enabled
This commit is contained in:
Bnyro 2023-10-11 09:17:14 +02:00 committed by GitHub
commit 51be2dfc9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
class HomeFragment : Fragment() { class HomeFragment : Fragment() {
@ -143,13 +144,17 @@ class HomeFragment : Fragment() {
SubscriptionHelper.getFeed() SubscriptionHelper.getFeed()
} }
}.getOrNull()?.takeIf { it.isNotEmpty() } ?: return }.getOrNull()?.takeIf { it.isNotEmpty() } ?: return
}.filter { }
var filteredFeed = feed.filter {
when (PreferenceHelper.getInt(PreferenceKeys.SELECTED_FEED_FILTER, 0)) { when (PreferenceHelper.getInt(PreferenceKeys.SELECTED_FEED_FILTER, 0)) {
1 -> !it.isShort 1 -> !it.isShort
2 -> it.isShort 2 -> it.isShort
else -> true else -> true
} }
}.take(20) }
if (PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) {
filteredFeed = runBlocking { DatabaseHelper.filterUnwatched(filteredFeed) }
}
val binding = _binding ?: return val binding = _binding ?: return
makeVisible(binding.featuredRV, binding.featuredTV) makeVisible(binding.featuredRV, binding.featuredTV)
@ -159,7 +164,7 @@ class HomeFragment : Fragment() {
false false
) )
binding.featuredRV.adapter = VideosAdapter( binding.featuredRV.adapter = VideosAdapter(
feed.toMutableList(), filteredFeed.take(20).toMutableList(),
forceMode = VideosAdapter.Companion.ForceMode.HOME forceMode = VideosAdapter.Companion.ForceMode.HOME
) )
} }