mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #2914 from Isira-Seneviratne/take
Use take() extension.
This commit is contained in:
commit
a293480bac
@ -1,5 +0,0 @@
|
|||||||
package com.github.libretube.ui.extensions
|
|
||||||
|
|
||||||
fun <T> List<T>.withMaxSize(maxSize: Int): List<T> {
|
|
||||||
return this.filterIndexed { index, _ -> index < maxSize }
|
|
||||||
}
|
|
@ -22,7 +22,6 @@ import com.github.libretube.ui.adapters.PlaylistBookmarkAdapter
|
|||||||
import com.github.libretube.ui.adapters.PlaylistsAdapter
|
import com.github.libretube.ui.adapters.PlaylistsAdapter
|
||||||
import com.github.libretube.ui.adapters.VideosAdapter
|
import com.github.libretube.ui.adapters.VideosAdapter
|
||||||
import com.github.libretube.ui.base.BaseFragment
|
import com.github.libretube.ui.base.BaseFragment
|
||||||
import com.github.libretube.ui.extensions.withMaxSize
|
|
||||||
import com.github.libretube.util.LocaleHelper
|
import com.github.libretube.util.LocaleHelper
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -73,7 +72,7 @@ class HomeFragment : BaseFragment() {
|
|||||||
|
|
||||||
private suspend fun fetchHome() {
|
private suspend fun fetchHome() {
|
||||||
runOrError {
|
runOrError {
|
||||||
val feed = SubscriptionHelper.getFeed().withMaxSize(20)
|
val feed = SubscriptionHelper.getFeed().take(20)
|
||||||
if (feed.isEmpty()) return@runOrError
|
if (feed.isEmpty()) return@runOrError
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
makeVisible(binding.featuredRV, binding.featuredTV)
|
makeVisible(binding.featuredRV, binding.featuredTV)
|
||||||
@ -90,9 +89,8 @@ class HomeFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runOrError {
|
runOrError {
|
||||||
val trending = RetrofitInstance.api.getTrending(
|
val region = LocaleHelper.getTrendingRegion(requireContext())
|
||||||
LocaleHelper.getTrendingRegion(requireContext())
|
val trending = RetrofitInstance.api.getTrending(region).take(10)
|
||||||
).withMaxSize(10)
|
|
||||||
if (trending.isEmpty()) return@runOrError
|
if (trending.isEmpty()) return@runOrError
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
makeVisible(binding.trendingRV, binding.trendingTV)
|
makeVisible(binding.trendingRV, binding.trendingTV)
|
||||||
@ -105,7 +103,7 @@ class HomeFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runOrError {
|
runOrError {
|
||||||
val playlists = PlaylistsHelper.getPlaylists().withMaxSize(20)
|
val playlists = PlaylistsHelper.getPlaylists().take(20)
|
||||||
if (playlists.isEmpty()) return@runOrError
|
if (playlists.isEmpty()) return@runOrError
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
makeVisible(binding.playlistsRV, binding.playlistsTV)
|
makeVisible(binding.playlistsRV, binding.playlistsTV)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user