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