Skip to content

Commit

Permalink
Automate the download dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
martel800 committed Jun 28, 2024
1 parent 5f79582 commit 23c85ac
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<b>Mod for automated downloads based on criteria, instead of clicking through the download popup (name, audio/video, format, bitrate, etc.).</b>
<b>A mod for more automated downloads. For use with Youtube's "Share" button from a browser, essentially using NewPipe like a downloader "plugin" (a replacement for TubeMate, which is a freaking Adware, if not worse).
Introduces two new "Video and Audio" settings, one for treating all networks as metered, and another for automatically OK'ing the download dialog.</b>

<h3 align="center">We are planning to <i>rewrite</i> large chunks of the codebase, to bring about <a href="https://github.com/TeamNewPipe/NewPipe/discussions/10118">a new, modern and stable NewPipe</a>!</h3>
<h4 align="center">Please do <b>not</b> open pull requests for <i>new features</i> now, only bugfix PRs will be accepted.</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;
Expand All @@ -28,6 +29,7 @@
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
import androidx.annotation.IdRes;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
Expand Down Expand Up @@ -110,6 +112,8 @@ public class DownloadDialog extends DialogFragment
int selectedAudioIndex = 0; // default to the first item
@State
int selectedSubtitleIndex = 0; // default to the first item
@State
boolean okClicked = false; // guard

private StoredDirectoryHelper mainStorageAudio = null;
private StoredDirectoryHelper mainStorageVideo = null;
Expand Down Expand Up @@ -350,13 +354,35 @@ private void initToolbar(final Toolbar toolbar) {

toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.okay) {
prepareSelectedDownload();
if (!this.okClicked) {
this.okClicked = true;
prepareSelectedDownload();
}
return true;
}
return false;
});
}

@MainThread
@Override
public void onStart() {
super.onStart();
final boolean autoOkDownloadDialog =
PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean(
context.getString(R.string.auto_ok_download_dialog_key), false);
if (autoOkDownloadDialog) {
final Handler timerHandler = new Handler();
final Runnable timerRunnable = new Runnable() {
@Override
public void run() {
okButton.performClick();
}
};
timerHandler.postDelayed(timerRunnable, 500);
}
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<string name="default_resolution_value">720p60</string>
<string name="show_higher_resolutions_key">show_higher_resolutions</string>
<string name="treat_all_networks_as_mobile_key">treat_all_networks_as_mobile</string>
<string name="auto_ok_download_dialog_key">auto_ok_download_dialog</string>
<string name="default_popup_resolution_key">default_popup_resolution</string>
<string name="default_popup_resolution_value">480p</string>
<string name="best_resolution_key">best_resolution</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<string name="default_resolution_title">Default resolution</string>
<string name="default_popup_resolution_title">Default popup resolution</string>
<string name="treat_all_networks_as_mobile_title">Treat all networks as mobile</string>
<string name="auto_ok_download_dialog_title">Automatically OK download dialog</string>
<string name="show_higher_resolutions_title">Show higher resolutions</string>
<string name="show_higher_resolutions_summary">Only some devices can play 2K/4K videos</string>
<string name="play_with_kodi_title">Play with Kodi</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/video_audio_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/auto_ok_download_dialog_key"
android:title="@string/auto_ok_download_dialog_title"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/show_higher_resolutions_key"
Expand Down

0 comments on commit 23c85ac

Please sign in to comment.