From 6304e31227f42bd65b97af0e30e342d97a9dc98b Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 18 Jan 2019 10:14:21 +0800 Subject: [PATCH] Support mux --- .../shadowsocks/plugin/v2ray/ConfigFragment.kt | 12 ++++++++++++ app/src/main/res/xml/config.xml | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/app/src/main/java/com/github/shadowsocks/plugin/v2ray/ConfigFragment.kt b/app/src/main/java/com/github/shadowsocks/plugin/v2ray/ConfigFragment.kt index b2bfc34..e3a7d02 100644 --- a/app/src/main/java/com/github/shadowsocks/plugin/v2ray/ConfigFragment.kt +++ b/app/src/main/java/com/github/shadowsocks/plugin/v2ray/ConfigFragment.kt @@ -23,6 +23,8 @@ package com.github.shadowsocks.plugin.v2ray import android.app.Activity import android.content.Intent import android.os.Bundle +import android.text.InputFilter +import android.text.InputType import android.view.View import androidx.preference.EditTextPreference import androidx.preference.ListPreference @@ -40,6 +42,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange private val mode by lazy { findPreference("mode") } private val host by lazy { findPreference("host") } private val path by lazy { findPreference("path") } + private val mux by lazy { findPreference("mux") } private val certRaw by lazy { findPreference("certRaw") } private val loglevel by lazy { findPreference("loglevel") } @@ -59,6 +62,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange if (tls) this["tls"] = null putWithDefault("host", host.text, "cloudfront.com") putWithDefault("path", path.text, "/") + putWithDefault("mux", mux.text, "1") putWithDefault("certRaw", certRaw.text?.replace("\n", ""), "") putWithDefault("loglevel", loglevel.value, "warning") } @@ -71,6 +75,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange }.also { onPreferenceChange(null, it) } host.text = options["host"] ?: "cloudfront.com" path.text = options["path"] ?: "/" + mux.text = options["mux"] ?: "1" certRaw.text = options["certRaw"] loglevel.value = options["loglevel"] ?: "warning" } @@ -78,11 +83,18 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.config) mode.onPreferenceChangeListener = this + host.setOnBindEditTextListener { it.inputType = InputType.TYPE_TEXT_VARIATION_URI } + path.setOnBindEditTextListener { it.inputType = InputType.TYPE_TEXT_VARIATION_URI } + mux.setOnBindEditTextListener { + it.inputType = InputType.TYPE_CLASS_NUMBER + it.filters = arrayOf(InputFilter.LengthFilter(4)) + } } override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { val (mode, tls) = readMode(newValue as String) path.isEnabled = mode == null + mux.isEnabled = mode == null certRaw.isEnabled = mode != null || tls return true } diff --git a/app/src/main/res/xml/config.xml b/app/src/main/res/xml/config.xml index 79e474e..8fa2f23 100644 --- a/app/src/main/res/xml/config.xml +++ b/app/src/main/res/xml/config.xml @@ -17,6 +17,11 @@ app:persistent="false" app:title="Path" app:useSimpleSummaryProvider="true"/> +