Skip to content

Commit 79e3a0a

Browse files
committed
Feature: emoji on subtitles / sources selection
* Show flag and translated name when choosing subtitles / sources * Group by language code instead of name on sources / mirrors selection
1 parent e761ba4 commit 79e3a0a

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,24 +1179,25 @@ class GeneratorPlayer : FullScreenPlayer() {
11791179
ArrayAdapter<Spanned>(ctx, R.layout.sort_bottom_single_choice)
11801180
subsArrayAdapter.add(ctx.getString(R.string.no_subtitles).html())
11811181

1182-
val subtitlesGrouped =
1183-
currentSubtitles.groupBy { it.originalName }.map { (key, value) ->
1184-
key to value.sortedBy { it.nameSuffix.toIntOrNull() ?: 0 }
1185-
}.toMap()
1182+
val subtitlesGrouped = currentSubtitles
1183+
.groupBy { it.languageCode }
1184+
.mapValues { it.value.sortedWith(
1185+
compareBy({ it.localizedName.substringAfter("\u00a0").lowercase() }, { it.nameSuffix.toIntOrNull() ?: 0 })) }
1186+
.toMap()
11861187
val subtitlesGroupedList = subtitlesGrouped.entries.toList()
11871188

1188-
val subtitles = subtitlesGrouped.map { it.key.html() }
1189+
val subtitlesDisplayNames = subtitlesGrouped.map { it.value.first().localizedName.html() }
11891190

11901191
val subtitleGroupIndexStart =
1191-
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.originalName) + 1
1192+
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.languageCode) + 1
11921193
var subtitleGroupIndex = subtitleGroupIndexStart
11931194

11941195
val subtitleOptionIndexStart =
1195-
subtitlesGrouped[currentSelectedSubtitles?.originalName]?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix }
1196-
?: 0
1196+
subtitlesGrouped[currentSelectedSubtitles?.languageCode]
1197+
?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix } ?: 0
11971198
var subtitleOptionIndex = subtitleOptionIndexStart
11981199

1199-
subsArrayAdapter.addAll(subtitles)
1200+
subsArrayAdapter.addAll(subtitlesDisplayNames)
12001201

12011202
subtitleList.adapter = subsArrayAdapter
12021203
subtitleList.choiceMode = AbsListView.CHOICE_MODE_SINGLE

app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerSubtitleHelper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.media3.ui.SubtitleView
1111
import com.lagradost.cloudstream3.SubtitleFile
1212
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
1313
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.setSubtitleViewStyle
14+
import com.lagradost.cloudstream3.utils.SubtitleHelper.getNameNextToFlagEmoji
1415
import com.lagradost.cloudstream3.utils.UIHelper.toPx
1516

1617
enum class SubtitleStatus {
@@ -49,6 +50,9 @@ data class SubtitleData(
4950

5051
val name = "$originalName $nameSuffix"
5152

53+
val localizedName
54+
get() = getNameNextToFlagEmoji(languageCode) ?: originalName
55+
5256
/**
5357
* Gets the URL, but tries to fix it if it is malformed.
5458
*/

app/src/main/java/com/lagradost/cloudstream3/ui/player/RepoLinkGenerator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class RepoLinkGenerator(
8888

8989
currentCache.subtitleCache.forEach { sub ->
9090
currentSubsUrls.add(sub.url)
91-
val suffixCount = lastCountedSuffix.getOrDefault(sub.originalName, 0u) + 1u
92-
lastCountedSuffix[sub.originalName] = suffixCount
91+
val suffixCount = lastCountedSuffix.getOrDefault(sub.languageCode, 0u) + 1u
92+
lastCountedSuffix[sub.languageCode] = suffixCount
9393
subtitleCallback(sub)
9494
}
9595

@@ -116,9 +116,9 @@ class RepoLinkGenerator(
116116
// this part makes sure that all names are unique for UX
117117

118118
val nameDecoded = correctFile.originalName.html().toString().trim() // `%3Ch1%3Esub%20name…` → `<h1>sub name…` → `sub name…`
119-
120-
val suffixCount = lastCountedSuffix.getOrDefault(nameDecoded, 0u) +1u
121-
lastCountedSuffix[nameDecoded] = suffixCount
119+
val langCode = correctFile.languageCode
120+
val suffixCount = lastCountedSuffix.getOrDefault(langCode, 0u) +1u
121+
lastCountedSuffix[langCode] = suffixCount
122122

123123
val updatedFile =
124124
correctFile.copy(originalName = nameDecoded, nameSuffix = "$suffixCount")

app/src/main/java/com/lagradost/cloudstream3/utils/AppContextUtils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ object AppContextUtils {
383383
}
384384

385385
fun sortSubs(subs: Set<SubtitleData>): List<SubtitleData> {
386-
return subs.sortedBy { it.name }
386+
return subs.sortedWith(
387+
compareBy({ it.localizedName.substringAfter("\u00a0").lowercase() }, { it.nameSuffix.toIntOrNull() ?: 0 })
388+
)
387389
}
388390

389391
fun Context.getApiSettings(): HashSet<String> {

0 commit comments

Comments
 (0)