From 6f400bfdc6bdad8be9d84e2254783d73dd03baff Mon Sep 17 00:00:00 2001 From: Max Lv Date: Tue, 24 Jan 2017 14:44:08 +0800 Subject: [PATCH] Fix getOrDefault() --- .../plugin/obfs_local/ConfigFragment.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/plugin/obfs_local/ConfigFragment.scala b/src/main/scala/com/github/shadowsocks/plugin/obfs_local/ConfigFragment.scala index 98f7a00..a61be52 100644 --- a/src/main/scala/com/github/shadowsocks/plugin/obfs_local/ConfigFragment.scala +++ b/src/main/scala/com/github/shadowsocks/plugin/obfs_local/ConfigFragment.scala @@ -13,13 +13,20 @@ class ConfigFragment extends PreferenceFragment { override def onCreatePreferences(bundle: Bundle, key: String): Unit = addPreferencesFromResource(R.xml.config) + def getOrDefault(options: PluginOptions, key: String, defaultValue: String): String = { + options.get(key) match { + case v: String => v + case _ => defaultValue + } + } + def onInitializePluginOptions(options: PluginOptions): Unit = { this.options = options for ((key, defaultValue) <- Array(("obfs", "http"), ("obfs-host", "cloudfront.net"))) { val pref = findPreference(key) pref match { - case ddp: DropDownPreference => ddp.setValue(options.getOrDefault(key, defaultValue)) - case etp: EditTextPreference => etp.setText(options.getOrDefault(key, defaultValue)) + case ddp: DropDownPreference => ddp.setValue(getOrDefault(options, key, defaultValue)) + case etp: EditTextPreference => etp.setText(getOrDefault(options, key, defaultValue)) } pref.setOnPreferenceChangeListener((_, value) => { options.put(key, value.toString)