From 4d4d6ed1a043e1cb095f8d1ec713fe782724634f Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 23 Jan 2017 14:31:42 +0800 Subject: [PATCH] Add RESULT_FALLBACK to ConfigurationActivity --- .../shadowsocks/ProfileConfigFragment.scala | 28 +++++++++++-------- .../github/shadowsocks/utils/Constants.scala | 1 + .../shadowsocks/plugin/PluginContract.java | 3 ++ .../plugin/ConfigurationActivity.scala | 8 ++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/mobile/src/main/scala/com/github/shadowsocks/ProfileConfigFragment.scala b/mobile/src/main/scala/com/github/shadowsocks/ProfileConfigFragment.scala index d04ce749..506f459f 100644 --- a/mobile/src/main/scala/com/github/shadowsocks/ProfileConfigFragment.scala +++ b/mobile/src/main/scala/com/github/shadowsocks/ProfileConfigFragment.scala @@ -73,7 +73,7 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe false }) plugin = findPreference(Key.plugin).asInstanceOf[IconListPreference] - pluginConfigure = findPreference("plugin.configure").asInstanceOf[EditTextPreference] + pluginConfigure = findPreference(Key.pluginConfigure).asInstanceOf[EditTextPreference] plugin.unknownValueSummary = getString(R.string.plugin_unknown) plugin.setOnPreferenceChangeListener((_, value) => { val selected = value.asInstanceOf[String] @@ -130,23 +130,29 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe isProxyApps.setChecked(app.settings.getBoolean(Key.proxyApps, false)) // fetch proxyApps updated by AppManager } - override def onDisplayPreferenceDialog(preference: Preference): Unit = if (preference eq pluginConfigure) { - val selected = pluginConfiguration.selected - val intent = PluginManager.buildIntent(selected, PluginContract.ACTION_CONFIGURE) + private def showPluginEditor() { + val bundle = new Bundle() + bundle.putString(PluginConfigurationDialogFragment.PLUGIN_ID_FRAGMENT_TAG, pluginConfiguration.selected) + displayPreferenceDialog(Key.pluginConfigure, new PluginConfigurationDialogFragment, bundle) + } + + override def onDisplayPreferenceDialog(preference: Preference): Unit = if (preference.getKey == Key.pluginConfigure) { + val intent = PluginManager.buildIntent(pluginConfiguration.selected, PluginContract.ACTION_CONFIGURE) if (intent.resolveActivity(getActivity.getPackageManager) != null) startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, pluginConfiguration.selectedOptions.toString), REQUEST_CODE_PLUGIN_CONFIGURE) else { - val bundle = new Bundle() - bundle.putString(PluginConfigurationDialogFragment.PLUGIN_ID_FRAGMENT_TAG, selected) - displayPreferenceDialog(preference.getKey, new PluginConfigurationDialogFragment, bundle) + showPluginEditor() } } else super.onDisplayPreferenceDialog(preference) override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = requestCode match { - case REQUEST_CODE_PLUGIN_CONFIGURE => if (resultCode == Activity.RESULT_OK) { - val options = data.getStringExtra(PluginContract.EXTRA_OPTIONS) - pluginConfigure.setText(options) - onPluginConfigureChanged(null, options) + case REQUEST_CODE_PLUGIN_CONFIGURE => resultCode match { + case Activity.RESULT_OK => + val options = data.getStringExtra(PluginContract.EXTRA_OPTIONS) + pluginConfigure.setText(options) + onPluginConfigureChanged(null, options) + case PluginContract.RESULT_FALLBACK => showPluginEditor() + case _ => } case _ => super.onActivityResult(requestCode, resultCode, data) } diff --git a/mobile/src/main/scala/com/github/shadowsocks/utils/Constants.scala b/mobile/src/main/scala/com/github/shadowsocks/utils/Constants.scala index 7d7bea16..69034aba 100644 --- a/mobile/src/main/scala/com/github/shadowsocks/utils/Constants.scala +++ b/mobile/src/main/scala/com/github/shadowsocks/utils/Constants.scala @@ -152,6 +152,7 @@ object Key { val remoteDns = "remoteDns" val plugin = "plugin" + val pluginConfigure = "plugin.configure" val dirty = "profileDirty" diff --git a/plugin/src/main/java/com/github/shadowsocks/plugin/PluginContract.java b/plugin/src/main/java/com/github/shadowsocks/plugin/PluginContract.java index 1bd3732f..ec73be4b 100644 --- a/plugin/src/main/java/com/github/shadowsocks/plugin/PluginContract.java +++ b/plugin/src/main/java/com/github/shadowsocks/plugin/PluginContract.java @@ -71,6 +71,9 @@ public final class PluginContract { static final String METHOD_GET_EXECUTABLE = "shadowsocks:getExecutable"; + /** ConfigurationActivity result: fallback to manual edit mode. */ + public static final int RESULT_FALLBACK = 1; + /** * Relative to the file to be copied. This column is required. * diff --git a/plugin/src/main/scala/com/github/shadowsocks/plugin/ConfigurationActivity.scala b/plugin/src/main/scala/com/github/shadowsocks/plugin/ConfigurationActivity.scala index f35e4dc3..ff618ade 100644 --- a/plugin/src/main/scala/com/github/shadowsocks/plugin/ConfigurationActivity.scala +++ b/plugin/src/main/scala/com/github/shadowsocks/plugin/ConfigurationActivity.scala @@ -36,4 +36,12 @@ trait ConfigurationActivity extends OptionsCapableActivity { */ final def saveChanges(options: PluginOptions): Unit = setResult(Activity.RESULT_OK, new Intent().putExtra(PluginContract.EXTRA_OPTIONS, options.toString)) + + /** + * Finish this activity and request manual editor to pop up instead. + */ + final def fallbackToManualEditor() { + setResult(PluginContract.RESULT_FALLBACK) + finish() + } }