Merge pull request #3303 from rezanejati/develop
Add socks proxy in network settings
This commit is contained in:
commit
3ceb99d2e2
|
@ -3,6 +3,7 @@ package de.danoeh.antennapod.dialog;
|
|||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
|
@ -23,6 +24,8 @@ import java.io.IOException;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
|
@ -92,7 +95,11 @@ public class ProxyDialog {
|
|||
if(!TextUtils.isEmpty(port)) {
|
||||
portValue = Integer.valueOf(port);
|
||||
}
|
||||
proxy = ProxyConfig.http(host, portValue, username, password);
|
||||
if (Proxy.Type.valueOf(type) == Proxy.Type.SOCKS) {
|
||||
proxy = ProxyConfig.socks(host, portValue, username, password);
|
||||
} else {
|
||||
proxy = ProxyConfig.http(host, portValue, username, password);
|
||||
}
|
||||
}
|
||||
UserPreferences.setProxyConfig(proxy);
|
||||
AntennapodHttpClient.reinit();
|
||||
|
@ -103,7 +110,13 @@ public class ProxyDialog {
|
|||
.build();
|
||||
View view = dialog.getCustomView();
|
||||
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,
|
||||
android.R.layout.simple_spinner_item, types);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
|
|
|
@ -22,6 +22,10 @@ public class ProxyConfig {
|
|||
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) {
|
||||
this.type = type;
|
||||
this.host = host;
|
||||
|
@ -29,4 +33,4 @@ public class ProxyConfig {
|
|||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue