Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to save data even on WiFi & Automate the download dialog #7

Merged
merged 3 commits into from
Aug 5, 2024
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<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
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {

defaultConfig {
applicationId "org.schabi.newpipe"
resValue "string", "app_name", "NewPipe"
resValue "string", "app_name", "NewPipeAutoDL"
minSdk 21
targetSdk 33
versionCode 997
Expand All @@ -42,19 +42,19 @@ android {
if (normalizedWorkingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") {
// default values when branch name could not be determined or is master or dev
applicationIdSuffix ".debug"
resValue "string", "app_name", "NewPipe Debug"
resValue "string", "app_name", "NewPipeAutoDLNewPipe Debug"
} else {
applicationIdSuffix ".debug." + normalizedWorkingBranch
resValue "string", "app_name", "NewPipe " + workingBranch
archivesBaseName = 'NewPipe_' + normalizedWorkingBranch
resValue "string", "app_name", "NewPipeAutoDL " + workingBranch
archivesBaseName = 'NewPipeAutoDL_' + normalizedWorkingBranch
}
}

release {
if (System.properties.containsKey('packageSuffix')) {
applicationIdSuffix System.getProperty('packageSuffix')
resValue "string", "app_name", "NewPipe " + System.getProperty('packageSuffix')
archivesBaseName = 'NewPipe_' + System.getProperty('packageSuffix')
resValue "string", "app_name", "NewPipeAutoDL " + System.getProperty('packageSuffix')
archivesBaseName = 'NewPipeAutoDL_' + System.getProperty('packageSuffix')
}
minifyEnabled true
shrinkResources false // disabled to fix F-Droid's reproducible build
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
9 changes: 6 additions & 3 deletions app/src/main/java/org/schabi/newpipe/util/ListHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,12 @@ static boolean isLimitingDataUsage(@NonNull final Context context) {
*/
private static String getResolutionLimit(@NonNull final Context context) {
String resolutionLimit = null;
if (isMeteredNetwork(context)) {
final SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(context);
final boolean treatAllNetworksAsMobileData =
preferences.getBoolean(context.getString(R.string.treat_all_networks_as_mobile_key),
false);
if (isMeteredNetwork(context) || treatAllNetworksAsMobileData) {
final String defValue = context.getString(R.string.limit_data_usage_none_key);
final String value = preferences.getString(
context.getString(R.string.limit_mobile_data_usage_key), defValue);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
<string name="default_resolution_key">default_resolution</string>
<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
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<string name="download_path_audio_dialog_title">Choose download folder for audio files</string>
<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
14 changes: 14 additions & 0 deletions app/src/main/res/xml/video_audio_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/treat_all_networks_as_mobile_key"
android:title="@string/treat_all_networks_as_mobile_title"
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
Loading