mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #5772 from Bnyro/master
fix: respect feed filter on home tab
This commit is contained in:
commit
30a8166b49
@ -6,9 +6,11 @@ import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.db.DatabaseHolder.Database
|
||||
import com.github.libretube.db.obj.SearchHistoryItem
|
||||
import com.github.libretube.db.obj.WatchHistoryItem
|
||||
import com.github.libretube.enums.ContentFilter
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.TimeZone
|
||||
@ -92,4 +94,25 @@ object DatabaseHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun filterByStatusAndWatchPosition(streams: List<StreamItem>, hideWatched: Boolean): List<StreamItem> {
|
||||
val streamItems = streams.filter {
|
||||
val isVideo = !it.isShort && !it.isLive
|
||||
|
||||
return@filter when {
|
||||
!ContentFilter.SHORTS.isEnabled && it.isShort -> false
|
||||
!ContentFilter.VIDEOS.isEnabled && isVideo -> false
|
||||
!ContentFilter.LIVESTREAMS.isEnabled && it.isLive -> false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
return if (hideWatched) {
|
||||
runBlocking {
|
||||
filterUnwatched(streamItems)
|
||||
}
|
||||
} else {
|
||||
streamItems
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,10 @@ import com.github.libretube.R
|
||||
import com.github.libretube.api.PlaylistsHelper
|
||||
import com.github.libretube.api.obj.Playlists
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.constants.PreferenceKeys.HOME_TAB_CONTENT
|
||||
import com.github.libretube.databinding.FragmentHomeBinding
|
||||
import com.github.libretube.db.DatabaseHelper
|
||||
import com.github.libretube.db.obj.PlaylistBookmark
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.ui.activities.SettingsActivity
|
||||
@ -154,7 +156,12 @@ class HomeFragment : Fragment() {
|
||||
if (streamItems == null) return
|
||||
|
||||
makeVisible(binding.featuredRV, binding.featuredTV)
|
||||
val feedVideos = streamItems.take(20).toMutableList()
|
||||
val hideWatched = PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)
|
||||
val feedVideos = streamItems
|
||||
.let { DatabaseHelper.filterByStatusAndWatchPosition(it, hideWatched) }
|
||||
.take(20)
|
||||
.toMutableList()
|
||||
|
||||
with(binding.featuredRV) {
|
||||
layoutManager = LinearLayoutManager(context, HORIZONTAL, false)
|
||||
adapter = VideosAdapter(feedVideos, forceMode = LayoutMode.RELATED_COLUMN)
|
||||
|
@ -24,7 +24,6 @@ import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.FragmentSubscriptionsBinding
|
||||
import com.github.libretube.db.DatabaseHelper
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.enums.ContentFilter
|
||||
import com.github.libretube.extensions.dpToPx
|
||||
import com.github.libretube.extensions.formatShort
|
||||
import com.github.libretube.extensions.toID
|
||||
@ -46,7 +45,6 @@ import com.github.libretube.util.PlayingQueue
|
||||
import com.google.android.material.chip.Chip
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
private var _binding: FragmentSubscriptionsBinding? = null
|
||||
@ -226,7 +224,7 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
private fun playByGroup(groupIndex: Int) {
|
||||
val streams = viewModel.videoFeed.value.orEmpty()
|
||||
.filterByGroup(groupIndex)
|
||||
.filterByStatusAndWatchPosition()
|
||||
.let { DatabaseHelper.filterByStatusAndWatchPosition(it, hideWatched) }
|
||||
.sortedBySelectedOrder()
|
||||
|
||||
if (streams.isEmpty()) return
|
||||
@ -291,27 +289,6 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
return filter { group?.channels?.contains(it.url.toID()) != false }
|
||||
}
|
||||
|
||||
private fun List<StreamItem>.filterByStatusAndWatchPosition(): List<StreamItem> {
|
||||
val streamItems = this.filter {
|
||||
val isVideo = !it.isShort && !it.isLive
|
||||
|
||||
return@filter when {
|
||||
!ContentFilter.SHORTS.isEnabled && it.isShort -> false
|
||||
!ContentFilter.VIDEOS.isEnabled && isVideo -> false
|
||||
!ContentFilter.LIVESTREAMS.isEnabled && it.isLive -> false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
return if (hideWatched) {
|
||||
runBlocking {
|
||||
DatabaseHelper.filterUnwatched(streamItems)
|
||||
}
|
||||
} else {
|
||||
streamItems
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<StreamItem>.sortedBySelectedOrder() = when (selectedSortOrder) {
|
||||
0 -> this
|
||||
1 -> this.reversed()
|
||||
@ -328,7 +305,9 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
binding.subRefresh.isRefreshing = false
|
||||
val feed = videoFeed
|
||||
.filterByGroup(selectedFilterGroup)
|
||||
.filterByStatusAndWatchPosition()
|
||||
.let {
|
||||
DatabaseHelper.filterByStatusAndWatchPosition(it, hideWatched)
|
||||
}
|
||||
|
||||
val sortedFeed = feed
|
||||
.sortedBySelectedOrder()
|
||||
|
Loading…
x
Reference in New Issue
Block a user