Skip to content

Commit 51e54ed

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 b471469 commit 51e54ed

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
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
@@ -1162,24 +1162,25 @@ class GeneratorPlayer : FullScreenPlayer() {
11621162
ArrayAdapter<Spanned>(ctx, R.layout.sort_bottom_single_choice)
11631163
subsArrayAdapter.add(ctx.getString(R.string.no_subtitles).html())
11641164

1165-
val subtitlesGrouped =
1166-
currentSubtitles.groupBy { it.originalName }.map { (key, value) ->
1167-
key to value.sortedBy { it.nameSuffix.toIntOrNull() ?: 0 }
1168-
}.toMap()
1165+
val subtitlesGrouped = currentSubtitles
1166+
.groupBy { it.languageCode }
1167+
.mapValues { it.value.sortedWith(
1168+
compareBy({ it.localizedName.substringAfter("\u00a0").lowercase() }, { it.nameSuffix.toIntOrNull() ?: 0 })) }
1169+
.toMap()
11691170
val subtitlesGroupedList = subtitlesGrouped.entries.toList()
11701171

1171-
val subtitles = subtitlesGrouped.map { it.key.html() }
1172+
val subtitlesDisplayNames = subtitlesGrouped.map { it.value.first().localizedName.html() }
11721173

11731174
val subtitleGroupIndexStart =
1174-
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.originalName) + 1
1175+
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.languageCode) + 1
11751176
var subtitleGroupIndex = subtitleGroupIndexStart
11761177

11771178
val subtitleOptionIndexStart =
1178-
subtitlesGrouped[currentSelectedSubtitles?.originalName]?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix }
1179-
?: 0
1179+
subtitlesGrouped[currentSelectedSubtitles?.languageCode]
1180+
?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix } ?: 0
11801181
var subtitleOptionIndex = subtitleOptionIndexStart
11811182

1182-
subsArrayAdapter.addAll(subtitles)
1183+
subsArrayAdapter.addAll(subtitlesDisplayNames)
11831184

11841185
subtitleList.adapter = subsArrayAdapter
11851186
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: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class RepoLinkGenerator(
6464
// these act as a general filter to prevent duplication of links or names
6565
val currentLinksUrls = mutableSetOf<String>() // makes all urls unique
6666
val currentSubsUrls = mutableSetOf<String>() // makes all subs urls unique
67-
val currentSubsNames = mutableSetOf<String>() // makes all subs names unique
6867

6968
synchronized(currentCache) {
7069
val outdatedCache =
@@ -88,7 +87,6 @@ class RepoLinkGenerator(
8887

8988
currentCache.subtitleCache.forEach { sub ->
9089
currentSubsUrls.add(sub.url)
91-
currentSubsNames.add(sub.name)
9290
subtitleCallback(sub)
9391
}
9492

@@ -116,12 +114,11 @@ class RepoLinkGenerator(
116114

117115
val nameDecoded = correctFile.originalName.html().toString().trim() // `%3Ch1%3Esub%20name…` → `<h1>sub name…` → `sub name…`
118116

119-
val suffixCount = currentSubsNames.count { it.contains(nameDecoded) } +1
117+
val suffixCount = currentCache.subtitleCache.count {
118+
it.languageCode == correctFile.languageCode
119+
} + 1
120120

121-
val updatedFile =
122-
correctFile.copy(originalName = nameDecoded, nameSuffix = "$suffixCount")
123-
124-
currentSubsNames.add(updatedFile.name)
121+
val updatedFile = correctFile.copy(originalName = nameDecoded, nameSuffix = "$suffixCount")
125122

126123
synchronized(currentCache) {
127124
if (currentCache.subtitleCache.add(updatedFile)) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ object AppContextUtils {
377377
}
378378

379379
fun sortSubs(subs: Set<SubtitleData>): List<SubtitleData> {
380-
return subs.sortedBy { it.name }
380+
return subs.sortedWith(
381+
compareBy({ it.localizedName.substringAfter("\u00a0").lowercase() }, { it.nameSuffix.toIntOrNull() ?: 0 })
382+
)
381383
}
382384

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

0 commit comments

Comments
 (0)