-
Notifications
You must be signed in to change notification settings - Fork 858
Improve subtitle selection UX: Move "No Subtitles" option to bottom #2523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
eab2b07
23c1d30
702b923
b193104
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) -> | ||
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = | ||
|
|
@@ -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 | ||
|
|
@@ -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) { | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.