ask for comfirmation when leaving edit entry with back buttom after making changes

This commit is contained in:
PhilippC 2013-03-17 06:25:53 +01:00
parent 5370e73639
commit 6ba4068a28
4 changed files with 63 additions and 6 deletions

View File

@ -52,6 +52,8 @@ namespace keepass2android
private PwIcon mSelectedIconID;
private PwUuid mSelectedCustomIconID = PwUuid.Zero;
private bool mSelectedIcon = false;
bool mEntryModified;
public static void Launch(Activity act, PwEntry pw) {
Intent i = new Intent(act, typeof(EntryEditActivity));
@ -145,6 +147,7 @@ namespace keepass2android
}
}*/
mIsNew = true;
mEntryModified = true;
} else {
@ -356,7 +359,9 @@ namespace keepass2android
ees.setData("", new ProtectedString(false, ""));
ees.getDeleteButton().Click += (senderEes, eEes) => deleteAdvancedString((View)senderEes);
container.AddView(ees);
mEntryModified = true;
// Scroll bottom
scroll.Post(() => {
scroll.FullScroll(FocusSearchDirection.Down);
@ -374,7 +379,7 @@ namespace keepass2android
mEntry.ExpiryTime = DateTime.Now;
}
updateExpires();
mEntryModified = true;
};
}
@ -446,8 +451,39 @@ namespace keepass2android
{
Toast.MakeText(this, GetString(Resource.String.AttachFailed)+" "+exAttach.Message, ToastLength.Long).Show();
}
mEntryModified = true;
populateBinaries();
}
public override void OnBackPressed()
{
if (mEntryModified == false)
{
base.OnBackPressed();
} else
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetTitle(GetString(Resource.String.AskDiscardChanges_title));
builder.SetMessage(GetString(Resource.String.AskDiscardChanges));
builder.SetPositiveButton(GetString(Android.Resource.String.Yes), new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) =>
{
Finish();
}));
builder.SetNegativeButton(GetString(Android.Resource.String.No), new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) =>
{
}));
Dialog dialog = builder.Create();
dialog.Show();
}
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
@ -463,6 +499,7 @@ namespace keepass2android
ImageButton currIconButton = (ImageButton) FindViewById(Resource.Id.icon_button);
//TODO: custom image
currIconButton.SetImageResource(Icons.iconToResId(mSelectedIconID));
mEntryModified = true;
break;
case RESULT_OK_PASSWORD_GENERATOR:
@ -472,7 +509,7 @@ namespace keepass2android
password.Text = generatedPassword;
confPassword.Text = generatedPassword;
mEntryModified = true;
break;
case (int)Result.Ok:
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE)
@ -511,6 +548,7 @@ namespace keepass2android
binaryButton.SetCompoundDrawablesWithIntrinsicBounds( Resources.GetDrawable(Android.Resource.Drawable.IcMenuDelete),null, null, null);
binaryButton.Click += (object sender, EventArgs e) =>
{
mEntryModified = true;
Button btnSender = (Button)(sender);
mEntry.Binaries.Remove(key);
populateBinaries();
@ -632,6 +670,7 @@ namespace keepass2android
if (!PwDefs.IsStandardField(key)) {
EntryEditSection ees = (EntryEditSection) LayoutInflater.Inflate(Resource.Layout.entry_edit_section, null);
ees.setData(key, pair.Value);
ees.ContentChanged += (sender, e) => {mEntryModified=true;};
ees.getDeleteButton().Click += (sender, e) => deleteAdvancedString((View)sender);
container.AddView(ees);
}
@ -652,7 +691,7 @@ namespace keepass2android
public void deleteAdvancedString(View view) {
EntryEditSection section = (EntryEditSection) view.Parent;
LinearLayout container = (LinearLayout) FindViewById(Resource.Id.advanced_container);
mEntryModified = true;
for (int i = 0; i < container.ChildCount; i++) {
EntryEditSection ees = (EntryEditSection) container.GetChildAt(i);
if (ees == section) {
@ -714,6 +753,7 @@ namespace keepass2android
private void populateText(int viewId, String text) {
TextView tv = (TextView) FindViewById(viewId);
tv.Text = text;
tv.TextChanged += (sender, e) => {mEntryModified = true;};
}
private class AfterSave : OnFinish {

View File

@ -1009,6 +1009,12 @@ namespace keepass2android
// aapt resource value: 0x7f0500f1
public const int AskDeletePermanently_title = 2131034353;
// aapt resource value: 0x7f0500f4
public const int AskDiscardChanges = 2131034356;
// aapt resource value: 0x7f0500f5
public const int AskDiscardChanges_title = 2131034357;
// aapt resource value: 0x7f0500e9
public const int AskOverwriteBinary = 2131034345;

View File

@ -214,6 +214,8 @@
<string name="AskDeletePermanently_title">Delete permanently?</string>
<string name="AskReloadFile_title">Reload file?</string>
<string name="AskReloadFile">The file which is currently open was changed by another program. Do you want to reload it?</string>
<string name="AskDiscardChanges">Do you really want to discard the changes made? (The Save button is at the top of the form.)</string>
<string name="AskDiscardChanges_title">Discard changes?</string>
<string-array name="clipboard_timeout_options">
<item>30 seconds</item>
<item>1 minute</item>

View File

@ -33,6 +33,8 @@ namespace keepass2android.view
{
public class EntryEditSection : RelativeLayout
{
public event EventHandler ContentChanged;
public EntryEditSection (IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
@ -62,6 +64,9 @@ namespace keepass2android.view
CheckBox cb = (CheckBox) FindViewById(Resource.Id.protection);
cb.Checked = value.IsProtected;
cb.CheckedChange += (sender, e) => {if (ContentChanged != null)
ContentChanged(this, new EventArgs());
};
}
public ImageButton getDeleteButton()
@ -73,8 +78,12 @@ namespace keepass2android.view
{
if (str != null)
{
TextView tvTitle = (TextView)FindViewById(resId);
tvTitle.Text = str;
TextView tv = (TextView)FindViewById(resId);
tv.Text = str;
tv.TextChanged += (sender, e) => {
if (ContentChanged != null)
ContentChanged(this, new EventArgs());
};
}
}