Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
import org.schabi.newpipe.util.ThemeHelper;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -193,7 +195,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
nameEditText = view.findViewById(R.id.file_name);
nameEditText.setText(FilenameUtils.createFilename(getContext(), currentInfo.getName()));

nameEditText.setText(createFilename());
selectedAudioIndex = ListHelper.getDefaultAudioFormat(getContext(), currentInfo.getAudioStreams());

selectedSubtitleIndex = getSubtitleIndexBy(subtitleStreamsAdapter.getAll());
Expand Down Expand Up @@ -268,10 +271,10 @@ public void onSaveInstanceState(Bundle outState) {
Icepick.saveInstanceState(this, outState);
}


/*//////////////////////////////////////////////////////////////////////////
// Inits
//////////////////////////////////////////////////////////////////////////*/

private void initToolbar(Toolbar toolbar) {
if (DEBUG) Log.d(TAG, "initToolbar() called with: toolbar = [" + toolbar + "]");
toolbar.setTitle(R.string.download_dialog_title);
Expand Down Expand Up @@ -312,10 +315,10 @@ private void setupSubtitleSpinner() {
setRadioButtonsState(true);
}


/*//////////////////////////////////////////////////////////////////////////
// Radio group Video&Audio options - Listener
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
if (DEBUG)
Expand All @@ -338,10 +341,10 @@ public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
threadsSeekBar.setEnabled(flag);
}


/*//////////////////////////////////////////////////////////////////////////
// Streams Spinner Listener
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (DEBUG)
Expand All @@ -363,10 +366,10 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
public void onNothingSelected(AdapterView<?> parent) {
}


/*//////////////////////////////////////////////////////////////////////////
// Utils
//////////////////////////////////////////////////////////////////////////*/

protected void setupDownloadOptions() {
setRadioButtonsState(false);

Expand Down Expand Up @@ -538,4 +541,37 @@ private void downloadSelected(Context context, Stream selectedStream, String loc

getDialog().dismiss();
}

private String createFilename() {
String defaultDownloadFilenameFormat = requireContext().getString(
R.string.download_filename_format_default_value);

String currentDownloadFilenameFormat = PreferenceManager.getDefaultSharedPreferences(getContext())
.getString(
requireContext().getString(R.string.download_filename_format_key),
defaultDownloadFilenameFormat);

if (currentDownloadFilenameFormat == null) {
throw new NullPointerException("currentDownloadFilenameFormat is null");
}

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM", Locale.US);
String currentDate = sdf.format(new Date());

String secondParam = currentInfo.getName();
String thirdParam = currentDate;

if (!currentDownloadFilenameFormat.equals(defaultDownloadFilenameFormat)) {
secondParam = currentDate;
thirdParam = currentInfo.getName();
}

String filename = String.format(
"%s-%s-%s",
currentInfo.getUploaderName(),
secondParam,
thirdParam);

return FilenameUtils.createFilename(getContext(), filename);
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -919,4 +919,8 @@
<item>@string/grid</item>
</string-array>

<string-array name="download_filename_formats">
<item>@string/download_filename_format_cnvtcd</item>
<item>@string/download_filename_format_cncdvt</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -603,4 +603,10 @@
<string name="pause_downloads_on_mobile_desc">Downloads that can not be paused will be restarted</string>
<string name="close">Close</string>

<string name="download_filename_format_key" translatable="false">download_filename_format</string>
<string name="download_filename_format_default_value">@string/download_filename_format_cnvtcd</string>
<string name="download_filename_format_cnvtcd">ChannelName-VideoTitle-CurrentDate</string>
<string name="download_filename_format_cncdvt">ChannelName-CurrentDate-VideoTitle</string>
<string name="download_filename_format_title">Download filename format</string>
<string name="download_filename_format_summary">Videos will have filename with this format</string>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/xml/download_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
android:summary="@string/settings_file_replacement_character_summary"
android:title="@string/settings_file_replacement_character_title"/>

<ListPreference
app:iconSpaceReserved="false"
android:defaultValue="@string/download_filename_format_default_value"
android:entries="@array/download_filename_formats"
android:entryValues="@array/download_filename_formats"
android:key="@string/download_filename_format_key"
android:title="@string/download_filename_format_title"
android:summary="@string/download_filename_format_summary"/>

<ListPreference
app:iconSpaceReserved="false"
android:defaultValue="@string/downloads_maximum_retry_default"
Expand Down