Skip to content
Merged
Changes from 1 commit
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 @@ -1162,7 +1162,6 @@ class GeneratorPlayer : FullScreenPlayer() {

val subsArrayAdapter =
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) ->
Expand All @@ -1173,7 +1172,7 @@ class GeneratorPlayer : FullScreenPlayer() {
val subtitles = subtitlesGrouped.map { it.key.html() }

val subtitleGroupIndexStart =
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.originalName) + 1
subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.originalName)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when you select no subtitles the checkmark does not appear, because this index returns -1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should now be fixed.

When No Subtitles was selected, currentSelectedSubtitles became null. On reopening the dialog, indexOf(...) returned -1, so setItemChecked(-1, true) did nothing and the checkmark was not shown.

I now handle the null case explicitly by setting subtitleGroupIndexStart = subtitlesGrouped.size, which points to the No Subtitles item in the adapter (same convention used in the apply logic).

I had tested this earlier, but after your feedback I rechecked and noticed the selection state was not persisting when reopening the dialog. I’ve retested the full flow and it now works as expected.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may still give -1, so you have to add a if statement to check if the result == -1 then set it to subtitlesGrouped.size, or check for "contains". Just because it is non-null does not mean subtitlesGrouped must contain it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Now handles the case where indexOf returns -1 by defaulting to no subtitles

var subtitleGroupIndex = subtitleGroupIndexStart

val subtitleOptionIndexStart =
Expand All @@ -1182,6 +1181,7 @@ class GeneratorPlayer : FullScreenPlayer() {
var subtitleOptionIndex = subtitleOptionIndexStart

subsArrayAdapter.addAll(subtitles)
subsArrayAdapter.add(ctx.getString(R.string.no_subtitles).html())

subtitleList.adapter = subsArrayAdapter
subtitleList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
Expand All @@ -1200,7 +1200,7 @@ class GeneratorPlayer : FullScreenPlayer() {

val subtitleOptions =
subtitlesGroupedList
.getOrNull(subtitleGroupIndex - 1)?.value?.map { subtitle ->
.getOrNull(subtitleGroupIndex)?.value?.map { subtitle ->
val nameSuffix = subtitle.nameSuffix.html()
nameSuffix.ifBlank {
when (subtitle.origin) {
Expand Down Expand Up @@ -1252,7 +1252,7 @@ class GeneratorPlayer : FullScreenPlayer() {
}

subtitleOptionList.setOnItemClickListener { _, _, which, _ ->
if (which >= (subtitlesGroupedList.getOrNull(subtitleGroupIndex - 1)?.value?.size
if (which >= (subtitlesGroupedList.getOrNull(subtitleGroupIndex)?.value?.size
?: -1)
) {
val child = subtitleOptionList.adapter.getView(which, null, subtitleList)
Expand Down Expand Up @@ -1337,10 +1337,10 @@ class GeneratorPlayer : FullScreenPlayer() {
binding.applyBtt.setOnClickListener {
var init = sourceIndex != startSource
if (subtitleGroupIndex != subtitleGroupIndexStart || subtitleOptionIndex != subtitleOptionIndexStart) {
init = init or if (subtitleGroupIndex <= 0) {
init = init or if (subtitleGroupIndex >= subtitlesGrouped.size) {
noSubtitles()
} else {
subtitlesGroupedList.getOrNull(subtitleGroupIndex - 1)?.value?.getOrNull(
subtitlesGroupedList.getOrNull(subtitleGroupIndex)?.value?.getOrNull(
subtitleOptionIndex
)?.let {
setSubtitles(it, true)
Expand Down