From 1afb9cdba93ebf6b744d26a1b13010ee2aded19e Mon Sep 17 00:00:00 2001 From: pratyaksh1610 Date: Sun, 4 Dec 2022 17:59:22 +0530 Subject: [PATCH 1/4] added Language suffix for subtitle downloads --- .../newpipe/download/DownloadDialog.java | 18 ++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 2 files changed, 19 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 2975fe43a..c54fd5173 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -562,6 +562,24 @@ public class DownloadDialog extends DialogFragment selectedSubtitleIndex = position; break; } + onItemSelectedSetFileName(); + } + + private void onItemSelectedSetFileName() { + final String setSubtitleLanguageCode = subtitleStreamsAdapter.getItem(selectedSubtitleIndex) + .getLanguageTag(); + switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) { + case R.id.audio_button: + case R.id.video_button: + dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(), + currentInfo.getName())); + break; + case R.id.subtitle_button: + dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(), + currentInfo.getName() + getString( + R.string.caption_file_name, setSubtitleLanguageCode))); + break; + } } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3fa37155a..fefba2c77 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -452,6 +452,7 @@ Zoom Auto-generated + -%s Captions Modify player caption text scale and background styles. Requires app restart to take effect From 50269d0f5ebd3653f3498c78020792294762827f Mon Sep 17 00:00:00 2001 From: pratyaksh1610 Date: Mon, 2 Jan 2023 16:23:45 +0530 Subject: [PATCH 2/4] updated caption file name and clean code --- .../org/schabi/newpipe/download/DownloadDialog.java | 10 +++++----- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index c54fd5173..7777f87fe 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -568,16 +568,16 @@ public class DownloadDialog extends DialogFragment private void onItemSelectedSetFileName() { final String setSubtitleLanguageCode = subtitleStreamsAdapter.getItem(selectedSubtitleIndex) .getLanguageTag(); + final String fileName = FilenameUtils.createFilename(getContext(), + currentInfo.getName()); switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) { case R.id.audio_button: case R.id.video_button: - dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(), - currentInfo.getName())); + dialogBinding.fileName.setText(fileName); break; case R.id.subtitle_button: - dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(), - currentInfo.getName() + getString( - R.string.caption_file_name, setSubtitleLanguageCode))); + dialogBinding.fileName.setText(fileName + getString( + R.string.caption_file_name, fileName, setSubtitleLanguageCode)); break; } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fefba2c77..f9d1361a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -452,7 +452,7 @@ Zoom Auto-generated - -%s + %1$s-%2$s Captions Modify player caption text scale and background styles. Requires app restart to take effect From 3e15c77a05209b76215fb0ef080930f19cfd62e8 Mon Sep 17 00:00:00 2001 From: pratyaksh1610 Date: Tue, 3 Jan 2023 14:07:28 +0530 Subject: [PATCH 3/4] move string to donottranslate.xml and fix nits --- .../java/org/schabi/newpipe/download/DownloadDialog.java | 6 +++--- app/src/main/res/values/donottranslate.xml | 1 + app/src/main/res/values/strings.xml | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 7777f87fe..77bb48a81 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -566,8 +566,6 @@ public class DownloadDialog extends DialogFragment } private void onItemSelectedSetFileName() { - final String setSubtitleLanguageCode = subtitleStreamsAdapter.getItem(selectedSubtitleIndex) - .getLanguageTag(); final String fileName = FilenameUtils.createFilename(getContext(), currentInfo.getName()); switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) { @@ -576,7 +574,9 @@ public class DownloadDialog extends DialogFragment dialogBinding.fileName.setText(fileName); break; case R.id.subtitle_button: - dialogBinding.fileName.setText(fileName + getString( + final String setSubtitleLanguageCode = subtitleStreamsAdapter + .getItem(selectedSubtitleIndex).getLanguageTag(); + dialogBinding.fileName.setText(getString( R.string.caption_file_name, fileName, setSubtitleLanguageCode)); break; } diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index d28f794c0..09bf9080c 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -27,4 +27,5 @@ SoundCloud @string/app_name LeakCanary + %1$s-%2$s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f9d1361a8..3fa37155a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -452,7 +452,6 @@ Zoom Auto-generated - %1$s-%2$s Captions Modify player caption text scale and background styles. Requires app restart to take effect From 2afbe58722215494e5eea8de148cd42d8970715e Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 11 Jan 2023 19:45:55 +0100 Subject: [PATCH 4/4] UX improvements: keep user edits & do not reset cursor --- .../newpipe/download/DownloadDialog.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 77bb48a81..208d27bb2 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -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; @@ -566,19 +567,34 @@ public class DownloadDialog extends DialogFragment } private void onItemSelectedSetFileName() { - final String fileName = FilenameUtils.createFilename(getContext(), - currentInfo.getName()); - switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) { - case R.id.audio_button: - case R.id.video_button: - dialogBinding.fileName.setText(fileName); - break; - case R.id.subtitle_button: - final String setSubtitleLanguageCode = subtitleStreamsAdapter - .getItem(selectedSubtitleIndex).getLanguageTag(); - dialogBinding.fileName.setText(getString( - R.string.caption_file_name, fileName, setSubtitleLanguageCode)); - break; + 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; + } } }