Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ interface MediaServiceRepository {
}

enum class TrendingCategory {
TRENDING,
GAMING,
PODCASTS,
TRAILERS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ class NewPipeMediaServiceRepository : MediaServiceRepository {

// see https://github.com/TeamNewPipe/NewPipeExtractor/tree/dev/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/kiosk
private val trendingCategories = mapOf(
TrendingCategory.TRENDING to "Trending",
TrendingCategory.GAMING to "trending_gaming",
TrendingCategory.TRAILERS to "trending_movies_and_shows",
TrendingCategory.PODCASTS to "trending_podcasts_episodes",
TrendingCategory.MUSIC to "trending_music",
TrendingCategory.LIVE to "live"
)
override fun getTrendingCategories(): List<TrendingCategory> = trendingCategories.keys.toList()
override fun getTrendingCategories(): List<TrendingCategory> =
trendingCategories.keys.toList()

override suspend fun getTrending(region: String, category: TrendingCategory): List<StreamItem> {
val kioskList = NewPipeExtractorInstance.extractor.kioskList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlinx.serialization.encodeToString
import retrofit2.HttpException

open class PipedMediaServiceRepository : MediaServiceRepository {
override fun getTrendingCategories(): List<TrendingCategory> = listOf(TrendingCategory.TRENDING)
override fun getTrendingCategories(): List<TrendingCategory> = emptyList()

override suspend fun getTrending(region: String, category: TrendingCategory): List<StreamItem> =
api.getTrending(region)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.github.libretube.LibreTubeApp
import com.github.libretube.R
import com.github.libretube.api.TrendingCategory
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.enums.SbSkipOptions
import com.github.libretube.helpers.LocaleHelper.getDetectedCountry
Expand Down Expand Up @@ -52,6 +53,10 @@ object PreferenceHelper {
}
}
},
PreferenceMigration(1, 2) {
// select a random category as the new value
putString(PreferenceKeys.TRENDING_CATEGORY, TrendingCategory.LIVE.name)
},
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class HomeFragment : Fragment(R.layout.fragment_home) {
binding.trendingCategory.setOnClickListener {
val currentTrendingCategoryPref = PreferenceHelper.getString(
PreferenceKeys.TRENDING_CATEGORY,
TrendingCategory.TRENDING.name
TrendingCategory.LIVE.name
).let { TrendingCategory.valueOf(it) }

val categories = trendingCategories.map { category ->
Expand Down Expand Up @@ -201,12 +201,13 @@ class HomeFragment : Fragment(R.layout.fragment_home) {
)
}

private fun showTrending(streamItems: List<StreamItem>?) {
if (streamItems == null) return
private fun showTrending(trends: Pair<TrendingCategory, List<StreamItem>>?) {
if (trends == null) return
val (category, streamItems) = trends

// cache the loaded trends in the [TrendsViewModel] so that the trends don't need to be
// reloaded there
trendsViewModel.setStreamsForCategory(TrendingCategory.TRENDING, streamItems)
trendsViewModel.setStreamsForCategory(category, streamItems)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related: I noticed we currently only set the first 10 trending streams to the view model (because showTrending only gets passed the 10 first items).

Ref: #7695

Copy link
Contributor

@dhanuarf dhanuarf Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for chiming in, I accidentally set the category to podcast, and my podcast is not showing (related: #7602). Since the returned StreamItems is null, this section is kept hidden. And the only way to change the category back is via trendingTV, and since it's hidden, I cant change it back.

Maybe kept trendingTV shown and put a placeholder in trendingRV when the returned list is empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, sounds like a good idea.


makeVisible(binding.trendingRV, binding.trendingTV)
trendingAdapter.submitList(streamItems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class TrendsFragment : Fragment(R.layout.fragment_trends) {

companion object {
val categoryNamesToStringRes = mapOf(
TrendingCategory.TRENDING to R.string.trends,
TrendingCategory.GAMING to R.string.gaming,
TrendingCategory.TRAILERS to R.string.trailers,
TrendingCategory.PODCASTS to R.string.podcasts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import kotlinx.coroutines.withContext
class HomeViewModel : ViewModel() {
private val hideWatched get() = PreferenceHelper.getBoolean(HIDE_WATCHED_FROM_FEED, false)

val trending: MutableLiveData<List<StreamItem>> = MutableLiveData(null)
val trending: MutableLiveData<Pair<TrendingCategory, List<StreamItem>>> = MutableLiveData(null)
val feed: MutableLiveData<List<StreamItem>> = MutableLiveData(null)
val bookmarks: MutableLiveData<List<PlaylistBookmark>> = MutableLiveData(null)
val playlists: MutableLiveData<List<Playlists>> = MutableLiveData(null)
Expand Down Expand Up @@ -62,7 +62,7 @@ class HomeViewModel : ViewModel() {
async { if (visibleItems.contains(PLAYLISTS)) loadPlaylists() },
async { if (visibleItems.contains(WATCHING)) loadVideosToContinueWatching() }
)
loadedSuccessfully.value = sections.any { !it.value.isNullOrEmpty() }
loadedSuccessfully.value = sections.any { it.isInitialized }
isLoading.value = false
}

Expand All @@ -78,11 +78,13 @@ class HomeViewModel : ViewModel() {
val region = PreferenceHelper.getTrendingRegion(context)
val category = PreferenceHelper.getString(
PreferenceKeys.TRENDING_CATEGORY,
TrendingCategory.TRENDING.name
TrendingCategory.LIVE.name
).let { TrendingCategory.valueOf(it) }

runSafely(
onSuccess = { videos -> trending.updateIfChanged(videos) },
onSuccess = { videos ->
trending.updateIfChanged(Pair(category, videos))
},
ioBlock = {
MediaServiceRepository.instance.getTrending(region, category).take(10).deArrow()
}
Expand Down
Loading