fix crash when copying entries, closes #920
This commit is contained in:
		| @@ -31,15 +31,17 @@ namespace keepass2android | ||||
| 		private readonly PwEntry _entry; | ||||
| 		private readonly PwGroup _parentGroup; | ||||
| 		private readonly Activity _ctx; | ||||
| 		 | ||||
| 		public static AddEntry GetInstance(Activity ctx, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish) { | ||||
| 	    private readonly Database _db; | ||||
|  | ||||
| 			return new AddEntry(ctx, app, entry, parentGroup, finish); | ||||
| 	    public static AddEntry GetInstance(Activity ctx, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish, Database db) { | ||||
|  | ||||
| 			return new AddEntry(ctx, db, app, entry, parentGroup, finish); | ||||
| 		} | ||||
| 		 | ||||
| 		public AddEntry(Activity ctx, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish):base(ctx, finish) { | ||||
| 		public AddEntry(Activity ctx, Database db, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish):base(ctx, finish) { | ||||
| 			_ctx = ctx; | ||||
| 			_parentGroup = parentGroup; | ||||
| 		    _db = db; | ||||
| 		    _parentGroup = parentGroup; | ||||
| 			_app = app; | ||||
| 			_entry = entry; | ||||
| 			 | ||||
| @@ -57,10 +59,13 @@ namespace keepass2android | ||||
| 			{ | ||||
| 				_parentGroup.AddEntry(_entry, true);	 | ||||
| 			} | ||||
| 			 | ||||
| 			 | ||||
| 			// Commit to disk | ||||
| 			SaveDb save = new SaveDb(_ctx, _app, _app.CurrentDb, OnFinishToRun); | ||||
|  | ||||
| 		    // Add entry to global | ||||
| 		    _db.EntriesById[_entry.Uuid] = _entry; | ||||
| 		    _db.Elements.Add(_entry); | ||||
|  | ||||
|             // Commit to disk | ||||
|             SaveDb save = new SaveDb(_ctx, _app, _app.CurrentDb, OnFinishToRun); | ||||
| 			save.SetStatusLogger(StatusLogger); | ||||
| 			save.Run(); | ||||
| 		} | ||||
| @@ -86,9 +91,7 @@ namespace keepass2android | ||||
| 					// Mark parent group dirty | ||||
| 					_app.DirtyGroups.Add(parent); | ||||
| 					 | ||||
| 					// Add entry to global | ||||
| 					_db.EntriesById[_entry.Uuid] = _entry; | ||||
| 				    _db.Elements.Add(_entry); | ||||
|  | ||||
|  | ||||
| 				} else | ||||
| 				{ | ||||
|   | ||||
| @@ -16,8 +16,8 @@ namespace keepass2android.database.edit | ||||
| { | ||||
| 	public class CopyEntry: AddEntry | ||||
| 	{ | ||||
| 		public CopyEntry(Activity ctx, IKp2aApp app, PwEntry entry, OnFinish finish) | ||||
| 			: base(ctx, app, CreateCopy(entry, app), entry.ParentGroup, finish) | ||||
| 		public CopyEntry(Activity ctx, IKp2aApp app, PwEntry entry, OnFinish finish, Database db) | ||||
| 			: base(ctx, db, app, CreateCopy(entry, app), entry.ParentGroup, finish) | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -227,7 +227,7 @@ namespace keepass2android | ||||
|             newEntry.SetUuid(new PwUuid(true), true); // Create new UUID | ||||
|             string strTitle = newEntry.Strings.ReadSafe(PwDefs.TitleField); | ||||
|             newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, strTitle + " (" + Android.OS.Build.Model + ")")); | ||||
|             var addTask = new AddEntry(this, App.Kp2a, newEntry,item.Entry.ParentGroup,new ActionOnFinish(this, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); | ||||
|             var addTask = new AddEntry(this, App.Kp2a.CurrentDb, App.Kp2a, newEntry,item.Entry.ParentGroup,new ActionOnFinish(this, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); | ||||
|  | ||||
|             ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask); | ||||
|             pt.Run(); | ||||
| @@ -366,7 +366,7 @@ namespace keepass2android | ||||
|                         {KeeAutoExecExt.ThisDeviceId, true} | ||||
|                     }))); | ||||
|  | ||||
|             var addTask = new AddEntry(this, App.Kp2a, newEntry, autoOpenGroup, new ActionOnFinish(this, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update())); | ||||
|             var addTask = new AddEntry(this, db, App.Kp2a, newEntry, autoOpenGroup, new ActionOnFinish(this, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update())); | ||||
|  | ||||
|             ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask); | ||||
|             pt.Run(); | ||||
|   | ||||
| @@ -506,7 +506,7 @@ namespace keepass2android | ||||
| 			},closeOrShowError); | ||||
|  | ||||
| 			if ( State.IsNew ) { | ||||
| 				runnable = AddEntry.GetInstance(this, App.Kp2a, newEntry, State.ParentGroup, afterAddEntry); | ||||
| 				runnable = AddEntry.GetInstance(this, App.Kp2a, newEntry, State.ParentGroup, afterAddEntry, db); | ||||
| 			} else { | ||||
| 				runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError); | ||||
| 			} | ||||
|   | ||||
| @@ -1390,7 +1390,7 @@ namespace keepass2android | ||||
|                 case Resource.Id.menu_copy: | ||||
|  | ||||
|                     var copyTask = new CopyEntry((GroupBaseActivity)Activity, App.Kp2a, (PwEntry)checkedItems.First(), | ||||
|                         new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity))); | ||||
|                         new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity)), App.Kp2a.CurrentDb); | ||||
|  | ||||
|                     ProgressTask pt = new ProgressTask(App.Kp2a, Activity, copyTask); | ||||
|                     pt.Run(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Philipp Crocoll
					Philipp Crocoll