@@ -263,7 +263,7 @@ class SKTech : MainAPI() {
263263 }
264264 }
265265
266- // Group by sport for sport rows (show both live and upcoming events)
266+ // Group by sport — use trimmed category to avoid trailing-space duplicates
267267 val sport = ev.category.trim()
268268 if (sport.isNotEmpty() && isSportEnabled(sport)) {
269269 if (evMs >= now - 4 * 3600_000L ) { // Live or upcoming
@@ -277,12 +277,14 @@ class SKTech : MainAPI() {
277277 lists.add(HomePageList (" 🔴 LIVE NOW" , live, isHorizontalImages = true ))
278278 }
279279
280- // Sport sections sorted by name
281- byCategory.entries.sortedBy { it.key }.forEach { (sport, items) ->
282- if (items.isNotEmpty()) {
283- lists.add(HomePageList (sport, items.take(20 ), isHorizontalImages = true ))
280+ // Sport sections sorted by event count (most events first), then alphabetically
281+ byCategory.entries
282+ .sortedWith(compareByDescending<Map .Entry <String , MutableList <SearchResponse >>> { it.value.size }.thenBy { it.key })
283+ .forEach { (sport, items) ->
284+ if (items.isNotEmpty()) {
285+ lists.add(HomePageList (sport, items.take(20 ), isHorizontalImages = true ))
286+ }
284287 }
285- }
286288
287289 return newHomePageResponse(lists)
288290 }
@@ -304,6 +306,7 @@ class SKTech : MainAPI() {
304306 if (evMs != null && evMs > now) {
305307 if (isUpcomingEventsEnabled()) {
306308 upcoming.add(item)
309+ // Trim category to avoid trailing-space duplicates
307310 val sport = ev.category.trim()
308311 if (sport.isNotEmpty() && isSportEnabled(sport)) {
309312 byCategory.getOrPut(sport) { mutableListOf () }.add(item)
@@ -317,12 +320,14 @@ class SKTech : MainAPI() {
317320 lists.add(HomePageList (" 📅 UPCOMING" , upcoming.take(30 ), isHorizontalImages = true ))
318321 }
319322
320- // Sport sections sorted by name
321- byCategory.entries.sortedBy { it.key }.forEach { (sport, items) ->
322- if (items.isNotEmpty()) {
323- lists.add(HomePageList (sport, items.take(20 ), isHorizontalImages = true ))
323+ // Sport sections sorted by event count (most events first), then alphabetically
324+ byCategory.entries
325+ .sortedWith(compareByDescending<Map .Entry <String , MutableList <SearchResponse >>> { it.value.size }.thenBy { it.key })
326+ .forEach { (sport, items) ->
327+ if (items.isNotEmpty()) {
328+ lists.add(HomePageList (sport, items.take(20 ), isHorizontalImages = true ))
329+ }
324330 }
325- }
326331
327332 return newHomePageResponse(lists)
328333 }
@@ -438,13 +443,22 @@ class SKTech : MainAPI() {
438443 private fun SKTechEventData.toSearchResponse (): SearchResponse ? {
439444 return try {
440445 val style = getThumbnailStyle()
441- val logo = if (style == " logos" ) {
442- teamAFlag?.takeIf { it.isNotEmpty() }
443- ? : teamBFlag?.takeIf { it.isNotEmpty() }
444- ? : eventLogo?.takeIf { it.isNotEmpty() }
445- ? : getCategoryFallbackLogo(category)
446- } else {
447- getCategoryFallbackLogo(category)
446+ // Always prefer real images from the server — use fallback only as last resort
447+ val logo = when (style) {
448+ " logos" -> {
449+ // logos mode: prefer team flags (face/kit images)
450+ teamAFlag?.takeIf { it.isNotEmpty() }
451+ ? : teamBFlag?.takeIf { it.isNotEmpty() }
452+ ? : eventLogo?.takeIf { it.isNotEmpty() }
453+ ? : getCategoryFallbackLogo(category)
454+ }
455+ else -> {
456+ // banners mode (default): prefer event logo, then team flags
457+ eventLogo?.takeIf { it.isNotEmpty() }
458+ ? : teamAFlag?.takeIf { it.isNotEmpty() }
459+ ? : teamBFlag?.takeIf { it.isNotEmpty() }
460+ ? : getCategoryFallbackLogo(category)
461+ }
448462 }
449463 val title = buildTitle()
450464 val cd = ChannelData (name = eventName, logo = logo, linksPath = links)
0 commit comments