diff --git a/src/main/scala/com/github/shadowsocks/AppManager.scala b/src/main/scala/com/github/shadowsocks/AppManager.scala index 54d9ea33b6..0be21374a8 100644 --- a/src/main/scala/com/github/shadowsocks/AppManager.scala +++ b/src/main/scala/com/github/shadowsocks/AppManager.scala @@ -163,7 +163,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { case R.id.action_apply_all => app.profileManager.getAllProfiles match { case Some(profiles) => - val proxiedAppString = prefs.getString(Key.proxied, "") + val proxiedAppString = prefs.getString(Key.individual, "") profiles.foreach(profile => { profile.individual = proxiedAppString app.profileManager.updateProfile(profile) @@ -173,9 +173,9 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { } return true case R.id.action_export => - val bypass = prefs.getBoolean(Key.isBypassApps, false) - val proxiedAppString = prefs.getString(Key.proxied, "") - val clip = ClipData.newPlainText(Key.proxied, bypass + "\n" + proxiedAppString) + val bypass = prefs.getBoolean(Key.bypass, false) + val proxiedAppString = prefs.getString(Key.individual, "") + val clip = ClipData.newPlainText(Key.individual, bypass + "\n" + proxiedAppString) clipboard.setPrimaryClip(clip) Toast.makeText(this, R.string.action_export_msg, Toast.LENGTH_SHORT).show() return true @@ -191,7 +191,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { val (enabled, apps) = if (i < 0) (proxiedAppString, "") else (proxiedAppString.substring(0, i), proxiedAppString.substring(i + 1)) bypassSwitch.setChecked(enabled.toBoolean) - editor.putString(Key.proxied, apps).apply() + editor.putString(Key.individual, apps).apply() Toast.makeText(this, R.string.action_import_msg, Toast.LENGTH_SHORT).show() appListView.setVisibility(View.GONE) loadingView.setVisibility(View.VISIBLE) diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index 61c410c6f5..63907dbaa5 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -405,7 +405,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { fab = findViewById(R.id.fab).asInstanceOf[FloatingActionButton] fabProgressCircle = findViewById(R.id.fabProgressCircle).asInstanceOf[FABProgressCircle] fab.setOnClickListener(_ => if (serviceStarted) serviceStop() - else if (checkText(Key.proxy) && checkText(Key.sitekey) && bgService != null) prepareStartService() + else if (checkText(Key.host) && checkText(Key.password) && bgService != null) prepareStartService() else changeSwitch(checked = false)) fab.setOnLongClickListener((v: View) => { Utils.positionToast(Toast.makeText(this, if (serviceStarted) R.string.stop else R.string.connect, diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala index 200606dcd5..71699eb41c 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala @@ -83,8 +83,8 @@ class ShadowsocksApplication extends Application { .setLabel(getVersionName) .build()) - def profileId = settings.getInt(Key.profileId, -1) - def profileId(i: Int) = editor.putInt(Key.profileId, i).apply + def profileId = settings.getInt(Key.id, -1) + def profileId(i: Int) = editor.putInt(Key.id, i).apply def currentProfile = profileManager.getProfile(profileId) def switchProfile(id: Int) = { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala index 4f50faaa8d..cfa2c7813e 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala @@ -17,9 +17,9 @@ import com.github.shadowsocks.utils.{Key, Utils} object ShadowsocksSettings { // Constants private final val TAG = "ShadowsocksSettings" - private val PROXY_PREFS = Array(Key.profileName, Key.proxy, Key.remotePort, Key.localPort, Key.sitekey, Key.encMethod, - Key.isAuth) - private val FEATURE_PREFS = Array(Key.route, Key.isProxyApps, Key.isUdpDns, Key.isIpv6) + private val PROXY_PREFS = Array(Key.name, Key.host, Key.remotePort, Key.localPort, Key.password, Key.method, + Key.auth) + private val FEATURE_PREFS = Array(Key.route, Key.proxyApps, Key.udpdns, Key.ipv6) // Helper functions def updateDropDownPreference(pref: Preference, value: String) { @@ -46,17 +46,17 @@ object ShadowsocksSettings { def updatePreference(pref: Preference, name: String, profile: Profile) { name match { - case Key.profileName => updateSummaryEditTextPreference(pref, profile.name) - case Key.proxy => updateSummaryEditTextPreference(pref, profile.host) + case Key.name => updateSummaryEditTextPreference(pref, profile.name) + case Key.host => updateSummaryEditTextPreference(pref, profile.host) case Key.remotePort => updateNumberPickerPreference(pref, profile.remotePort) case Key.localPort => updateNumberPickerPreference(pref, profile.localPort) - case Key.sitekey => updatePasswordEditTextPreference(pref, profile.password) - case Key.encMethod => updateDropDownPreference(pref, profile.method) + case Key.password => updatePasswordEditTextPreference(pref, profile.password) + case Key.method => updateDropDownPreference(pref, profile.method) case Key.route => updateDropDownPreference(pref, profile.route) - case Key.isProxyApps => updateSwitchPreference(pref, profile.proxyApps) - case Key.isUdpDns => updateSwitchPreference(pref, profile.udpdns) - case Key.isAuth => updateSwitchPreference(pref, profile.auth) - case Key.isIpv6 => updateSwitchPreference(pref, profile.ipv6) + case Key.proxyApps => updateSwitchPreference(pref, profile.proxyApps) + case Key.udpdns => updateSwitchPreference(pref, profile.udpdns) + case Key.auth => updateSwitchPreference(pref, profile.auth) + case Key.ipv6 => updateSwitchPreference(pref, profile.ipv6) } } } @@ -74,11 +74,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan addPreferencesFromResource(R.xml.pref_all) getPreferenceManager.getSharedPreferences.registerOnSharedPreferenceChangeListener(this) - findPreference(Key.profileName).setOnPreferenceChangeListener((_, value) => { + findPreference(Key.name).setOnPreferenceChangeListener((_, value) => { profile.name = value.asInstanceOf[String] app.profileManager.updateProfile(profile) }) - findPreference(Key.proxy).setOnPreferenceChangeListener((_, value) => { + findPreference(Key.host).setOnPreferenceChangeListener((_, value) => { profile.host = value.asInstanceOf[String] app.profileManager.updateProfile(profile) }) @@ -90,11 +90,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan profile.localPort = value.asInstanceOf[Int] app.profileManager.updateProfile(profile) }) - findPreference(Key.sitekey).setOnPreferenceChangeListener((_, value) => { + findPreference(Key.password).setOnPreferenceChangeListener((_, value) => { profile.password = value.asInstanceOf[String] app.profileManager.updateProfile(profile) }) - findPreference(Key.encMethod).setOnPreferenceChangeListener((_, value) => { + findPreference(Key.method).setOnPreferenceChangeListener((_, value) => { profile.method = value.asInstanceOf[String] app.profileManager.updateProfile(profile) }) @@ -103,7 +103,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan app.profileManager.updateProfile(profile) }) - isProxyApps = findPreference(Key.isProxyApps).asInstanceOf[SwitchPreference] + isProxyApps = findPreference(Key.proxyApps).asInstanceOf[SwitchPreference] isProxyApps.setOnPreferenceClickListener(_ => { startActivity(new Intent(activity, classOf[AppManager])) isProxyApps.setChecked(true) @@ -114,15 +114,15 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan app.profileManager.updateProfile(profile) }) - findPreference(Key.isUdpDns).setOnPreferenceChangeListener((_, value) => { + findPreference(Key.udpdns).setOnPreferenceChangeListener((_, value) => { profile.udpdns = value.asInstanceOf[Boolean] app.profileManager.updateProfile(profile) }) - findPreference(Key.isAuth).setOnPreferenceChangeListener((_, value) => { + findPreference(Key.auth).setOnPreferenceChangeListener((_, value) => { profile.auth = value.asInstanceOf[Boolean] app.profileManager.updateProfile(profile) }) - findPreference(Key.isIpv6).setOnPreferenceChangeListener((_, value) => { + findPreference(Key.ipv6).setOnPreferenceChangeListener((_, value) => { profile.ipv6 = value.asInstanceOf[Boolean] app.profileManager.updateProfile(profile) }) @@ -202,7 +202,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan for (name <- Key.isNAT #:: PROXY_PREFS.toStream #::: FEATURE_PREFS.toStream) { val pref = findPreference(name) if (pref != null) pref.setEnabled(enabled && - (name != Key.isProxyApps || Utils.isLollipopOrAbove || app.isNatEnabled)) + (name != Key.proxyApps || Utils.isLollipopOrAbove || app.isNatEnabled)) } } diff --git a/src/main/scala/com/github/shadowsocks/utils/Constants.scala b/src/main/scala/com/github/shadowsocks/utils/Constants.scala index 808dab5588..ef784116cd 100644 --- a/src/main/scala/com/github/shadowsocks/utils/Constants.scala +++ b/src/main/scala/com/github/shadowsocks/utils/Constants.scala @@ -143,25 +143,25 @@ object ConfigUtils { } object Key { - val profileId = "profileId" - val profileName = "profileName" + val id = "profileId" + val name = "profileName" - val proxied = "Proxyed" + val individual = "Proxyed" val isNAT = "isNAT" val route = "route" val isAutoConnect = "isAutoConnect" - val isProxyApps = "isProxyApps" - val isBypassApps = "isBypassApps" - val isUdpDns = "isUdpDns" - val isAuth = "isAuth" - val isIpv6 = "isIpv6" + val proxyApps = "isProxyApps" + val bypass = "isBypassApps" + val udpdns = "isUdpDns" + val auth = "isAuth" + val ipv6 = "isIpv6" - val proxy = "proxy" - val sitekey = "sitekey" - val encMethod = "encMethod" + val host = "proxy" + val password = "sitekey" + val method = "encMethod" val remotePort = "remotePortNum" val localPort = "localPortNum"