Merge pull request #4038 from vmazoyer/remember_dl_pref

Remember last selected media type for downloads.
This commit is contained in:
Tobias Groza 2020-09-03 20:11:36 +02:00 committed by GitHub
commit 0fd1e2fcd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -516,7 +516,23 @@ public class DownloadDialog extends DialogFragment
videoButton.setVisibility(isVideoStreamsAvailable ? View.VISIBLE : View.GONE); videoButton.setVisibility(isVideoStreamsAvailable ? View.VISIBLE : View.GONE);
subtitleButton.setVisibility(isSubtitleStreamsAvailable ? View.VISIBLE : View.GONE); subtitleButton.setVisibility(isSubtitleStreamsAvailable ? View.VISIBLE : View.GONE);
if (isVideoStreamsAvailable) { prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final String defaultMedia = prefs.getString(getString(R.string.last_used_download_type),
getString(R.string.last_download_type_video_key));
if (isVideoStreamsAvailable
&& (defaultMedia.equals(getString(R.string.last_download_type_video_key)))) {
videoButton.setChecked(true);
setupVideoSpinner();
} else if (isAudioStreamsAvailable
&& (defaultMedia.equals(getString(R.string.last_download_type_audio_key)))) {
audioButton.setChecked(true);
setupAudioSpinner();
} else if (isSubtitleStreamsAvailable
&& (defaultMedia.equals(getString(R.string.last_download_type_subtitle_key)))) {
subtitleButton.setChecked(true);
setupSubtitleSpinner();
} else if (isVideoStreamsAvailable) {
videoButton.setChecked(true); videoButton.setChecked(true);
setupVideoSpinner(); setupVideoSpinner();
} else if (isAudioStreamsAvailable) { } else if (isAudioStreamsAvailable) {
@ -595,6 +611,7 @@ public class DownloadDialog extends DialogFragment
final StoredDirectoryHelper mainStorage; final StoredDirectoryHelper mainStorage;
final MediaFormat format; final MediaFormat format;
final String mime; final String mime;
final String selectedMediaType;
// first, build the filename and get the output folder (if possible) // first, build the filename and get the output folder (if possible)
// later, run a very very very large file checking logic // later, run a very very very large file checking logic
@ -603,6 +620,7 @@ public class DownloadDialog extends DialogFragment
switch (radioStreamsGroup.getCheckedRadioButtonId()) { switch (radioStreamsGroup.getCheckedRadioButtonId()) {
case R.id.audio_button: case R.id.audio_button:
selectedMediaType = getString(R.string.last_download_type_audio_key);
mainStorage = mainStorageAudio; mainStorage = mainStorageAudio;
format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat(); format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat();
switch (format) { switch (format) {
@ -617,12 +635,14 @@ public class DownloadDialog extends DialogFragment
} }
break; break;
case R.id.video_button: case R.id.video_button:
selectedMediaType = getString(R.string.last_download_type_video_key);
mainStorage = mainStorageVideo; mainStorage = mainStorageVideo;
format = videoStreamsAdapter.getItem(selectedVideoIndex).getFormat(); format = videoStreamsAdapter.getItem(selectedVideoIndex).getFormat();
mime = format.mimeType; mime = format.mimeType;
filename += format.suffix; filename += format.suffix;
break; break;
case R.id.subtitle_button: case R.id.subtitle_button:
selectedMediaType = getString(R.string.last_download_type_subtitle_key);
mainStorage = mainStorageVideo; // subtitle & video files go together mainStorage = mainStorageVideo; // subtitle & video files go together
format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat(); format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat();
mime = format.mimeType; mime = format.mimeType;
@ -664,6 +684,11 @@ public class DownloadDialog extends DialogFragment
// check for existing file with the same name // check for existing file with the same name
checkSelectedDownload(mainStorage, mainStorage.findFile(filename), filename, mime); checkSelectedDownload(mainStorage, mainStorage.findFile(filename), filename, mime);
// remember the last media type downloaded by the user
prefs.edit()
.putString(getString(R.string.last_used_download_type), selectedMediaType)
.apply();
} }
private void checkSelectedDownload(final StoredDirectoryHelper mainStorage, private void checkSelectedDownload(final StoredDirectoryHelper mainStorage,

View File

@ -236,6 +236,11 @@
<string name="clear_playback_states_key" translatable="false">clear_playback_states</string> <string name="clear_playback_states_key" translatable="false">clear_playback_states</string>
<string name="clear_search_history_key" translatable="false">clear_search_history</string> <string name="clear_search_history_key" translatable="false">clear_search_history</string>
<string name="last_used_download_type" translatable="false">@string/last_download_type_video_key</string>
<string name="last_download_type_video_key" translatable="false">last_dl_type_video</string>
<string name="last_download_type_audio_key" translatable="false">last_dl_type_audio</string>
<string name="last_download_type_subtitle_key" translatable="false">last_dl_type_subtitle</string>
<string name="downloads_storage_ask" translatable="false">downloads_storage_ask</string> <string name="downloads_storage_ask" translatable="false">downloads_storage_ask</string>
<string name="storage_use_saf" translatable="false">storage_use_saf</string> <string name="storage_use_saf" translatable="false">storage_use_saf</string>