diff --git a/app/src/main/java/net/jeena/jtubetv/ui/screens/ChannelsScreen.kt b/app/src/main/java/net/jeena/jtubetv/ui/screens/ChannelsScreen.kt index 2b5c424..1de2c73 100644 --- a/app/src/main/java/net/jeena/jtubetv/ui/screens/ChannelsScreen.kt +++ b/app/src/main/java/net/jeena/jtubetv/ui/screens/ChannelsScreen.kt @@ -76,8 +76,7 @@ import net.jeena.jtubetv.ui.screens.list.dpadCenterActivatable * Channels, SmartTube-style: one row per LOCAL user. * * - Row 1: the logged-in user ("'s Channels") — only when they own - * at least one channel WITH videos; then the other local users, rows and - * channels alike sorted by subscribers / videos / views (desc). + * at least one channel WITH videos; then the other local users by total videos. * - Channels with no videos never render (watching-only accounts), at any level. * - Followed-instance channels at the end, grouped per platform. * @@ -281,10 +280,13 @@ class ChannelsViewModel(private val store: TokenStore) : ViewModel() { val byOwner = locals.groupBy { ownerKey(it) } val groups = byOwner.values.map { row -> val sorted = row.sortedWith( - // One ordering everywhere: subscribers, videos, views (desc). - compareByDescending { it.followersCount } - .thenByDescending { statOf(it) } - .thenByDescending { playsOf(it) }, + // Stable keys only: all of these come from the video listing and + // never change mid-load — subscriber counts arrive later per- + // channel and must not reorder anything while loading (rows that + // jump while stats stream in read as broken). + compareByDescending { statOf(it) } + .thenByDescending { playsOf(it) } + .thenByDescending { it.followersCount }, ) val own = row.firstOrNull { it.name in ownNames } UserGroup( @@ -296,9 +298,9 @@ class ChannelsViewModel(private val store: TokenStore) : ViewModel() { } userRows = groups.sortedWith( compareByDescending { g -> g.channels.any { it.name in ownNames } } - .thenByDescending { g -> g.channels.sumOf { it.followersCount } } .thenByDescending { g -> g.channels.sumOf { statsMap[it.name + "@" + it.host]?.videos ?: 0 } } - .thenByDescending { g -> g.channels.sumOf { statsMap[it.name + "@" + it.host]?.plays ?: 0 } }, + .thenByDescending { g -> g.channels.sumOf { statsMap[it.name + "@" + it.host]?.plays ?: 0 } } + .thenByDescending { g -> g.channels.sumOf { it.followersCount } }, ) Log.w( "JTube",