Skip to content

Commit

Permalink
Merge pull request #4038 from vmazoyer/remember_dl_pref
Browse files Browse the repository at this point in the history
Remember last selected media type for downloads.
  • Loading branch information
TobiGr authored Sep 3, 2020
2 parents a84b54f + 99442b6 commit 0fd1e2f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,23 @@ protected void setupDownloadOptions() {
videoButton.setVisibility(isVideoStreamsAvailable ? 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);
setupVideoSpinner();
} else if (isAudioStreamsAvailable) {
Expand Down Expand Up @@ -595,6 +611,7 @@ private void prepareSelectedDownload() {
final StoredDirectoryHelper mainStorage;
final MediaFormat format;
final String mime;
final String selectedMediaType;

// first, build the filename and get the output folder (if possible)
// later, run a very very very large file checking logic
Expand All @@ -603,6 +620,7 @@ private void prepareSelectedDownload() {

switch (radioStreamsGroup.getCheckedRadioButtonId()) {
case R.id.audio_button:
selectedMediaType = getString(R.string.last_download_type_audio_key);
mainStorage = mainStorageAudio;
format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat();
switch (format) {
Expand All @@ -617,12 +635,14 @@ private void prepareSelectedDownload() {
}
break;
case R.id.video_button:
selectedMediaType = getString(R.string.last_download_type_video_key);
mainStorage = mainStorageVideo;
format = videoStreamsAdapter.getItem(selectedVideoIndex).getFormat();
mime = format.mimeType;
filename += format.suffix;
break;
case R.id.subtitle_button:
selectedMediaType = getString(R.string.last_download_type_subtitle_key);
mainStorage = mainStorageVideo; // subtitle & video files go together
format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat();
mime = format.mimeType;
Expand Down Expand Up @@ -664,6 +684,11 @@ private void prepareSelectedDownload() {

// check for existing file with the same name
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,
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@
<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="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="storage_use_saf" translatable="false">storage_use_saf</string>

Expand Down

0 comments on commit 0fd1e2f

Please sign in to comment.