Add a confirm dialog before discarding changes
This commit is contained in:
@@ -68,8 +68,7 @@
|
||||
android:name=".ProfileConfigActivity"
|
||||
android:excludeFromRecents="true"
|
||||
android:label="Profile config"
|
||||
android:launchMode="singleTask"
|
||||
android:parentActivityName=".MainActivity"/>
|
||||
android:launchMode="singleTask"/>
|
||||
|
||||
<activity
|
||||
android:name=".ShadowsocksRunnerActivity"
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.app.Activity
|
||||
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 {
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
@@ -12,9 +16,16 @@ class ProfileConfigActivity extends Activity {
|
||||
val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar]
|
||||
toolbar.setTitle("Profile config") // TODO
|
||||
toolbar.setNavigationIcon(R.drawable.ic_navigation_close)
|
||||
toolbar.setNavigationOnClickListener(_ => finish())
|
||||
toolbar.setNavigationOnClickListener(_ => onBackPressed())
|
||||
toolbar.inflateMenu(R.menu.profile_config_menu)
|
||||
toolbar.setOnMenuItemClickListener(getFragmentManager.findFragmentById(R.id.content)
|
||||
.asInstanceOf[OnMenuItemClickListener])
|
||||
}
|
||||
|
||||
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)
|
||||
.create()
|
||||
.show() else super.onBackPressed()
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
||||
import android.content._
|
||||
import android.os._
|
||||
import android.support.v14.preference.SwitchPreference
|
||||
@@ -34,7 +35,8 @@ import com.github.shadowsocks.database.Profile
|
||||
import com.github.shadowsocks.preferences.KcpCliPreferenceDialogFragment
|
||||
import com.github.shadowsocks.utils.{Action, Key, Utils}
|
||||
|
||||
class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListener {
|
||||
class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListener
|
||||
with OnSharedPreferenceChangeListener {
|
||||
private lazy val clipboard = getActivity.getSystemService(Context.CLIPBOARD_SERVICE).asInstanceOf[ClipboardManager]
|
||||
private var profile: Profile = _
|
||||
private var isProxyApps: SwitchPreference = _
|
||||
@@ -59,6 +61,15 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
|
||||
isProxyApps.setChecked(true)
|
||||
false
|
||||
})
|
||||
app.settings.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String): Unit =
|
||||
if (findPreference(key) != null) app.editor.putBoolean(Key.dirty, true).apply()
|
||||
|
||||
override def onDestroy() {
|
||||
app.settings.unregisterOnSharedPreferenceChangeListener(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override def onResume() {
|
||||
|
||||
@@ -119,7 +119,7 @@ class Profile {
|
||||
.putString(Key.individual, individual)
|
||||
.putBoolean(Key.kcp, kcp)
|
||||
.putInt(Key.kcpPort, kcpPort)
|
||||
.putString(Key.kcpcli, kcpcli)
|
||||
.remove(Key.dirty)
|
||||
def deserialize(pref: SharedPreferences) {
|
||||
// It's assumed that default values are never used, so 0/false/null is always used even if that isn't the case
|
||||
name = pref.getString(Key.name, null)
|
||||
|
||||
@@ -155,6 +155,8 @@ object Key {
|
||||
val kcpPort = "kcpPort"
|
||||
val kcpcli = "kcpcli"
|
||||
|
||||
val dirty = "profileDirty"
|
||||
|
||||
val tfo = "tcp_fastopen"
|
||||
val currentVersionCode = "currentVersionCode"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user