Revert "Remove unsupported proxy types"

This reverts commit be761071f8.
This commit is contained in:
tarsin committed 2023-02-13 17:27:07 +08:00
1 parent d6939b2913
commit 388685b784
4 files changed
+18 -17

No files matched your search

@@ -315,6 +315,8 @@ 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()
@@ -323,7 +325,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
Proxy(Proxy.Type.HTTP, socketAddress)
}
// CIO does not support non-HTTP proxy yet
// CIO does not support Socks proxy yet
else -> null
}
https {
@@ -196,7 +196,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_DIRECT;
private static final int DEFAULT_PROXY_TYPE = EhProxySelector.TYPE_SYSTEM;
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";
@@ -692,12 +692,8 @@ public class Settings {
return getBoolean(KEY_BYPASS_VPN, DEFAULT_BYPASS_VPN);
}
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;
return getInt(KEY_PROXY_TYPE, DEFAULT_PROXY_TYPE);
}
public static void putProxyType(int value) {
@@ -31,6 +31,7 @@ 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(
@@ -49,14 +50,8 @@ 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[getProxyTypeIndex(type)]
return mArray[MathUtils.clamp(type, 0, mArray.size - 1)]
}
private fun updateSummary(type: Int, ip: String?, port: Int) {
@@ -64,7 +59,7 @@ class ProxyPreference @JvmOverloads constructor(
if ((type1 == EhProxySelector.TYPE_HTTP || type1 == EhProxySelector.TYPE_SOCKS)
&& (TextUtils.isEmpty(ip) || !InetValidator.isValidInetPort(port))
) {
type1 = EhProxySelector.TYPE_DIRECT
type1 = EhProxySelector.TYPE_SYSTEM
}
summary = if (type1 == EhProxySelector.TYPE_HTTP || type1 == EhProxySelector.TYPE_SOCKS) {
val context = context
@@ -99,7 +94,13 @@ 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[getProxyTypeIndex(type)], false)
(mType!!.editText as AutoCompleteTextView).setText(
array[MathUtils.clamp(
type,
0,
array.size
)], false
)
mIp!!.setText(Settings.getProxyIp())
val portString: String?
val port = Settings.getProxyPort()
@@ -126,7 +127,7 @@ class ProxyPreference @JvmOverloads constructor(
if (null == dialog || null == mType || null == mIpInputLayout || null == mIp || null == mPortInputLayout || null == mPort) {
return
}
val type = getProxyType(mArray.indexOf(mType!!.editText!!.text.toString()))
val type = 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) {
+2
View File
@@ -224,7 +224,9 @@
<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">