Skip to content

Commit

Permalink
Refine utils.Key for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Jul 5, 2016
1 parent c480137 commit 07eb4d2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
10 changes: 5 additions & 5 deletions src/main/scala/com/github/shadowsocks/AppManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/github/shadowsocks/Shadowsocks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) = {
Expand Down
40 changes: 20 additions & 20 deletions src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
Expand All @@ -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)
})
Expand Down Expand Up @@ -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))
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/scala/com/github/shadowsocks/utils/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 07eb4d2

Please sign in to comment.