Fix HelpCallback
This commit is contained in:
@@ -21,14 +21,21 @@
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.content.{DialogInterface, Intent}
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.widget.Toolbar
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
import com.github.shadowsocks.plugin.PluginContract
|
||||
import com.github.shadowsocks.utils.Key
|
||||
|
||||
object ProfileConfigActivity {
|
||||
final val REQUEST_CODE_PLUGIN_HELP = 1
|
||||
}
|
||||
|
||||
class ProfileConfigActivity extends Activity {
|
||||
import ProfileConfigActivity._
|
||||
|
||||
private lazy val child = getFragmentManager.findFragmentById(R.id.content).asInstanceOf[ProfileConfigFragment]
|
||||
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
@@ -49,4 +56,12 @@ class ProfileConfigActivity extends Activity {
|
||||
.setNeutralButton(android.R.string.cancel, null)
|
||||
.create()
|
||||
.show() else super.onBackPressed()
|
||||
|
||||
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = requestCode match {
|
||||
case REQUEST_CODE_PLUGIN_HELP => if (resultCode == Activity.RESULT_OK) new AlertDialog.Builder(this)
|
||||
.setTitle("?")
|
||||
.setMessage(data.getCharSequenceExtra(PluginContract.EXTRA_HELP_MESSAGE))
|
||||
.show()
|
||||
case _ => super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import com.github.shadowsocks.preference.{IconListPreference, PluginConfiguratio
|
||||
import com.github.shadowsocks.utils.{Action, Key, Utils}
|
||||
|
||||
object ProfileConfigFragment {
|
||||
private final val REQUEST_CODE_CONFIGURE = 1
|
||||
private final val REQUEST_CODE_PLUGIN_CONFIGURE = 1
|
||||
}
|
||||
|
||||
class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListener
|
||||
@@ -135,7 +135,7 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
|
||||
val intent = PluginManager.buildIntent(selected, PluginContract.ACTION_CONFIGURE)
|
||||
if (intent.resolveActivity(getActivity.getPackageManager) != null)
|
||||
startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS,
|
||||
pluginConfiguration.selectedOptions.toString), REQUEST_CODE_CONFIGURE) else {
|
||||
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)
|
||||
@@ -143,7 +143,7 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
|
||||
} else super.onDisplayPreferenceDialog(preference)
|
||||
|
||||
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = requestCode match {
|
||||
case REQUEST_CODE_CONFIGURE => if (resultCode == Activity.RESULT_OK) {
|
||||
case REQUEST_CODE_PLUGIN_CONFIGURE => if (resultCode == Activity.RESULT_OK) {
|
||||
val options = data.getStringExtra(PluginContract.EXTRA_OPTIONS)
|
||||
pluginConfigure.setText(options)
|
||||
onPluginConfigureChanged(null, options)
|
||||
|
||||
+5
-16
@@ -20,9 +20,10 @@
|
||||
|
||||
package com.github.shadowsocks.preference
|
||||
|
||||
import android.app.{Activity, AlertDialog}
|
||||
import android.content.{DialogInterface, Intent}
|
||||
import android.app.AlertDialog
|
||||
import android.content.DialogInterface
|
||||
import be.mygod.preference.EditTextPreferenceDialogFragment
|
||||
import com.github.shadowsocks.ProfileConfigActivity
|
||||
import com.github.shadowsocks.plugin.{PluginContract, PluginManager}
|
||||
|
||||
/**
|
||||
@@ -30,7 +31,6 @@ import com.github.shadowsocks.plugin.{PluginContract, PluginManager}
|
||||
*/
|
||||
object PluginConfigurationDialogFragment {
|
||||
final val PLUGIN_ID_FRAGMENT_TAG = "com.github.shadowsocks.preference.PluginConfigurationDialogFragment.PLUGIN_ID"
|
||||
private final val REQUEST_CODE_HELP = 1
|
||||
}
|
||||
|
||||
class PluginConfigurationDialogFragment extends EditTextPreferenceDialogFragment {
|
||||
@@ -40,18 +40,7 @@ class PluginConfigurationDialogFragment extends EditTextPreferenceDialogFragment
|
||||
super.onPrepareDialogBuilder(builder)
|
||||
val intent = PluginManager.buildIntent(getArguments.getString(PLUGIN_ID_FRAGMENT_TAG), PluginContract.ACTION_HELP)
|
||||
if (intent.resolveActivity(getActivity.getPackageManager) != null) builder.setNeutralButton("?", ((_, _) =>
|
||||
startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, editText.getText.toString),
|
||||
REQUEST_CODE_HELP)): DialogInterface.OnClickListener)
|
||||
}
|
||||
|
||||
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = requestCode match {
|
||||
case REQUEST_CODE_HELP => requestCode match {
|
||||
case Activity.RESULT_OK => new AlertDialog.Builder(getContext)
|
||||
.setTitle("?")
|
||||
.setMessage(data.getCharSequenceExtra(PluginContract.EXTRA_HELP_MESSAGE))
|
||||
.show()
|
||||
case _ =>
|
||||
}
|
||||
case _ => super.onActivityResult(requestCode, resultCode, data)
|
||||
getActivity.startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, editText.getText.toString),
|
||||
ProfileConfigActivity.REQUEST_CODE_PLUGIN_HELP)): DialogInterface.OnClickListener)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import android.content.Intent
|
||||
trait HelpCallback extends HelpActivity {
|
||||
def produceHelpMessage(options: PluginOptions): CharSequence
|
||||
|
||||
override protected def onInitializePluginOptions(options: PluginOptions): Unit = setResult(Activity.RESULT_OK,
|
||||
new Intent().putExtra(PluginContract.EXTRA_HELP_MESSAGE, produceHelpMessage(options)))
|
||||
override protected def onInitializePluginOptions(options: PluginOptions) {
|
||||
setResult(Activity.RESULT_OK, new Intent().putExtra(PluginContract.EXTRA_HELP_MESSAGE, produceHelpMessage(options)))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user