Skip to content

Commit 2d1823f

Browse files
committed
PR#12691 fix by remarks
1 parent 78506f0 commit 2d1823f

14 files changed

Lines changed: 107 additions & 61 deletions

File tree

app/src/main/java/org/schabi/newpipe/DownloaderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.schabi.newpipe.extractor.downloader.Request;
1212
import org.schabi.newpipe.extractor.downloader.Response;
1313
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
14-
import org.schabi.newpipe.settings.ProxyManager;
14+
import org.schabi.newpipe.util.ProxyManager;
1515
import org.schabi.newpipe.util.InfoCache;
1616

1717
import java.io.IOException;

app/src/main/java/org/schabi/newpipe/player/datasource/YoutubeHttpDataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import com.google.common.net.HttpHeaders;
4747

4848
import org.schabi.newpipe.DownloaderImpl;
49-
import org.schabi.newpipe.settings.ProxyManager;
49+
import org.schabi.newpipe.util.ProxyManager;
5050

5151
import java.io.IOException;
5252
import java.io.InputStream;

app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
1919
import com.google.android.exoplayer2.upstream.DataSource;
2020
import com.google.android.exoplayer2.upstream.DefaultDataSource;
21-
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
2221
import com.google.android.exoplayer2.upstream.TransferListener;
2322
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
2423
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
2524

26-
import org.schabi.newpipe.DownloaderImpl;
2725
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreators.YoutubeOtfDashManifestCreator;
2826
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreators.YoutubePostLiveStreamDvrDashManifestCreator;
2927
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreators.YoutubeProgressiveDashManifestCreator;
@@ -86,12 +84,14 @@ public PlayerDataSource(final Context context,
8684
// make sure the static cache was created: needed by CacheFactories below
8785
instantiateCacheIfNeeded(context);
8886

89-
// generic data source factories use DefaultHttpDataSource.Factory
87+
// generic data source factories now use YoutubeHttpDataSource.Factory to support proxies
88+
final YoutubeHttpDataSource.Factory youtubeHttpDataSourceFactory =
89+
getYoutubeHttpDataSourceFactory(context, false, false);
9090
cachelessDataSourceFactory = new DefaultDataSource.Factory(context,
91-
new DefaultHttpDataSource.Factory().setUserAgent(DownloaderImpl.USER_AGENT))
91+
youtubeHttpDataSourceFactory)
9292
.setTransferListener(transferListener);
9393
cacheDataSourceFactory = new CacheFactory(context, transferListener, cache,
94-
new DefaultHttpDataSource.Factory().setUserAgent(DownloaderImpl.USER_AGENT));
94+
youtubeHttpDataSourceFactory);
9595

9696
// YouTube-specific data source factories use getYoutubeHttpDataSourceFactory()
9797
ytHlsCacheDataSourceFactory = new CacheFactory(context, transferListener, cache,
Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,70 @@
11
package org.schabi.newpipe.settings;
22

3+
import android.app.Activity;
4+
import android.app.AlertDialog;
5+
import android.content.SharedPreferences;
36
import android.os.Bundle;
4-
57
import androidx.annotation.Nullable;
6-
import androidx.preference.ListPreference;
7-
88
import org.schabi.newpipe.R;
9+
import org.schabi.newpipe.util.NavigationHelper;
910

1011
/**
1112
* A fragment that displays proxy settings.
1213
*/
1314
public class ProxySettingsFragment extends BasePreferenceFragment {
1415

16+
private boolean preferencesChanged = false;
17+
private SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener;
18+
1519
@Override
1620
public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
1721
@Nullable final String rootKey) {
18-
addPreferencesFromResource(R.xml.proxy_settings);
22+
//addPreferencesFromResource(R.xml.proxy_settings);
23+
addPreferencesFromResourceRegistry();
24+
preferenceChangeListener = (sharedPreferences, key) -> {
25+
preferencesChanged = true;
26+
};
27+
getPreferenceScreen().getSharedPreferences()
28+
.registerOnSharedPreferenceChangeListener(preferenceChangeListener);
29+
}
30+
31+
@Override
32+
public void onStop() {
33+
super.onStop();
34+
if (preferencesChanged && getActivity() != null && !getActivity().isFinishing()) {
35+
showRestartDialog();
36+
}
37+
}
38+
39+
private void showRestartDialog() {
40+
// Show Alert Dialogue
41+
final Activity activity = getActivity();
42+
if (activity == null) {
43+
return;
44+
}
45+
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
46+
builder.setMessage(R.string.restart_app_message);
47+
builder.setTitle(R.string.restart_app_title);
48+
builder.setCancelable(true);
49+
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
50+
// Restarts the app
51+
if (activity == null) {
52+
return;
53+
}
54+
NavigationHelper.restartApp(activity);
55+
});
56+
builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
57+
});
58+
final android.app.AlertDialog alertDialog = builder.create();
59+
alertDialog.show();
60+
}
1961

