mirror of
https://github.com/bilde2910/Hauk.git
synced 2026-01-23 10:25:39 +00:00
Refactor proxy TypeIndexResolver
This commit is contained in:
parent
4f1ac92b9a
commit
e51d628fe8
5 changed files with 15 additions and 13 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package info.varden.hauk;
|
||||
|
||||
import info.varden.hauk.system.preferences.indexresolver.ProxyTypeResolver;
|
||||
import info.varden.hauk.struct.Version;
|
||||
import info.varden.hauk.system.preferences.Preference;
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ public enum Constants {
|
|||
|
||||
// Keys for use in stored server preferences.
|
||||
public static final Preference<String> PREF_SERVER_ENCRYPTED = new Preference.EncryptedString("cryptServer", "");
|
||||
public static final Preference<Integer> PREF_PROXY_TYPE = new Preference.Integer("proxyType", 0);
|
||||
public static final Preference<Integer> PREF_PROXY_TYPE = new Preference.Integer("proxyType", ProxyTypeResolver.SYSTEM_DEFAULT.getIndex());
|
||||
public static final Preference<String> PREF_PROXY_HOST = new Preference.String("proxyHost", "localhost");
|
||||
public static final Preference<Integer> PREF_PROXY_PORT = new Preference.Integer("proxyPort", 9050);
|
||||
public static final Preference<Integer> PREF_CONNECTION_TIMEOUT = new Preference.Integer("connectTimeout", 10);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import info.varden.hauk.global.ui.toast.SessionInitiationResponseHandlerImpl;
|
|||
import info.varden.hauk.global.ui.toast.ShareListenerImpl;
|
||||
import info.varden.hauk.http.ConnectionParameters;
|
||||
import info.varden.hauk.http.SessionInitiationPacket;
|
||||
import info.varden.hauk.http.proxy.TypeIndexResolver;
|
||||
import info.varden.hauk.system.preferences.indexresolver.ProxyTypeResolver;
|
||||
import info.varden.hauk.manager.SessionManager;
|
||||
import info.varden.hauk.struct.AdoptabilityPreference;
|
||||
import info.varden.hauk.system.LocationPermissionsNotGrantedException;
|
||||
|
|
@ -189,7 +189,7 @@ public final class Receiver extends BroadcastReceiver {
|
|||
|
||||
int timeout = fallback.get(Constants.PREF_CONNECTION_TIMEOUT) * (int) TimeUtils.MILLIS_PER_SECOND;
|
||||
ConnectionParameters connParams;
|
||||
Proxy.Type proxyType = TypeIndexResolver.fromIndex(fallback.get(Constants.PREF_PROXY_TYPE)).getProxyType();
|
||||
Proxy.Type proxyType = ProxyTypeResolver.fromIndex(fallback.get(Constants.PREF_PROXY_TYPE)).getProxyType();
|
||||
if (proxyType == Proxy.Type.DIRECT) {
|
||||
connParams = new ConnectionParameters(Proxy.NO_PROXY.type(), Proxy.NO_PROXY.address(), timeout);
|
||||
} else if (proxyType != null) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.net.Proxy;
|
|||
import info.varden.hauk.Constants;
|
||||
import info.varden.hauk.http.FailureHandler;
|
||||
import info.varden.hauk.system.preferences.PreferenceManager;
|
||||
import info.varden.hauk.system.preferences.indexresolver.ProxyTypeResolver;
|
||||
import info.varden.hauk.utils.Log;
|
||||
|
||||
/**
|
||||
|
|
@ -50,7 +51,7 @@ public abstract class NameResolverTask extends AsyncTask<Void, Void, Proxy> impl
|
|||
private boolean wasSuccessful = true;
|
||||
|
||||
protected NameResolverTask(PreferenceManager prefs) {
|
||||
this.proxyType = TypeIndexResolver.fromIndex(prefs.get(Constants.PREF_PROXY_TYPE)).getProxyType();
|
||||
this.proxyType = ProxyTypeResolver.fromIndex(prefs.get(Constants.PREF_PROXY_TYPE)).getProxyType();
|
||||
this.proxyHost = prefs.get(Constants.PREF_PROXY_HOST).trim();
|
||||
this.proxyPort = prefs.get(Constants.PREF_PROXY_PORT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package info.varden.hauk.http.proxy;
|
||||
package info.varden.hauk.system.preferences.indexresolver;
|
||||
|
||||
import java.net.Proxy;
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ import java.net.Proxy;
|
|||
*
|
||||
* @author Marius Lindvall
|
||||
*/
|
||||
public enum TypeIndexResolver {
|
||||
public enum ProxyTypeResolver {
|
||||
SYSTEM_DEFAULT(0, null),
|
||||
DIRECT(1, Proxy.Type.DIRECT),
|
||||
HTTP(2, Proxy.Type.HTTP),
|
||||
|
|
@ -24,7 +24,7 @@ public enum TypeIndexResolver {
|
|||
*/
|
||||
private final Proxy.Type type;
|
||||
|
||||
TypeIndexResolver(int index, Proxy.Type type) {
|
||||
ProxyTypeResolver(int index, Proxy.Type type) {
|
||||
this.index = index;
|
||||
this.type = type;
|
||||
}
|
||||
|
|
@ -36,16 +36,16 @@ public enum TypeIndexResolver {
|
|||
* @return A proxy type enum member.
|
||||
* @throws EnumConstantNotPresentException if there is no matching type for the given index.
|
||||
*/
|
||||
public static TypeIndexResolver fromIndex(int index) throws EnumConstantNotPresentException {
|
||||
for (TypeIndexResolver type : TypeIndexResolver.values()) {
|
||||
public static ProxyTypeResolver fromIndex(int index) throws EnumConstantNotPresentException {
|
||||
for (ProxyTypeResolver type : ProxyTypeResolver.values()) {
|
||||
if (type.getIndex() == index) return type;
|
||||
}
|
||||
throw new EnumConstantNotPresentException(TypeIndexResolver.class, "index=" + index);
|
||||
throw new EnumConstantNotPresentException(ProxyTypeResolver.class, "index=" + index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TypeIndexResolver{index=" + this.index + ",type=" + this.type + "}";
|
||||
return "ProxyTypeResolver{index=" + this.index + ",type=" + this.type + "}";
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
|
|
@ -2,7 +2,7 @@ package info.varden.hauk.system.preferences.ui.listener;
|
|||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import info.varden.hauk.http.proxy.TypeIndexResolver;
|
||||
import info.varden.hauk.system.preferences.indexresolver.ProxyTypeResolver;
|
||||
|
||||
/**
|
||||
* Value change listener for the proxy type selection preference that disables the other proxy
|
||||
|
|
@ -20,7 +20,7 @@ public final class ProxyPreferenceChangeListener implements Preference.OnPrefere
|
|||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int choice = Integer.valueOf((String) newValue);
|
||||
boolean enable = choice != TypeIndexResolver.SYSTEM_DEFAULT.getIndex() && choice != TypeIndexResolver.DIRECT.getIndex();
|
||||
boolean enable = choice != ProxyTypeResolver.SYSTEM_DEFAULT.getIndex() && choice != ProxyTypeResolver.DIRECT.getIndex();
|
||||
for (Preference pref : this.prefsToDisable) {
|
||||
pref.setEnabled(enable);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue