Skip to content

Commit

Permalink
Fix getOrDefault()
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Jan 24, 2017
1 parent 7fe5c7f commit 6f400bf
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6f400bf

Please sign in to comment.