Remove unsupported proxy types
This commit is contained in:
1 parent
e48f19269f
commit
be761071f8
4 files changed
+17
-18
No files matched your search
@@ -322,8 +322,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
|
||||
HttpClient(CIO) {
|
||||
engine {
|
||||
proxy = when (Settings.getProxyType()) {
|
||||
EhProxySelector.TYPE_DIRECT -> Proxy.NO_PROXY
|
||||
EhProxySelector.TYPE_SYSTEM -> null
|
||||
EhProxySelector.TYPE_HTTP -> {
|
||||
val ip = Settings.getProxyIp()
|
||||
val port = Settings.getProxyPort()
|
||||
@@ -332,7 +330,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
|
||||
Proxy(Proxy.Type.HTTP, socketAddress)
|
||||
}
|
||||
|
||||
// CIO does not support Socks proxy yet
|
||||
// CIO does not support non-HTTP proxy yet
|
||||
else -> null
|
||||
}
|
||||
https {
|
||||
|
||||
@@ -182,7 +182,7 @@ public class Settings {
|
||||
private static final boolean DEFAULT_FRONTING = false;
|
||||
private static final boolean DEFAULT_BYPASS_VPN = true;
|
||||
private static final String KEY_PROXY_TYPE = "proxy_type";
|
||||
private static final int DEFAULT_PROXY_TYPE = EhProxySelector.TYPE_SYSTEM;
|
||||
private static final int DEFAULT_PROXY_TYPE = EhProxySelector.TYPE_DIRECT;
|
||||
private static final String KEY_PROXY_IP = "proxy_ip";
|
||||
private static final String DEFAULT_PROXY_IP = null;
|
||||
private static final String KEY_PROXY_PORT = "proxy_port";
|
||||
@@ -679,10 +679,14 @@ public class Settings {
|
||||
return getBoolean(KEY_BYPASS_VPN, DEFAULT_BYPASS_VPN);
|
||||
}
|
||||
|
||||
public static int getProxyType() {
|
||||
private static int getProxyTypeInternal() {
|
||||
return getInt(KEY_PROXY_TYPE, DEFAULT_PROXY_TYPE);
|
||||
}
|
||||
|
||||
public static int getProxyType() {
|
||||
return getProxyTypeInternal() == EhProxySelector.TYPE_HTTP ? EhProxySelector.TYPE_HTTP : DEFAULT_PROXY_TYPE;
|
||||
}
|
||||
|
||||
public static void putProxyType(int value) {
|
||||
putInt(KEY_PROXY_TYPE, value);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.network.InetValidator
|
||||
import com.hippo.preference.DialogPreference
|
||||
import com.hippo.yorozuya.MathUtils
|
||||
import com.hippo.yorozuya.ViewUtils
|
||||
|
||||
class ProxyPreference @JvmOverloads constructor(
|
||||
@@ -50,8 +49,14 @@ class ProxyPreference @JvmOverloads constructor(
|
||||
updateSummary(Settings.getProxyType(), Settings.getProxyIp(), Settings.getProxyPort())
|
||||
}
|
||||
|
||||
private fun getProxyType(index: Int): Int =
|
||||
if (index == 1) EhProxySelector.TYPE_HTTP else EhProxySelector.TYPE_DIRECT
|
||||
|
||||
private fun getProxyTypeIndex(type: Int): Int =
|
||||
if (type == EhProxySelector.TYPE_HTTP) 1 else 0
|
||||
|
||||
private fun getProxyTypeText(type: Int): String {
|
||||
return mArray[MathUtils.clamp(type, 0, mArray.size - 1)]
|
||||
return mArray[getProxyTypeIndex(type)]
|
||||
}
|
||||
|
||||
private fun updateSummary(type: Int, ip: String?, port: Int) {
|
||||
@@ -59,7 +64,7 @@ class ProxyPreference @JvmOverloads constructor(
|
||||
if ((type1 == EhProxySelector.TYPE_HTTP || type1 == EhProxySelector.TYPE_SOCKS)
|
||||
&& (TextUtils.isEmpty(ip) || !InetValidator.isValidInetPort(port))
|
||||
) {
|
||||
type1 = EhProxySelector.TYPE_SYSTEM
|
||||
type1 = EhProxySelector.TYPE_DIRECT
|
||||
}
|
||||
summary = if (type1 == EhProxySelector.TYPE_HTTP || type1 == EhProxySelector.TYPE_SOCKS) {
|
||||
val context = context
|
||||
@@ -94,13 +99,7 @@ class ProxyPreference @JvmOverloads constructor(
|
||||
mPortInputLayout = ViewUtils.`$$`(dialog, R.id.port_input_layout) as TextInputLayout
|
||||
mPort = ViewUtils.`$$`(dialog, R.id.port) as EditText
|
||||
val type = Settings.getProxyType()
|
||||
(mType!!.editText as AutoCompleteTextView).setText(
|
||||
array[MathUtils.clamp(
|
||||
type,
|
||||
0,
|
||||
array.size
|
||||
)], false
|
||||
)
|
||||
(mType!!.editText as AutoCompleteTextView).setText(array[getProxyTypeIndex(type)], false)
|
||||
mIp!!.setText(Settings.getProxyIp())
|
||||
val portString: String?
|
||||
val port = Settings.getProxyPort()
|
||||
@@ -127,7 +126,7 @@ class ProxyPreference @JvmOverloads constructor(
|
||||
if (null == dialog || null == mType || null == mIpInputLayout || null == mIp || null == mPortInputLayout || null == mPort) {
|
||||
return
|
||||
}
|
||||
val type = mArray.indexOf(mType!!.editText!!.text.toString())
|
||||
val type = getProxyType(mArray.indexOf(mType!!.editText!!.text.toString()))
|
||||
val ip = mIp!!.text.toString().trim { it <= ' ' }
|
||||
if (ip.isEmpty()) {
|
||||
if (type == EhProxySelector.TYPE_HTTP || type == EhProxySelector.TYPE_SOCKS) {
|
||||
|
||||
@@ -222,9 +222,7 @@
|
||||
|
||||
<string-array name="proxy_types">
|
||||
<item>@string/proxy_direct</item>
|
||||
<item>@string/proxy_system</item>
|
||||
<item>HTTP</item>
|
||||
<item>SOCKS</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="night_mode_entries" translatable="false">
|
||||
|
||||
Reference in new issue
Block a user