|
75 | 75 | import java.util.List; |
76 | 76 | import java.util.Locale; |
77 | 77 | import java.util.Objects; |
| 78 | +import java.util.Optional; |
78 | 79 |
|
79 | 80 | import icepick.Icepick; |
80 | 81 | import icepick.State; |
@@ -560,6 +561,39 @@ public void onItemSelected(final AdapterView<?> parent, |
560 | 561 | selectedSubtitleIndex = position; |
561 | 562 | break; |
562 | 563 | } |
| 564 | + onItemSelectedSetFileName(); |
| 565 | + } |
| 566 | + |
| 567 | + private void onItemSelectedSetFileName() { |
| 568 | + final String fileName = FilenameUtils.createFilename(getContext(), currentInfo.getName()); |
| 569 | + final String prevFileName = Optional.ofNullable(dialogBinding.fileName.getText()) |
| 570 | + .map(Object::toString) |
| 571 | + .orElse(""); |
| 572 | + |
| 573 | + if (prevFileName.isEmpty() |
| 574 | + || prevFileName.equals(fileName) |
| 575 | + || prevFileName.startsWith(getString(R.string.caption_file_name, fileName, ""))) { |
| 576 | + // only update the file name field if it was not edited by the user |
| 577 | + |
| 578 | + switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) { |
| 579 | + case R.id.audio_button: |
| 580 | + case R.id.video_button: |
| 581 | + if (!prevFileName.equals(fileName)) { |
| 582 | + // since the user might have switched between audio and video, the correct |
| 583 | + // text might already be in place, so avoid resetting the cursor position |
| 584 | + dialogBinding.fileName.setText(fileName); |
| 585 | + } |
| 586 | + break; |
| 587 | + |
| 588 | + case R.id.subtitle_button: |
| 589 | + final String setSubtitleLanguageCode = subtitleStreamsAdapter |
| 590 | + .getItem(selectedSubtitleIndex).getLanguageTag(); |
| 591 | + // this will reset the cursor position, which is bad UX, but it can't be avoided |
| 592 | + dialogBinding.fileName.setText(getString( |
| 593 | + R.string.caption_file_name, fileName, setSubtitleLanguageCode)); |
| 594 | + break; |
| 595 | + } |
| 596 | + } |
563 | 597 | } |
564 | 598 |
|
565 | 599 | @Override |
|
0 commit comments