Merge pull request #3303 from rezanejati/develop

Add socks proxy in network settings
This commit is contained in:
H. Lehmann 2019-08-11 10:19:52 +02:00 committed by GitHub
commit 3ceb99d2e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Build;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
@ -23,6 +24,8 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
@ -92,8 +95,12 @@ public class ProxyDialog {
if(!TextUtils.isEmpty(port)) { if(!TextUtils.isEmpty(port)) {
portValue = Integer.valueOf(port); portValue = Integer.valueOf(port);
} }
if (Proxy.Type.valueOf(type) == Proxy.Type.SOCKS) {
proxy = ProxyConfig.socks(host, portValue, username, password);
} else {
proxy = ProxyConfig.http(host, portValue, username, password); proxy = ProxyConfig.http(host, portValue, username, password);
} }
}
UserPreferences.setProxyConfig(proxy); UserPreferences.setProxyConfig(proxy);
AntennapodHttpClient.reinit(); AntennapodHttpClient.reinit();
dialog.dismiss(); dialog.dismiss();
@ -103,7 +110,13 @@ public class ProxyDialog {
.build(); .build();
View view = dialog.getCustomView(); View view = dialog.getCustomView();
spType = view.findViewById(R.id.spType); spType = view.findViewById(R.id.spType);
String[] types = { Proxy.Type.DIRECT.name(), Proxy.Type.HTTP.name() };
List<String> types= new ArrayList<>();
types.add(Proxy.Type.DIRECT.name());
types.add(Proxy.Type.HTTP.name());
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
types.add(Proxy.Type.SOCKS.name());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(context, ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
android.R.layout.simple_spinner_item, types); android.R.layout.simple_spinner_item, types);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

View File

@ -22,6 +22,10 @@ public class ProxyConfig {
return new ProxyConfig(Proxy.Type.HTTP, host, port, username, password); return new ProxyConfig(Proxy.Type.HTTP, host, port, username, password);
} }
public static ProxyConfig socks(String host, int port, String username, String password) {
return new ProxyConfig(Proxy.Type.SOCKS, host, port, username, password);
}
public ProxyConfig(Proxy.Type type, String host, int port, String username, String password) { public ProxyConfig(Proxy.Type type, String host, int port, String username, String password) {
this.type = type; this.type = type;
this.host = host; this.host = host;