Skip to content

Commit

Permalink
Code style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Dec 27, 2020
1 parent b1dfb5b commit cd40edb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ import com.github.shadowsocks.plugin.PluginOptions

class ConfigActivity : ConfigurationActivity(), Toolbar.OnMenuItemClickListener {

fun getChild(): ConfigFragment {
private fun getChild(): ConfigFragment {
return supportFragmentManager.findFragmentById(R.id.content) as ConfigFragment
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_config)
val toolbar = findViewById<Toolbar>(R.id.toolbar) as Toolbar
toolbar.setTitle(getTitle())
val toolbar = findViewById<Toolbar>(R.id.toolbar)
toolbar.title = title
toolbar.setNavigationIcon(R.drawable.ic_navigation_close)
toolbar.setNavigationOnClickListener(
fun(_) {
onBackPressed()
})
toolbar.setNavigationOnClickListener { onBackPressed()}
toolbar.inflateMenu(R.menu.menu_config)
toolbar.setOnMenuItemClickListener(this)
}
Expand All @@ -33,14 +30,14 @@ class ConfigActivity : ConfigurationActivity(), Toolbar.OnMenuItemClickListener
}

override fun onMenuItemClick(item: MenuItem): Boolean {
when (item.getItemId()) {
return when (item.itemId) {
R.id.action_apply -> {
Log.d("options", getChild()._options.toString())
saveChanges(getChild()._options)
Log.d("options", getChild().options.toString())
saveChanges(getChild().options)
finish()
return true
true
}
else -> return false
else -> false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import com.github.shadowsocks.plugin.PluginOptions


class ConfigFragment : PreferenceFragmentCompat() {
var _options = PluginOptions()
var options = PluginOptions()

fun onInitializePluginOptions(options: PluginOptions) {
this._options = options
this.options = options
val ary = arrayOf(Pair("ProxyMethod","shadowsocks"), Pair("EncryptionMethod","plain"),
Pair("Transport", "direct"), Pair("UID", ""), Pair("PublicKey",""), Pair("ServerName", "bing.com"),
Pair("CDNOriginHost", ""), Pair("NumConn","4"), Pair("BrowserSig", "chrome"),
Expand All @@ -22,7 +22,7 @@ class ConfigFragment : PreferenceFragmentCompat() {
val key = element.first
val defaultValue = element.second
val pref: Preference? = findPreference(key)
val value: String? = options.get(key)?:defaultValue
val value: String? = options[key] ?:defaultValue
when (pref) {
is ListPreference -> {
pref.value = value
Expand All @@ -32,10 +32,10 @@ class ConfigFragment : PreferenceFragmentCompat() {
}
}
// we want all preferences to be put into the options, not only the changed ones
options.put(key, value)
options[key] = value
pref!!.setOnPreferenceChangeListener(
fun(_: Preference, value: Any): Boolean {
options.put(key, value.toString())
fun(_, value: Any): Boolean {
options[key] = value.toString()
return true
}
)
Expand All @@ -44,13 +44,13 @@ class ConfigFragment : PreferenceFragmentCompat() {

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString(PluginContract.EXTRA_OPTIONS, _options.toString())
outState.putString(PluginContract.EXTRA_OPTIONS, options.toString())
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
if (savedInstanceState != null) {
_options = PluginOptions(savedInstanceState.getString(PluginContract.EXTRA_OPTIONS))
onInitializePluginOptions(_options)
options = PluginOptions(savedInstanceState.getString(PluginContract.EXTRA_OPTIONS))
onInitializePluginOptions(options)
}
addPreferencesFromResource(R.xml.config)
}
Expand Down

0 comments on commit cd40edb

Please sign in to comment.