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