Skip to content

Commit bb881a8

Browse files
Merge pull request #7 from martel800/moddev
Add an option to save data even on WiFi & Automate the download dialog
2 parents 34d8220 + 23c85ac commit bb881a8

File tree

7 files changed

+60
-10
lines changed

7 files changed

+60
-10
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<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).
2+
Introduces two new "Video and Audio" settings, one for treating all networks as metered, and another for automatically OK'ing the download dialog.</b>
3+
14
<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>
25
<h4 align="center">Please do <b>not</b> open pull requests for <i>new features</i> now, only bugfix PRs will be accepted.</h4>
36

app/build.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ android {
1717

1818
defaultConfig {
1919
applicationId "org.schabi.newpipe"
20-
resValue "string", "app_name", "NewPipe"
20+
resValue "string", "app_name", "NewPipeAutoDL"
2121
minSdk 21
2222
targetSdk 33
2323
versionCode 998
@@ -42,19 +42,19 @@ android {
4242
if (normalizedWorkingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") {
4343
// default values when branch name could not be determined or is master or dev
4444
applicationIdSuffix ".debug"
45-
resValue "string", "app_name", "NewPipe Debug"
45+
resValue "string", "app_name", "NewPipeAutoDLNewPipe Debug"
4646
} else {
4747
applicationIdSuffix ".debug." + normalizedWorkingBranch
48-
resValue "string", "app_name", "NewPipe " + workingBranch
49-
archivesBaseName = 'NewPipe_' + normalizedWorkingBranch
48+
resValue "string", "app_name", "NewPipeAutoDL " + workingBranch
49+
archivesBaseName = 'NewPipeAutoDL_' + normalizedWorkingBranch
5050
}
5151
}
5252

5353
release {
5454
if (System.properties.containsKey('packageSuffix')) {
5555
applicationIdSuffix System.getProperty('packageSuffix')
56-
resValue "string", "app_name", "NewPipe " + System.getProperty('packageSuffix')
57-
archivesBaseName = 'NewPipe_' + System.getProperty('packageSuffix')
56+
resValue "string", "app_name", "NewPipeAutoDL " + System.getProperty('packageSuffix')
57+
archivesBaseName = 'NewPipeAutoDL_' + System.getProperty('packageSuffix')
5858
}
5959
minifyEnabled true
6060
shrinkResources false // disabled to fix F-Droid's reproducible build

app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.net.Uri;
1414
import android.os.Bundle;
1515
import android.os.Environment;
16+
import android.os.Handler;
1617
import android.os.IBinder;
1718
import android.provider.Settings;
1819
import android.util.Log;
@@ -28,6 +29,7 @@
2829
import androidx.activity.result.ActivityResultLauncher;
2930
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
3031
import androidx.annotation.IdRes;
32+
import androidx.annotation.MainThread;
3133
import androidx.annotation.NonNull;
3234
import androidx.annotation.Nullable;
3335
import androidx.annotation.StringRes;
@@ -110,6 +112,8 @@ public class DownloadDialog extends DialogFragment
110112
int selectedAudioIndex = 0; // default to the first item
111113
@State
112114
int selectedSubtitleIndex = 0; // default to the first item
115+
@State
116+
boolean okClicked = false; // guard
113117

114118
private StoredDirectoryHelper mainStorageAudio = null;
115119
private StoredDirectoryHelper mainStorageVideo = null;
@@ -350,13 +354,35 @@ private void initToolbar(final Toolbar toolbar) {
350354

351355
toolbar.setOnMenuItemClickListener(item -> {
352356
if (item.getItemId() == R.id.okay) {
353-
prepareSelectedDownload();
357+
if (!this.okClicked) {
358+
this.okClicked = true;
359+
prepareSelectedDownload();
360+
}
354361
return true;
355362
}
356363
return false;
357364
});
358365
}
359366

367+
@MainThread
368+
@Override
369+
public void onStart() {
370+
super.onStart();
371+
final boolean autoOkDownloadDialog =
372+
PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean(
373+
context.getString(R.string.auto_ok_download_dialog_key), false);
374+
if (autoOkDownloadDialog) {
375+
final Handler timerHandler = new Handler();
376+
final Runnable timerRunnable = new Runnable() {
377+
@Override
378+
public void run() {
379+
okButton.performClick();
380+
}
381+
};
382+
timerHandler.postDelayed(timerRunnable, 500);
383+
}
384+
}
385+
360386
@Override
361387
public void onDestroy() {
362388
super.onDestroy();

app/src/main/java/org/schabi/newpipe/util/ListHelper.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,12 @@ static boolean isLimitingDataUsage(@NonNull final Context context) {
705705
*/
706706
private static String getResolutionLimit(@NonNull final Context context) {
707707
String resolutionLimit = null;
708-
if (isMeteredNetwork(context)) {
709-
final SharedPreferences preferences =
710-
PreferenceManager.getDefaultSharedPreferences(context);
708+
final SharedPreferences preferences =
709+
PreferenceManager.getDefaultSharedPreferences(context);
710+
final boolean treatAllNetworksAsMobileData =
711+
preferences.getBoolean(context.getString(R.string.treat_all_networks_as_mobile_key),
712+
false);
713+
if (isMeteredNetwork(context) || treatAllNetworksAsMobileData) {
711714
final String defValue = context.getString(R.string.limit_data_usage_none_key);
712715
final String value = preferences.getString(
713716
context.getString(R.string.limit_mobile_data_usage_key), defValue);

app/src/main/res/values/settings_keys.xml

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@
120120
<string name="default_resolution_key">default_resolution</string>
121121
<string name="default_resolution_value">720p60</string>
122122
<string name="show_higher_resolutions_key">show_higher_resolutions</string>
123+
<string name="treat_all_networks_as_mobile_key">treat_all_networks_as_mobile</string>
124+
<string name="auto_ok_download_dialog_key">auto_ok_download_dialog</string>
123125
<string name="default_popup_resolution_key">default_popup_resolution</string>
124126
<string name="default_popup_resolution_value">480p</string>
125127
<string name="best_resolution_key">best_resolution</string>

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
<string name="download_path_audio_dialog_title">Choose download folder for audio files</string>
4646
<string name="default_resolution_title">Default resolution</string>
4747
<string name="default_popup_resolution_title">Default popup resolution</string>
48+
<string name="treat_all_networks_as_mobile_title">Treat all networks as mobile</string>
49+
<string name="auto_ok_download_dialog_title">Automatically OK download dialog</string>
4850
<string name="show_higher_resolutions_title">Show higher resolutions</string>
4951
<string name="show_higher_resolutions_summary">Only some devices can play 2K/4K videos</string>
5052
<string name="play_with_kodi_title">Play with Kodi</string>

app/src/main/res/xml/video_audio_settings.xml

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
app:iconSpaceReserved="false"
3434
app:useSimpleSummaryProvider="true" />
3535

36+
<SwitchPreferenceCompat
37+
android:defaultValue="false"
38+
android:key="@string/treat_all_networks_as_mobile_key"
39+
android:title="@string/treat_all_networks_as_mobile_title"
40+
app:singleLineTitle="false"
41+
app:iconSpaceReserved="false" />
42+
43+
<SwitchPreferenceCompat
44+
android:defaultValue="false"
45+
android:key="@string/auto_ok_download_dialog_key"
46+
android:title="@string/auto_ok_download_dialog_title"
47+
app:singleLineTitle="false"
48+
app:iconSpaceReserved="false" />
49+
3650
<SwitchPreferenceCompat
3751
android:defaultValue="false"
3852
android:key="@string/show_higher_resolutions_key"

0 commit comments

Comments
 (0)