20-
final ListPreference proxyTypePreference = findPreference("proxy_type");
21-
if (proxyTypePreference != null) {
22-
proxyTypePreference.setSummaryProvider(
23-
ListPreference.SimpleSummaryProvider.getInstance());
62+
@Override
63+
public void onDestroy() {
64+
super.onDestroy();
65+
if (preferenceChangeListener != null && getPreferenceScreen() != null) {
66+
getPreferenceScreen().getSharedPreferences()
67+
.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener);
2468
}
2569
}
2670
}

app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private SettingsResourceRegistry() {
4242
add(VideoAudioSettingsFragment.class, R.xml.video_audio_settings);
4343
add(ExoPlayerSettingsFragment.class, R.xml.exoplayer_settings);
4444
add(BackupRestoreSettingsFragment.class, R.xml.backup_restore_settings);
45+
add(ProxySettingsFragment.class, R.xml.proxy_settings);
4546
}
4647

4748
private SettingRegistryEntry add(

app/src/main/java/org/schabi/newpipe/settings/ProxyManager.java renamed to app/src/main/java/org/schabi/newpipe/util/ProxyManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.schabi.newpipe.settings;
1+
package org.schabi.newpipe.util;
22

33
import android.content.Context;
44
import android.content.SharedPreferences;

app/src/main/java/org/schabi/newpipe/util/image/PicassoHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.schabi.newpipe.R;
2525
import org.schabi.newpipe.extractor.Image;
26-
import org.schabi.newpipe.settings.ProxyManager;
26+
import org.schabi.newpipe.util.ProxyManager;
2727

2828
import java.io.File;
2929
import java.io.IOException;

app/src/main/java/us/shandian/giga/get/DownloadMission.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package us.shandian.giga.get;
22

3+
import android.content.Context;
34
import android.os.Handler;
45
import android.system.ErrnoException;
56
import android.system.OsConstants;
@@ -17,6 +18,7 @@
1718
import java.io.Serializable;
1819
import java.net.ConnectException;
1920
import java.net.HttpURLConnection;
21+
import java.net.Proxy;
2022
import java.net.SocketTimeoutException;
2123
import java.net.URL;
2224
import java.net.UnknownHostException;
@@ -25,6 +27,7 @@
2527

2628
import javax.net.ssl.SSLException;
2729

30+
import org.schabi.newpipe.util.ProxyManager;
2831
import org.schabi.newpipe.streams.io.StoredFileHelper;
2932
import us.shandian.giga.postprocessing.Postprocessing;
3033
import us.shandian.giga.service.DownloadManagerService;
@@ -34,7 +37,7 @@
3437

3538
public class DownloadMission extends Mission {
3639
private static final long serialVersionUID = 6L;// last bump: 07 october 2019
37-
40+
private final Context context;
3841
static final int BUFFER_SIZE = 64 * 1024;
3942
static final int BLOCK_SIZE = 512 * 1024;
4043

@@ -153,9 +156,10 @@ public class DownloadMission extends Mission {
153156
public transient Thread[] threads = new Thread[0];
154157
public transient Thread init = null;
155158

156-
public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) {
159+
public DownloadMission(final Context context, String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) {
157160
if (Objects.requireNonNull(urls).length < 1)
158161
throw new IllegalArgumentException("urls array is empty");
162+
this.context = context;
159163
this.urls = urls;
160164
this.kind = kind;
161165
this.offsets = new long[urls.length];
@@ -164,6 +168,7 @@ public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postp
164168
this.storage = storage;
165169
this.psAlgorithm = psInstance;
166170

171+
167172
if (DEBUG && psInstance == null && urls.length > 1) {
168173
Log.w(TAG, "mission created with multiple urls ¿missing post-processing algorithm?");
169174
}
@@ -219,7 +224,14 @@ HttpURLConnection openConnection(boolean headRequest, long rangeStart, long rang
219224
}
220225

221226
HttpURLConnection openConnection(String url, boolean headRequest, long rangeStart, long rangeEnd) throws IOException {
222-
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
227+
final ProxyManager proxyManager = new ProxyManager(context);
228+
final Proxy proxy = proxyManager.getProxy();
229+
final HttpURLConnection conn;
230+
if (proxy != null) {
231+
conn = (HttpURLConnection) new URL(url).openConnection(proxy);
232+
} else {
233+
conn = (HttpURLConnection) new URL(url).openConnection();
234+
}
223235
conn.setInstanceFollowRedirects(true);
224236
conn.setRequestProperty("User-Agent", DownloaderImpl.USER_AGENT);
225237
conn.setRequestProperty("Accept", "*/*");

app/src/main/java/us/shandian/giga/service/DownloadManagerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private void startMission(Intent intent) {
408408
else
409409
ps = Postprocessing.getAlgorithm(psName, psArgs, streamInfo);
410410

411-
final DownloadMission mission = new DownloadMission(urls, storage, kind, ps);
411+
final DownloadMission mission = new DownloadMission(this, urls, storage, kind, ps);
412412
mission.threadCount = threads;
413413
mission.source = streamInfo.getUrl();
414414
mission.nearLength = nearLength;

app/src/main/res/menu/main_menu.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)