mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Merge pull request #9499 from pratyaksh1610/branch-9466
Added Language suffix for subtitle downloads
This commit is contained in:
commit
03f5dd71a5
@ -75,6 +75,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import icepick.Icepick;
|
||||
import icepick.State;
|
||||
@ -560,6 +561,39 @@ public class DownloadDialog extends DialogFragment
|
||||
selectedSubtitleIndex = position;
|
||||
break;
|
||||
}
|
||||
onItemSelectedSetFileName();
|
||||
}
|
||||
|
||||
private void onItemSelectedSetFileName() {
|
||||
final String fileName = FilenameUtils.createFilename(getContext(), currentInfo.getName());
|
||||
final String prevFileName = Optional.ofNullable(dialogBinding.fileName.getText())
|
||||
.map(Object::toString)
|
||||
.orElse("");
|
||||
|
||||
if (prevFileName.isEmpty()
|
||||
|| prevFileName.equals(fileName)
|
||||
|| prevFileName.startsWith(getString(R.string.caption_file_name, fileName, ""))) {
|
||||
// only update the file name field if it was not edited by the user
|
||||
|
||||
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
||||
case R.id.audio_button:
|
||||
case R.id.video_button:
|
||||
if (!prevFileName.equals(fileName)) {
|
||||
// since the user might have switched between audio and video, the correct
|
||||
// text might already be in place, so avoid resetting the cursor position
|
||||
dialogBinding.fileName.setText(fileName);
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.subtitle_button:
|
||||
final String setSubtitleLanguageCode = subtitleStreamsAdapter
|
||||
.getItem(selectedSubtitleIndex).getLanguageTag();
|
||||
// this will reset the cursor position, which is bad UX, but it can't be avoided
|
||||
dialogBinding.fileName.setText(getString(
|
||||
R.string.caption_file_name, fileName, setSubtitleLanguageCode));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,4 +27,5 @@
|
||||
<string name="soundcloud">SoundCloud</string>
|
||||
<string name="preferred_open_action_share_menu_title">@string/app_name</string>
|
||||
<string name="leakcanary">LeakCanary</string>
|
||||
<string name="caption_file_name">%1$s-%2$s</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user