Commit 07eb4d2a authored by Mygod's avatar Mygod

Refine utils.Key for readability

parent c480137d
...@@ -163,7 +163,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { ...@@ -163,7 +163,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener {
case R.id.action_apply_all => case R.id.action_apply_all =>
app.profileManager.getAllProfiles match { app.profileManager.getAllProfiles match {
case Some(profiles) => case Some(profiles) =>
val proxiedAppString = prefs.getString(Key.proxied, "") val proxiedAppString = prefs.getString(Key.individual, "")
profiles.foreach(profile => { profiles.foreach(profile => {
profile.individual = proxiedAppString profile.individual = proxiedAppString
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
...@@ -173,9 +173,9 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { ...@@ -173,9 +173,9 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener {
} }
return true return true
case R.id.action_export => case R.id.action_export =>
val bypass = prefs.getBoolean(Key.isBypassApps, false) val bypass = prefs.getBoolean(Key.bypass, false)
val proxiedAppString = prefs.getString(Key.proxied, "") val proxiedAppString = prefs.getString(Key.individual, "")
val clip = ClipData.newPlainText(Key.proxied, bypass + "\n" + proxiedAppString) val clip = ClipData.newPlainText(Key.individual, bypass + "\n" + proxiedAppString)
clipboard.setPrimaryClip(clip) clipboard.setPrimaryClip(clip)
Toast.makeText(this, R.string.action_export_msg, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.action_export_msg, Toast.LENGTH_SHORT).show()
return true return true
...@@ -191,7 +191,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { ...@@ -191,7 +191,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener {
val (enabled, apps) = if (i < 0) (proxiedAppString, "") val (enabled, apps) = if (i < 0) (proxiedAppString, "")
else (proxiedAppString.substring(0, i), proxiedAppString.substring(i + 1)) else (proxiedAppString.substring(0, i), proxiedAppString.substring(i + 1))
bypassSwitch.setChecked(enabled.toBoolean) 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() Toast.makeText(this, R.string.action_import_msg, Toast.LENGTH_SHORT).show()
appListView.setVisibility(View.GONE) appListView.setVisibility(View.GONE)
loadingView.setVisibility(View.VISIBLE) loadingView.setVisibility(View.VISIBLE)
......
...@@ -405,7 +405,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -405,7 +405,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
fab = findViewById(R.id.fab).asInstanceOf[FloatingActionButton] fab = findViewById(R.id.fab).asInstanceOf[FloatingActionButton]
fabProgressCircle = findViewById(R.id.fabProgressCircle).asInstanceOf[FABProgressCircle] fabProgressCircle = findViewById(R.id.fabProgressCircle).asInstanceOf[FABProgressCircle]
fab.setOnClickListener(_ => if (serviceStarted) serviceStop() 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)) else changeSwitch(checked = false))
fab.setOnLongClickListener((v: View) => { fab.setOnLongClickListener((v: View) => {
Utils.positionToast(Toast.makeText(this, if (serviceStarted) R.string.stop else R.string.connect, Utils.positionToast(Toast.makeText(this, if (serviceStarted) R.string.stop else R.string.connect,
......
...@@ -83,8 +83,8 @@ class ShadowsocksApplication extends Application { ...@@ -83,8 +83,8 @@ class ShadowsocksApplication extends Application {
.setLabel(getVersionName) .setLabel(getVersionName)
.build()) .build())
def profileId = settings.getInt(Key.profileId, -1) def profileId = settings.getInt(Key.id, -1)
def profileId(i: Int) = editor.putInt(Key.profileId, i).apply def profileId(i: Int) = editor.putInt(Key.id, i).apply
def currentProfile = profileManager.getProfile(profileId) def currentProfile = profileManager.getProfile(profileId)
def switchProfile(id: Int) = { def switchProfile(id: Int) = {
......
...@@ -17,9 +17,9 @@ import com.github.shadowsocks.utils.{Key, Utils} ...@@ -17,9 +17,9 @@ import com.github.shadowsocks.utils.{Key, Utils}
object ShadowsocksSettings { object ShadowsocksSettings {
// Constants // Constants
private final val TAG = "ShadowsocksSettings" private final val TAG = "ShadowsocksSettings"
private val PROXY_PREFS = Array(Key.profileName, Key.proxy, Key.remotePort, Key.localPort, Key.sitekey, Key.encMethod, private val PROXY_PREFS = Array(Key.name, Key.host, Key.remotePort, Key.localPort, Key.password, Key.method,
Key.isAuth) Key.auth)
private val FEATURE_PREFS = Array(Key.route, Key.isProxyApps, Key.isUdpDns, Key.isIpv6) private val FEATURE_PREFS = Array(Key.route, Key.proxyApps, Key.udpdns, Key.ipv6)
// Helper functions // Helper functions
def updateDropDownPreference(pref: Preference, value: String) { def updateDropDownPreference(pref: Preference, value: String) {
...@@ -46,17 +46,17 @@ object ShadowsocksSettings { ...@@ -46,17 +46,17 @@ object ShadowsocksSettings {
def updatePreference(pref: Preference, name: String, profile: Profile) { def updatePreference(pref: Preference, name: String, profile: Profile) {
name match { name match {
case Key.profileName => updateSummaryEditTextPreference(pref, profile.name) case Key.name => updateSummaryEditTextPreference(pref, profile.name)
case Key.proxy => updateSummaryEditTextPreference(pref, profile.host) case Key.host => updateSummaryEditTextPreference(pref, profile.host)
case Key.remotePort => updateNumberPickerPreference(pref, profile.remotePort) case Key.remotePort => updateNumberPickerPreference(pref, profile.remotePort)
case Key.localPort => updateNumberPickerPreference(pref, profile.localPort) case Key.localPort => updateNumberPickerPreference(pref, profile.localPort)
case Key.sitekey => updatePasswordEditTextPreference(pref, profile.password) case Key.password => updatePasswordEditTextPreference(pref, profile.password)
case Key.encMethod => updateDropDownPreference(pref, profile.method) case Key.method => updateDropDownPreference(pref, profile.method)
case Key.route => updateDropDownPreference(pref, profile.route) case Key.route => updateDropDownPreference(pref, profile.route)
case Key.isProxyApps => updateSwitchPreference(pref, profile.proxyApps) case Key.proxyApps => updateSwitchPreference(pref, profile.proxyApps)
case Key.isUdpDns => updateSwitchPreference(pref, profile.udpdns) case Key.udpdns => updateSwitchPreference(pref, profile.udpdns)
case Key.isAuth => updateSwitchPreference(pref, profile.auth) case Key.auth => updateSwitchPreference(pref, profile.auth)
case Key.isIpv6 => updateSwitchPreference(pref, profile.ipv6) case Key.ipv6 => updateSwitchPreference(pref, profile.ipv6)
} }
} }
} }
...@@ -74,11 +74,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -74,11 +74,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
addPreferencesFromResource(R.xml.pref_all) addPreferencesFromResource(R.xml.pref_all)
getPreferenceManager.getSharedPreferences.registerOnSharedPreferenceChangeListener(this) getPreferenceManager.getSharedPreferences.registerOnSharedPreferenceChangeListener(this)
findPreference(Key.profileName).setOnPreferenceChangeListener((_, value) => { findPreference(Key.name).setOnPreferenceChangeListener((_, value) => {
profile.name = value.asInstanceOf[String] profile.name = value.asInstanceOf[String]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
findPreference(Key.proxy).setOnPreferenceChangeListener((_, value) => { findPreference(Key.host).setOnPreferenceChangeListener((_, value) => {
profile.host = value.asInstanceOf[String] profile.host = value.asInstanceOf[String]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
...@@ -90,11 +90,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -90,11 +90,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
profile.localPort = value.asInstanceOf[Int] profile.localPort = value.asInstanceOf[Int]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
findPreference(Key.sitekey).setOnPreferenceChangeListener((_, value) => { findPreference(Key.password).setOnPreferenceChangeListener((_, value) => {
profile.password = value.asInstanceOf[String] profile.password = value.asInstanceOf[String]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
findPreference(Key.encMethod).setOnPreferenceChangeListener((_, value) => { findPreference(Key.method).setOnPreferenceChangeListener((_, value) => {
profile.method = value.asInstanceOf[String] profile.method = value.asInstanceOf[String]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
...@@ -103,7 +103,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -103,7 +103,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
isProxyApps = findPreference(Key.isProxyApps).asInstanceOf[SwitchPreference] isProxyApps = findPreference(Key.proxyApps).asInstanceOf[SwitchPreference]
isProxyApps.setOnPreferenceClickListener(_ => { isProxyApps.setOnPreferenceClickListener(_ => {
startActivity(new Intent(activity, classOf[AppManager])) startActivity(new Intent(activity, classOf[AppManager]))
isProxyApps.setChecked(true) isProxyApps.setChecked(true)
...@@ -114,15 +114,15 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -114,15 +114,15 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
findPreference(Key.isUdpDns).setOnPreferenceChangeListener((_, value) => { findPreference(Key.udpdns).setOnPreferenceChangeListener((_, value) => {
profile.udpdns = value.asInstanceOf[Boolean] profile.udpdns = value.asInstanceOf[Boolean]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
findPreference(Key.isAuth).setOnPreferenceChangeListener((_, value) => { findPreference(Key.auth).setOnPreferenceChangeListener((_, value) => {
profile.auth = value.asInstanceOf[Boolean] profile.auth = value.asInstanceOf[Boolean]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
findPreference(Key.isIpv6).setOnPreferenceChangeListener((_, value) => { findPreference(Key.ipv6).setOnPreferenceChangeListener((_, value) => {
profile.ipv6 = value.asInstanceOf[Boolean] profile.ipv6 = value.asInstanceOf[Boolean]
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
}) })
...@@ -202,7 +202,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -202,7 +202,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
for (name <- Key.isNAT #:: PROXY_PREFS.toStream #::: FEATURE_PREFS.toStream) { for (name <- Key.isNAT #:: PROXY_PREFS.toStream #::: FEATURE_PREFS.toStream) {
val pref = findPreference(name) val pref = findPreference(name)
if (pref != null) pref.setEnabled(enabled && if (pref != null) pref.setEnabled(enabled &&
(name != Key.isProxyApps || Utils.isLollipopOrAbove || app.isNatEnabled)) (name != Key.proxyApps || Utils.isLollipopOrAbove || app.isNatEnabled))
} }
} }
......
...@@ -143,25 +143,25 @@ object ConfigUtils { ...@@ -143,25 +143,25 @@ object ConfigUtils {
} }
object Key { object Key {
val profileId = "profileId" val id = "profileId"
val profileName = "profileName" val name = "profileName"
val proxied = "Proxyed" val individual = "Proxyed"
val isNAT = "isNAT" val isNAT = "isNAT"
val route = "route" val route = "route"
val isAutoConnect = "isAutoConnect" val isAutoConnect = "isAutoConnect"
val isProxyApps = "isProxyApps" val proxyApps = "isProxyApps"
val isBypassApps = "isBypassApps" val bypass = "isBypassApps"
val isUdpDns = "isUdpDns" val udpdns = "isUdpDns"
val isAuth = "isAuth" val auth = "isAuth"
val isIpv6 = "isIpv6" val ipv6 = "isIpv6"
val proxy = "proxy" val host = "proxy"
val sitekey = "sitekey" val password = "sitekey"
val encMethod = "encMethod" val method = "encMethod"
val remotePort = "remotePortNum" val remotePort = "remotePortNum"
val localPort = "localPortNum" val localPort = "localPortNum"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment