Skip to content
Draft
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 @@ -1179,24 +1179,25 @@ class GeneratorPlayer : FullScreenPlayer() {
ArrayAdapter<Spanned>(ctx, R.layout.sort_bottom_single_choice)
subsArrayAdapter.add(ctx.getString(R.string.no_subtitles).html())

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

val subtitles = subtitlesGrouped.map { it.key.html() }
val subtitlesDisplayNames = subtitlesGrouped.map { it.value.first().localizedName.html() }

val subtitleGroupIndexStart =
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.originalName) + 1
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.languageCode) + 1
var subtitleGroupIndex = subtitleGroupIndexStart

val subtitleOptionIndexStart =
subtitlesGrouped[currentSelectedSubtitles?.originalName]?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix }
?: 0
subtitlesGrouped[currentSelectedSubtitles?.languageCode]
?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix } ?: 0
var subtitleOptionIndex = subtitleOptionIndexStart

subsArrayAdapter.addAll(subtitles)
subsArrayAdapter.addAll(subtitlesDisplayNames)

subtitleList.adapter = subsArrayAdapter
subtitleList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.media3.ui.SubtitleView
import com.lagradost.cloudstream3.SubtitleFile
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.setSubtitleViewStyle
import com.lagradost.cloudstream3.utils.SubtitleHelper.getNameNextToFlagEmoji
import com.lagradost.cloudstream3.utils.UIHelper.toPx

enum class SubtitleStatus {
Expand Down Expand Up @@ -49,6 +50,9 @@ data class SubtitleData(

val name = "$originalName $nameSuffix"

val localizedName
get() = getNameNextToFlagEmoji(languageCode) ?: originalName

/**
* Gets the URL, but tries to fix it if it is malformed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class RepoLinkGenerator(

currentCache.subtitleCache.forEach { sub ->
currentSubsUrls.add(sub.url)
val suffixCount = lastCountedSuffix.getOrDefault(sub.originalName, 0u) + 1u
lastCountedSuffix[sub.originalName] = suffixCount
val suffixCount = lastCountedSuffix.getOrDefault(sub.languageCode?: "unknown", 0u) + 1u
lastCountedSuffix[sub.languageCode?: "unknown"] = suffixCount
subtitleCallback(sub)
}

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

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

val suffixCount = lastCountedSuffix.getOrDefault(nameDecoded, 0u) +1u
lastCountedSuffix[nameDecoded] = suffixCount
val langCode = correctFile.languageCode ?: "unknown"
val suffixCount = lastCountedSuffix.getOrDefault(langCode, 0u) +1u
lastCountedSuffix[langCode] = suffixCount

val updatedFile =
correctFile.copy(originalName = nameDecoded, nameSuffix = "$suffixCount")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ object AppContextUtils {
}

fun sortSubs(subs: Set<SubtitleData>): List<SubtitleData> {
return subs.sortedBy { it.name }
return subs.sortedWith(
compareBy({ it.localizedName.substringAfter("\u00a0").lowercase() }, { it.nameSuffix.toIntOrNull() ?: 0 })
)
}

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