mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #2533 from Bnyro/master
Add shorts filter to the feed
This commit is contained in:
commit
28adf33cd1
@ -26,7 +26,8 @@ class SubscriptionsFragment : BaseFragment() {
|
|||||||
private val viewModel: SubscriptionsViewModel by activityViewModels()
|
private val viewModel: SubscriptionsViewModel by activityViewModels()
|
||||||
|
|
||||||
private var subscriptionAdapter: VideosAdapter? = null
|
private var subscriptionAdapter: VideosAdapter? = null
|
||||||
private var sortOrder = 0
|
private var selectedSortOrder = 0
|
||||||
|
private var selectedFilter = 0
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@ -82,7 +83,27 @@ class SubscriptionsFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.sortTV.setOnClickListener {
|
binding.sortTV.setOnClickListener {
|
||||||
showSortDialog()
|
val sortOptions = resources.getStringArray(R.array.sortOptions)
|
||||||
|
|
||||||
|
BaseBottomSheet().apply {
|
||||||
|
setSimpleItems(sortOptions.toList()) { index ->
|
||||||
|
binding.sortTV.text = sortOptions[index]
|
||||||
|
selectedSortOrder = index
|
||||||
|
showFeed()
|
||||||
|
}
|
||||||
|
}.show(childFragmentManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.filterTV.setOnClickListener {
|
||||||
|
val filterOptions = resources.getStringArray(R.array.filterOptions)
|
||||||
|
|
||||||
|
BaseBottomSheet().apply {
|
||||||
|
setSimpleItems(filterOptions.toList()) { index ->
|
||||||
|
binding.filterTV.text = filterOptions[index]
|
||||||
|
selectedFilter = index
|
||||||
|
showFeed()
|
||||||
|
}
|
||||||
|
}.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.toggleSubs.visibility = View.VISIBLE
|
binding.toggleSubs.visibility = View.VISIBLE
|
||||||
@ -117,27 +138,21 @@ class SubscriptionsFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortDialog() {
|
|
||||||
val sortOptions = resources.getStringArray(R.array.sortOptions)
|
|
||||||
|
|
||||||
val bottomSheet = BaseBottomSheet().apply {
|
|
||||||
setSimpleItems(sortOptions.toList()) { index ->
|
|
||||||
binding.sortTV.text = sortOptions[index]
|
|
||||||
sortOrder = index
|
|
||||||
showFeed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bottomSheet.show(childFragmentManager, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showFeed() {
|
private fun showFeed() {
|
||||||
if (viewModel.videoFeed.value == null) return
|
if (viewModel.videoFeed.value == null) return
|
||||||
|
|
||||||
binding.subRefresh.isRefreshing = false
|
binding.subRefresh.isRefreshing = false
|
||||||
val feed = viewModel.videoFeed.value!!
|
val feed = viewModel.videoFeed.value!!.filter {
|
||||||
|
// apply the selected filter
|
||||||
|
when (selectedFilter) {
|
||||||
|
0 -> true
|
||||||
|
1 -> !it.isShort
|
||||||
|
2 -> it.isShort
|
||||||
|
else -> throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
// sort the feed
|
// sort the feed
|
||||||
val sortedFeed = when (sortOrder) {
|
val sortedFeed = when (selectedSortOrder) {
|
||||||
0 -> feed
|
0 -> feed
|
||||||
1 -> feed.reversed()
|
1 -> feed.reversed()
|
||||||
2 -> feed.sortedBy { it.views }.reversed()
|
2 -> feed.sortedBy { it.views }.reversed()
|
||||||
@ -148,7 +163,7 @@ class SubscriptionsFragment : BaseFragment() {
|
|||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
|
|
||||||
// add an "all caught up item"
|
// add an "all caught up item"
|
||||||
if (sortOrder == 0) {
|
if (selectedSortOrder == 0) {
|
||||||
val lastCheckedFeedTime = PreferenceHelper.getLastCheckedFeedTime()
|
val lastCheckedFeedTime = PreferenceHelper.getLastCheckedFeedTime()
|
||||||
val caughtUpIndex = feed.indexOfFirst {
|
val caughtUpIndex = feed.indexOfFirst {
|
||||||
(it.uploaded ?: 0L) / 1000 < lastCheckedFeedTime
|
(it.uploaded ?: 0L) / 1000 < lastCheckedFeedTime
|
||||||
|
@ -114,18 +114,36 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="5dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/filterTV"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:drawablePadding="5dp"
|
||||||
|
android:paddingHorizontal="10dp"
|
||||||
|
android:text="@string/all"
|
||||||
|
android:textSize="16sp"
|
||||||
|
app:drawableEndCompat="@drawable/ic_filter" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/sortTV"
|
android:id="@+id/sortTV"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:layout_marginBottom="5dp"
|
|
||||||
android:drawablePadding="5dp"
|
android:drawablePadding="5dp"
|
||||||
android:paddingHorizontal="10dp"
|
android:paddingHorizontal="10dp"
|
||||||
android:text="@string/most_recent"
|
android:text="@string/most_recent"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
app:drawableEndCompat="@drawable/ic_arrow_downward" />
|
app:drawableEndCompat="@drawable/ic_arrow_downward" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -331,6 +331,12 @@
|
|||||||
<item>@string/channel_name_za</item>
|
<item>@string/channel_name_za</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="filterOptions">
|
||||||
|
<item>@string/all</item>
|
||||||
|
<item>@string/videos</item>
|
||||||
|
<item>@string/yt_shorts</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="requiredNetwork">
|
<string-array name="requiredNetwork">
|
||||||
<item>@string/network_all</item>
|
<item>@string/network_all</item>
|
||||||
<item>@string/network_wifi</item>
|
<item>@string/network_wifi</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user