Commit 4d4d6ed1 authored by Mygod's avatar Mygod

Add RESULT_FALLBACK to ConfigurationActivity

parent a8222317
...@@ -73,7 +73,7 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe ...@@ -73,7 +73,7 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
false false
}) })
plugin = findPreference(Key.plugin).asInstanceOf[IconListPreference] 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.unknownValueSummary = getString(R.string.plugin_unknown)
plugin.setOnPreferenceChangeListener((_, value) => { plugin.setOnPreferenceChangeListener((_, value) => {
val selected = value.asInstanceOf[String] val selected = value.asInstanceOf[String]
...@@ -130,23 +130,29 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe ...@@ -130,23 +130,29 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
isProxyApps.setChecked(app.settings.getBoolean(Key.proxyApps, false)) // fetch proxyApps updated by AppManager isProxyApps.setChecked(app.settings.getBoolean(Key.proxyApps, false)) // fetch proxyApps updated by AppManager
} }
override def onDisplayPreferenceDialog(preference: Preference): Unit = if (preference eq pluginConfigure) { private def showPluginEditor() {
val selected = pluginConfiguration.selected val bundle = new Bundle()
val intent = PluginManager.buildIntent(selected, PluginContract.ACTION_CONFIGURE) 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) if (intent.resolveActivity(getActivity.getPackageManager) != null)
startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS,
pluginConfiguration.selectedOptions.toString), REQUEST_CODE_PLUGIN_CONFIGURE) else { pluginConfiguration.selectedOptions.toString), REQUEST_CODE_PLUGIN_CONFIGURE) else {
val bundle = new Bundle() showPluginEditor()
bundle.putString(PluginConfigurationDialogFragment.PLUGIN_ID_FRAGMENT_TAG, selected)
displayPreferenceDialog(preference.getKey, new PluginConfigurationDialogFragment, bundle)
} }
} else super.onDisplayPreferenceDialog(preference) } else super.onDisplayPreferenceDialog(preference)
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = requestCode match { override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = requestCode match {
case REQUEST_CODE_PLUGIN_CONFIGURE => if (resultCode == Activity.RESULT_OK) { case REQUEST_CODE_PLUGIN_CONFIGURE => resultCode match {
case Activity.RESULT_OK =>
val options = data.getStringExtra(PluginContract.EXTRA_OPTIONS) val options = data.getStringExtra(PluginContract.EXTRA_OPTIONS)
pluginConfigure.setText(options) pluginConfigure.setText(options)
onPluginConfigureChanged(null, options) onPluginConfigureChanged(null, options)
case PluginContract.RESULT_FALLBACK => showPluginEditor()
case _ =>
} }
case _ => super.onActivityResult(requestCode, resultCode, data) case _ => super.onActivityResult(requestCode, resultCode, data)
} }
......
...@@ -152,6 +152,7 @@ object Key { ...@@ -152,6 +152,7 @@ object Key {
val remoteDns = "remoteDns" val remoteDns = "remoteDns"
val plugin = "plugin" val plugin = "plugin"
val pluginConfigure = "plugin.configure"
val dirty = "profileDirty" val dirty = "profileDirty"
......
...@@ -71,6 +71,9 @@ public final class PluginContract { ...@@ -71,6 +71,9 @@ public final class PluginContract {
static final String METHOD_GET_EXECUTABLE = "shadowsocks:getExecutable"; 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. * Relative to the file to be copied. This column is required.
* *
......
...@@ -36,4 +36,12 @@ trait ConfigurationActivity extends OptionsCapableActivity { ...@@ -36,4 +36,12 @@ trait ConfigurationActivity extends OptionsCapableActivity {
*/ */
final def saveChanges(options: PluginOptions): Unit = final def saveChanges(options: PluginOptions): Unit =
setResult(Activity.RESULT_OK, new Intent().putExtra(PluginContract.EXTRA_OPTIONS, options.toString)) 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()
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment