Commit f01cbe15 authored by Mygod's avatar Mygod

Prompt to save changes when exiting profile config

parent f9e504b0
...@@ -259,7 +259,7 @@ trait BaseService extends Service { ...@@ -259,7 +259,7 @@ trait BaseService extends Service {
override def onCreate() { override def onCreate() {
super.onCreate() super.onCreate()
app.refreshContainerHolder app.refreshContainerHolder()
app.updateAssets() app.updateAssets()
} }
......
...@@ -327,9 +327,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -327,9 +327,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
} }
val dialog = new AlertDialog.Builder(this) val dialog = new AlertDialog.Builder(this)
.setTitle(R.string.add_profile_dialog) .setTitle(R.string.add_profile_dialog)
.setPositiveButton(android.R.string.yes, ((_, _) => .setPositiveButton("Yes", ((_, _) => // TODO
profiles.foreach(app.profileManager.createProfile)): DialogInterface.OnClickListener) profiles.foreach(app.profileManager.createProfile)): DialogInterface.OnClickListener)
.setNegativeButton(android.R.string.no, null) .setNegativeButton("No", null)
.setMessage(profiles.mkString("\n")) .setMessage(profiles.mkString("\n"))
.create() .create()
dialog.show() dialog.show()
......
...@@ -5,11 +5,12 @@ import android.content.DialogInterface ...@@ -5,11 +5,12 @@ import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.widget.Toolbar import android.support.v7.widget.Toolbar
import android.support.v7.widget.Toolbar.OnMenuItemClickListener
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
class ProfileConfigActivity extends Activity { class ProfileConfigActivity extends Activity {
private lazy val child = getFragmentManager.findFragmentById(R.id.content).asInstanceOf[ProfileConfigFragment]
override def onCreate(savedInstanceState: Bundle) { override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.layout_profile_config) setContentView(R.layout.layout_profile_config)
...@@ -18,14 +19,14 @@ class ProfileConfigActivity extends Activity { ...@@ -18,14 +19,14 @@ class ProfileConfigActivity extends Activity {
toolbar.setNavigationIcon(R.drawable.ic_navigation_close) toolbar.setNavigationIcon(R.drawable.ic_navigation_close)
toolbar.setNavigationOnClickListener(_ => onBackPressed()) toolbar.setNavigationOnClickListener(_ => onBackPressed())
toolbar.inflateMenu(R.menu.profile_config_menu) toolbar.inflateMenu(R.menu.profile_config_menu)
toolbar.setOnMenuItemClickListener(getFragmentManager.findFragmentById(R.id.content) toolbar.setOnMenuItemClickListener(child)
.asInstanceOf[OnMenuItemClickListener])
} }
override def onBackPressed(): Unit = if (app.settings.getBoolean(Key.dirty, false)) new AlertDialog.Builder(this) override def onBackPressed(): Unit = if (app.settings.getBoolean(Key.dirty, false)) new AlertDialog.Builder(this)
.setTitle("Confirm?") // TODO .setTitle("Changes not saved. Do you want to save?") // TODO: localizations
.setPositiveButton(android.R.string.yes, ((_, _) => finish()): DialogInterface.OnClickListener) .setPositiveButton("Yes", ((_, _) => child.saveAndExit()): DialogInterface.OnClickListener)
.setNegativeButton(android.R.string.no, null) .setNegativeButton("No", ((_, _) => finish()): DialogInterface.OnClickListener)
.setNeutralButton(android.R.string.cancel, null)
.create() .create()
.show() else super.onBackPressed() .show() else super.onBackPressed()
} }
...@@ -92,23 +92,27 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe ...@@ -92,23 +92,27 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
case R.id.action_delete => case R.id.action_delete =>
new AlertDialog.Builder(getActivity) new AlertDialog.Builder(getActivity)
.setTitle("Confirm?") // TODO .setTitle("Confirm?") // TODO
.setPositiveButton(android.R.string.yes, ((_, _) => { .setPositiveButton("Yes", ((_, _) => {
app.profileManager.delProfile(profile.id) app.profileManager.delProfile(profile.id)
LocalBroadcastManager.getInstance(getActivity) LocalBroadcastManager.getInstance(getActivity)
.sendBroadcast(new Intent(Action.PROFILE_REMOVED).putExtra(Action.EXTRA_PROFILE_ID, profile.id)) .sendBroadcast(new Intent(Action.PROFILE_REMOVED).putExtra(Action.EXTRA_PROFILE_ID, profile.id))
getActivity.finish() getActivity.finish()
}): DialogInterface.OnClickListener) }): DialogInterface.OnClickListener)
.setNegativeButton(android.R.string.no, null) .setNegativeButton("No", null)
.create() .create()
.show() .show()
true true
case R.id.action_apply => case R.id.action_apply =>
saveAndExit()
true
case _ => false
}
def saveAndExit() {
profile.deserialize(app.settings) profile.deserialize(app.settings)
app.profileManager.updateProfile(profile) app.profileManager.updateProfile(profile)
LocalBroadcastManager.getInstance(getActivity) LocalBroadcastManager.getInstance(getActivity)
.sendBroadcast(new Intent(Action.PROFILE_CHANGED).putExtra(Action.EXTRA_PROFILE_ID, profile.id)) .sendBroadcast(new Intent(Action.PROFILE_CHANGED).putExtra(Action.EXTRA_PROFILE_ID, profile.id))
getActivity.finish() getActivity.finish()
true
case _ => false
} }
} }
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