tasks no longer store references to activities. These can "expire" and are hard to update (e.g. if one task creates another). Instead, the app can provide the currently active context.
This commit is contained in:
		| @@ -228,9 +228,9 @@ 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.CurrentDb, App.Kp2a, newEntry,item.Entry.ParentGroup,new ActionOnOperationFinished(this, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); | ||||
|             var addTask = new AddEntry( App.Kp2a.CurrentDb, App.Kp2a, newEntry,item.Entry.ParentGroup,new ActionOnOperationFinished(App.Kp2a,  (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); | ||||
|  | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, this, addTask); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a,  addTask); | ||||
|             pt.Run(); | ||||
|  | ||||
|         } | ||||
| @@ -260,9 +260,9 @@ namespace keepass2android | ||||
|  | ||||
|         private void Save(AutoExecItem item) | ||||
|         { | ||||
|             var addTask = new SaveDb(this, App.Kp2a, App.Kp2a.FindDatabaseForElement(item.Entry), new ActionOnOperationFinished(this, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); | ||||
|             var addTask = new SaveDb(App.Kp2a, App.Kp2a.FindDatabaseForElement(item.Entry), new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); | ||||
|  | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, this, addTask); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a,  addTask); | ||||
|             pt.Run(); | ||||
|         } | ||||
|  | ||||
| @@ -343,7 +343,7 @@ namespace keepass2android | ||||
|             } | ||||
|             if (autoOpenGroup == null) | ||||
|             { | ||||
|                 AddGroup addGroupTask = AddGroup.GetInstance(this, App.Kp2a, "AutoOpen", 1, null, rootGroup, null, true); | ||||
|                 AddGroup addGroupTask = AddGroup.GetInstance(App.Kp2a, "AutoOpen", 1, null, rootGroup, null, true); | ||||
|                 addGroupTask.Run(); | ||||
|                 autoOpenGroup = addGroupTask.Group; | ||||
|             } | ||||
| @@ -367,9 +367,9 @@ namespace keepass2android | ||||
|                         {KeeAutoExecExt.ThisDeviceId, true} | ||||
|                     }))); | ||||
|  | ||||
|             var addTask = new AddEntry(this, db, App.Kp2a, newEntry, autoOpenGroup, new ActionOnOperationFinished(this, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update())); | ||||
|             var addTask = new AddEntry( db, App.Kp2a, newEntry, autoOpenGroup, new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update())); | ||||
|  | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, this, addTask); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, addTask); | ||||
|             pt.Run(); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -213,10 +213,9 @@ namespace keepass2android | ||||
| 			} | ||||
|  | ||||
| 			// Create the new database | ||||
| 			CreateDb create = new CreateDb(App.Kp2a, this, _ioc, new LaunchGroupActivity(_ioc, this), false, newKey, makeCurrent); | ||||
| 			CreateDb create = new CreateDb(App.Kp2a, this, _ioc, new LaunchGroupActivity(_ioc, App.Kp2a, this), false, newKey, makeCurrent); | ||||
| 			BlockingOperationRunner createTask = new BlockingOperationRunner( | ||||
| 				App.Kp2a, | ||||
| 				this, create); | ||||
| 				App.Kp2a, create); | ||||
| 			createTask.Run(); | ||||
| 		} | ||||
|  | ||||
| @@ -403,14 +402,14 @@ namespace keepass2android | ||||
|  | ||||
| 		private class LaunchGroupActivity : FileOnFinish | ||||
| 		{ | ||||
| 			readonly CreateDatabaseActivity _activity; | ||||
| 			private readonly IOConnectionInfo _ioc; | ||||
|             private readonly CreateDatabaseActivity _activity; | ||||
|  | ||||
| 			public LaunchGroupActivity(IOConnectionInfo ioc, CreateDatabaseActivity activity) | ||||
| 				: base(activity, null) | ||||
|             public LaunchGroupActivity(IOConnectionInfo ioc, IKp2aApp app, CreateDatabaseActivity activity) | ||||
| 				: base(app, null) | ||||
| 			{ | ||||
| 				_activity = activity; | ||||
| 				_ioc = ioc; | ||||
|                 _activity = activity; | ||||
|                 _ioc = ioc; | ||||
| 			} | ||||
|  | ||||
| 			public override void Run() | ||||
| @@ -420,7 +419,7 @@ namespace keepass2android | ||||
| 					// Update the ongoing notification | ||||
| 					App.Kp2a.UpdateOngoingNotification(); | ||||
|  | ||||
| 					if (PreferenceManager.GetDefaultSharedPreferences(_activity).GetBoolean(_activity.GetString(Resource.String.RememberRecentFiles_key), _activity.Resources.GetBoolean(Resource.Boolean.RememberRecentFiles_default)))  | ||||
| 					if (PreferenceManager.GetDefaultSharedPreferences(App.Context).GetBoolean(App.Context.GetString(Resource.String.RememberRecentFiles_key), App.Context.Resources.GetBoolean(Resource.Boolean.RememberRecentFiles_default)))  | ||||
| 					{ | ||||
| 						// Add to recent files | ||||
| 						FileDbHelper dbHelper = App.Kp2a.FileDbHelper; | ||||
|   | ||||
| @@ -8,8 +8,8 @@ namespace keepass2android | ||||
| 	{ | ||||
| 		private readonly string _filename; | ||||
|  | ||||
| 		public CreateNewFilename(Activity activity, OnOperationFinishedHandler operationFinishedHandler, string filename) | ||||
| 			: base(activity,operationFinishedHandler) | ||||
| 		public CreateNewFilename(IKp2aApp app, OnOperationFinishedHandler operationFinishedHandler, string filename) | ||||
| 			: base(app,operationFinishedHandler) | ||||
| 		{ | ||||
| 			_filename = filename; | ||||
| 		} | ||||
|   | ||||
| @@ -76,13 +76,13 @@ namespace keepass2android | ||||
|  | ||||
|         protected override void SaveFile(IOConnectionInfo ioc) | ||||
|         { | ||||
|             var task = new EntryActivity.WriteBinaryTask(_activity, App.Kp2a, new ActionOnOperationFinished(_activity, (success, message, activity) => | ||||
|             var task = new EntryActivity.WriteBinaryTask(App.Kp2a, new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => | ||||
|                 { | ||||
|                     if (!success) | ||||
|                         App.Kp2a.ShowMessage(activity, message,  MessageSeverity.Error); | ||||
|                 } | ||||
|             ), ((EntryActivity)_activity).Entry.Binaries.Get(_binaryToSave), ioc); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, _activity, task); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, task); | ||||
|             pt.Run(); | ||||
|  | ||||
|         } | ||||
| @@ -482,8 +482,8 @@ namespace keepass2android | ||||
| 				Entry.Expires = true; | ||||
| 				Entry.Touch(true); | ||||
| 				RequiresRefresh(); | ||||
| 				UpdateEntry update = new UpdateEntry(this, App.Kp2a, backupEntry, Entry, null); | ||||
| 				BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, this, update); | ||||
| 				UpdateEntry update = new UpdateEntry(App.Kp2a, backupEntry, Entry, null); | ||||
| 				BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, update); | ||||
| 				pt.Run(); | ||||
| 			} | ||||
| 			FillData(); | ||||
| @@ -526,7 +526,7 @@ namespace keepass2android | ||||
|                 App.Kp2a.DirtyGroups.Add(parent); | ||||
|             } | ||||
|  | ||||
| 			var saveTask = new SaveDb(this, App.Kp2a, App.Kp2a.FindDatabaseForElement(Entry), new ActionOnOperationFinished(this, (success, message, context) => | ||||
| 			var saveTask = new SaveDb( App.Kp2a, App.Kp2a.FindDatabaseForElement(Entry), new ActionOnOperationFinished(App.Kp2a, (success, message, context) => | ||||
|             { | ||||
| 				if (context is Activity activity) | ||||
|                 { | ||||
| @@ -536,7 +536,7 @@ namespace keepass2android | ||||
|                  | ||||
|             })); | ||||
|  | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, this, saveTask); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, saveTask); | ||||
|             pt.Run(); | ||||
| 		} | ||||
|  | ||||
| @@ -1271,7 +1271,7 @@ namespace keepass2android | ||||
| 	        private readonly ProtectedBinary _data; | ||||
| 	        private IOConnectionInfo _targetIoc; | ||||
|  | ||||
| 	        public WriteBinaryTask(Activity activity, IKp2aApp app, OnOperationFinishedHandler onOperationFinishedHandler, ProtectedBinary data, IOConnectionInfo targetIoc) : base(activity, onOperationFinishedHandler) | ||||
| 	        public WriteBinaryTask(IKp2aApp app, OnOperationFinishedHandler onOperationFinishedHandler, ProtectedBinary data, IOConnectionInfo targetIoc) : base(app, onOperationFinishedHandler) | ||||
| 	        { | ||||
| 	            _app = app; | ||||
| 	            _data = data; | ||||
| @@ -1445,8 +1445,8 @@ namespace keepass2android | ||||
|                     Finish(); | ||||
|                     return true; | ||||
| 				case Resource.Id.menu_delete: | ||||
|                     DeleteEntry task = new DeleteEntry(this, App.Kp2a, Entry, | ||||
|                         new ActionOnOperationFinished(this, (success, message, activity) => { if (success) { RequiresRefresh(); Finish();}})); | ||||
|                     DeleteEntry task = new DeleteEntry(App.Kp2a, Entry, | ||||
|                         new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => { if (success) { RequiresRefresh(); Finish();}})); | ||||
|                     task.Start(); | ||||
|                     break; | ||||
|                 case Resource.Id.menu_toggle_pass: | ||||
| @@ -1509,16 +1509,16 @@ namespace keepass2android | ||||
|  | ||||
| 			//save the entry: | ||||
|  | ||||
| 			ActionOnOperationFinished closeOrShowError = new ActionOnOperationFinished(this, (success, message, activity) => | ||||
| 			ActionOnOperationFinished closeOrShowError = new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => | ||||
| 			{ | ||||
| 				OnOperationFinishedHandler.DisplayMessage(this, message, true); | ||||
| 			    finishAction((EntryActivity)activity); | ||||
| 			}); | ||||
|  | ||||
|  | ||||
| 			OperationWithFinishHandler runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError); | ||||
| 			OperationWithFinishHandler runnable = new UpdateEntry(App.Kp2a, initialEntry, newEntry, closeOrShowError); | ||||
|  | ||||
| 			BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, this, runnable); | ||||
| 			BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, runnable); | ||||
| 			pt.Run(); | ||||
|  | ||||
| 		} | ||||
|   | ||||
| @@ -521,7 +521,7 @@ namespace keepass2android | ||||
| 			 | ||||
| 			OperationWithFinishHandler runnable; | ||||
|  | ||||
| 			ActionOnOperationFinished closeOrShowError = new ActionOnOperationFinished(this, (success, message, context) => { | ||||
| 			ActionOnOperationFinished closeOrShowError = new ActionOnOperationFinished(App.Kp2a, (success, message, context) => { | ||||
| 				if (success) | ||||
| 				{ | ||||
|                     (context as Activity)?.Finish(); | ||||
| @@ -536,18 +536,18 @@ namespace keepass2android | ||||
| 			closeOrShowError.AllowInactiveActivity = true; | ||||
| 			 | ||||
|  | ||||
| 			ActionOnOperationFinished afterAddEntry = new ActionOnOperationFinished(this, (success, message, activity) =>  | ||||
| 			ActionOnOperationFinished afterAddEntry = new ActionOnOperationFinished(App.Kp2a, (success, message, activity) =>  | ||||
| 			{ | ||||
| 				if (success && activity is EntryEditActivity entryEditActivity) | ||||
| 					AppTask.AfterAddNewEntry(entryEditActivity, newEntry); | ||||
| 			},closeOrShowError); | ||||
|  | ||||
| 			if ( State.IsNew ) { | ||||
| 				runnable = AddEntry.GetInstance(this, App.Kp2a, newEntry, State.ParentGroup, afterAddEntry, db); | ||||
| 				runnable = AddEntry.GetInstance(App.Kp2a, newEntry, State.ParentGroup, afterAddEntry, db); | ||||
| 			} else { | ||||
| 				runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError); | ||||
| 				runnable = new UpdateEntry(App.Kp2a, initialEntry, newEntry, closeOrShowError); | ||||
| 			} | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, act, runnable); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, runnable); | ||||
| 			pt.Run(); | ||||
| 			 | ||||
|  | ||||
|   | ||||
| @@ -26,16 +26,16 @@ namespace keepass2android | ||||
|  | ||||
|         protected override void SaveFile(IOConnectionInfo ioc) | ||||
|         { | ||||
|             var exportDb = new ExportDatabaseActivity.ExportDb(_activity, App.Kp2a, new ActionOnOperationFinished(_activity, (success, message, context) => | ||||
|             var exportDb = new ExportDatabaseActivity.ExportDb(App.Kp2a, new ActionOnOperationFinished(App.Kp2a, (success, message, context) => | ||||
|                 { | ||||
|                     if (!success) | ||||
|                         App.Kp2a.ShowMessage(context, message,  MessageSeverity.Error); | ||||
|                         App.Kp2a.ShowMessage(context, message, MessageSeverity.Error); | ||||
|                     else | ||||
|                         App.Kp2a.ShowMessage(context, _activity.GetString(Resource.String.export_database_successful),  MessageSeverity.Info); | ||||
|                         App.Kp2a.ShowMessage(context, _activity.GetString(Resource.String.export_database_successful), MessageSeverity.Info); | ||||
|                     (context as Activity)?.Finish(); | ||||
|                 } | ||||
|             ), _ffp, ioc); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, _activity, exportDb); | ||||
|             BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, exportDb); | ||||
|             pt.Run(); | ||||
|  | ||||
|         } | ||||
| @@ -99,7 +99,7 @@ namespace keepass2android | ||||
| 			private readonly FileFormatProvider _fileFormat; | ||||
| 			private IOConnectionInfo _targetIoc; | ||||
|  | ||||
| 			public ExportDb(Activity activity, IKp2aApp app, OnOperationFinishedHandler onOperationFinishedHandler, FileFormatProvider fileFormat, IOConnectionInfo targetIoc) : base(activity, onOperationFinishedHandler) | ||||
| 			public ExportDb(IKp2aApp app, OnOperationFinishedHandler onOperationFinishedHandler, FileFormatProvider fileFormat, IOConnectionInfo targetIoc) : base(app, onOperationFinishedHandler) | ||||
| 			{ | ||||
| 				_app = app; | ||||
| 				this._fileFormat = fileFormat; | ||||
|   | ||||
| @@ -103,7 +103,7 @@ namespace keepass2android | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             var task = new CreateNewFilename(_activity, new ActionOnOperationFinished(_activity, (success, messageOrFilename, activity) => | ||||
|                             var task = new CreateNewFilename(App.Kp2a, new ActionOnOperationFinished(App.Kp2a, (success, messageOrFilename, activity) => | ||||
|                             { | ||||
|                                 if (!success) | ||||
|                                 { | ||||
| @@ -115,7 +115,7 @@ namespace keepass2android | ||||
|  | ||||
|                             }), filename); | ||||
|  | ||||
|                             new BlockingOperationRunner(App.Kp2a, _activity, task).Run(); | ||||
|                             new BlockingOperationRunner(App.Kp2a, task).Run(); | ||||
|                         } | ||||
|  | ||||
|                         return true; | ||||
|   | ||||
| @@ -781,7 +781,7 @@ namespace keepass2android | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| 						var task = new CreateNewFilename(activity, new ActionOnOperationFinished(activity, (success, messageOrFilename, newActivity) => | ||||
| 						var task = new CreateNewFilename(App.Kp2a, new ActionOnOperationFinished(App.Kp2a, (success, messageOrFilename, newActivity) => | ||||
| 							{ | ||||
| 								if (!success) | ||||
| 								{ | ||||
| @@ -793,7 +793,7 @@ namespace keepass2android | ||||
| 								 | ||||
| 							}), filename); | ||||
|  | ||||
| 						new BlockingOperationRunner(App.Kp2a, activity, task).Run(); | ||||
| 						new BlockingOperationRunner(App.Kp2a, task).Run(); | ||||
| 					} | ||||
|  | ||||
| 				} | ||||
|   | ||||
| @@ -223,8 +223,8 @@ namespace keepass2android | ||||
| 							(o, args) => | ||||
| 							{ | ||||
| 								//yes | ||||
| 								BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, this, | ||||
| 									new AddTemplateEntries(this, App.Kp2a, new ActionOnOperationFinished(this, | ||||
| 								BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a,  | ||||
| 									new AddTemplateEntries(App.Kp2a, new ActionOnOperationFinished(App.Kp2a, | ||||
| 									    (success, message, activity) => ((GroupActivity)activity)?.StartAddEntry()))); | ||||
| 								pt.Run();		 | ||||
| 							}, | ||||
| @@ -235,7 +235,7 @@ namespace keepass2android | ||||
| 								edit.Commit(); | ||||
| 								//no  | ||||
| 								StartAddEntry(); | ||||
| 							},null, this); | ||||
| 							},null); | ||||
| 						 | ||||
| 					} | ||||
| 					else | ||||
|   | ||||
| @@ -206,15 +206,15 @@ namespace keepass2android | ||||
|                 OperationWithFinishHandler task; | ||||
|                 if (strGroupUuid == null) | ||||
|                 { | ||||
|                     task = AddGroup.GetInstance(this, App.Kp2a, groupName, groupIconId, groupCustomIconId, Group, new RefreshTask(handler, this), false); | ||||
|                     task = AddGroup.GetInstance(App.Kp2a, groupName, groupIconId, groupCustomIconId, Group, new RefreshTask(handler, this), false); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     PwUuid groupUuid = new PwUuid(MemUtil.HexStringToByteArray(strGroupUuid)); | ||||
|                     task = new EditGroup(this, App.Kp2a, groupName, (PwIcon)groupIconId, groupCustomIconId, App.Kp2a.FindGroup(groupUuid), | ||||
|                     task = new EditGroup(App.Kp2a, groupName, (PwIcon)groupIconId, groupCustomIconId, App.Kp2a.FindGroup(groupUuid), | ||||
|                                          new RefreshTask(handler, this)); | ||||
|                 } | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, act, task); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, task); | ||||
|                 pt.Run(); | ||||
|             } | ||||
|  | ||||
| @@ -925,14 +925,14 @@ namespace keepass2android | ||||
|  | ||||
|  | ||||
|  | ||||
|             var moveElement = new MoveElements(elementsToMove.ToList(), Group, this, App.Kp2a, new ActionOnOperationFinished(this, | ||||
|             var moveElement = new MoveElements(elementsToMove.ToList(), Group,  App.Kp2a, new ActionOnOperationFinished(App.Kp2a, | ||||
|                 (success, message, activity) => | ||||
|                 { | ||||
|                     ((GroupBaseActivity)activity)?.StopMovingElements(); | ||||
|                     if (!String.IsNullOrEmpty(message)) | ||||
|                         App.Kp2a.ShowMessage(activity, message,  MessageSeverity.Error); | ||||
|                 })); | ||||
|             var progressTask = new BlockingOperationRunner(App.Kp2a, this, moveElement); | ||||
|             var progressTask = new BlockingOperationRunner(App.Kp2a, moveElement); | ||||
|             progressTask.Run(); | ||||
|  | ||||
|         } | ||||
| @@ -1297,7 +1297,7 @@ namespace keepass2android | ||||
|         public class RefreshTask : OnOperationFinishedHandler | ||||
|         { | ||||
|             public RefreshTask(Handler handler, GroupBaseActivity act) | ||||
|                 : base(act, handler) | ||||
|                 : base(App.Kp2a, handler) | ||||
|             { | ||||
|             } | ||||
|  | ||||
| @@ -1316,7 +1316,7 @@ namespace keepass2android | ||||
|         public class AfterDeleteGroup : OnOperationFinishedHandler | ||||
|         { | ||||
|             public AfterDeleteGroup(Handler handler, GroupBaseActivity act) | ||||
|                 : base(act, handler) | ||||
|                 : base(App.Kp2a, handler) | ||||
|             { | ||||
|             } | ||||
|  | ||||
| @@ -1492,10 +1492,10 @@ namespace keepass2android | ||||
|                     break; | ||||
|                 case Resource.Id.menu_copy: | ||||
|  | ||||
|                     var copyTask = new CopyEntry((GroupBaseActivity)Activity, App.Kp2a, (PwEntry)checkedItems.First(), | ||||
|                     var copyTask = new CopyEntry(App.Kp2a, (PwEntry)checkedItems.First(), | ||||
|                         new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity)), App.Kp2a.CurrentDb); | ||||
|  | ||||
|                     BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, Activity, copyTask); | ||||
|                     BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, copyTask); | ||||
|                     pt.Run(); | ||||
|                     break; | ||||
|  | ||||
| @@ -1684,7 +1684,7 @@ namespace keepass2android | ||||
|                         return; | ||||
|                     } | ||||
|                     new DeleteMultipleItemsFromOneDatabase(activity, itemsForDatabases[dbIndex].Key, | ||||
|                         itemsForDatabases[dbIndex].Value, new ActionOnOperationFinished(activeActivity, (b, s, activity1) => action(b, s, activity1)), app) | ||||
|                         itemsForDatabases[dbIndex].Value, new ActionOnOperationFinished(App.Kp2a, (b, s, activity1) => action(b, s, activity1)), app) | ||||
|                         .Start(); | ||||
|                 } | ||||
|                 else | ||||
| @@ -1694,7 +1694,7 @@ namespace keepass2android | ||||
|             }; | ||||
|  | ||||
|             new DeleteMultipleItemsFromOneDatabase(activity, itemsForDatabases[dbIndex].Key, | ||||
|                 itemsForDatabases[dbIndex].Value, new ActionOnOperationFinished(activity, (b, s, activity1) => action(b, s, activity1)), app) | ||||
|                 itemsForDatabases[dbIndex].Value, new ActionOnOperationFinished(App.Kp2a, (b, s, activity1) => action(b, s, activity1)), app) | ||||
|                 .Start(); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -104,8 +104,10 @@ namespace keepass2android | ||||
|  | ||||
|         protected override void OnStart() | ||||
|         { | ||||
|             App.Kp2a.ActiveContext = this; | ||||
|             BlockingOperationRunner.SetNewActiveActivity(this); | ||||
|             BackgroundOperationRunner.Instance.SetNewActiveContext(this, App.Kp2a); | ||||
|             BackgroundOperationRunner.Instance.SetNewActiveContext( App.Kp2a); | ||||
|              | ||||
|             base.OnStart(); | ||||
|             Kp2aLog.Log(ClassName + ".OnStart" + " " + ID); | ||||
|         } | ||||
|   | ||||
| @@ -1447,7 +1447,7 @@ namespace keepass2android | ||||
| 					: new LoadDb(this, App.Kp2a, _ioConnection, _loadDbFileTask, compositeKey, GetKeyProviderString(), onOperationFinishedHandler,true, _makeCurrent); | ||||
| 				_loadDbFileTask = null; // prevent accidental re-use | ||||
|  | ||||
| 			    new BlockingOperationRunner(App.Kp2a, this, task).Run(); | ||||
| 			    new BlockingOperationRunner(App.Kp2a, task).Run(); | ||||
| 			} | ||||
| 			catch (Exception e) | ||||
| 			{ | ||||
| @@ -1889,7 +1889,7 @@ namespace keepass2android | ||||
|                 LoadDb task = new LoadDb(this, App.Kp2a, _ioConnection, _loadDbFileTask, compositeKeyForImmediateLoad, GetKeyProviderString(), | ||||
| 		            onOperationFinishedHandler, false, _makeCurrent); | ||||
| 		        _loadDbFileTask = null; // prevent accidental re-use | ||||
| 		        new BlockingOperationRunner(App.Kp2a, this, task).Run(); | ||||
| 		        new BlockingOperationRunner(App.Kp2a, task).Run(); | ||||
| 		        compositeKeyForImmediateLoad = null; //don't reuse or keep in memory | ||||
|  | ||||
| 		    } | ||||
| @@ -2135,7 +2135,7 @@ namespace keepass2android | ||||
| 			readonly PasswordActivity _act; | ||||
| 		    private readonly IOConnectionInfo _ioConnection; | ||||
|  | ||||
| 		    public AfterLoad(Handler handler, PasswordActivity act, IOConnectionInfo ioConnection):base(act, handler) | ||||
| 		    public AfterLoad(Handler handler, PasswordActivity act, IOConnectionInfo ioConnection):base(App.Kp2a, handler) | ||||
| 		    { | ||||
| 		        _act = act; | ||||
| 		        _ioConnection = ioConnection; | ||||
|   | ||||
| @@ -72,8 +72,8 @@ namespace keepass2android | ||||
| 					 | ||||
| 				} | ||||
| 				 | ||||
| 				SetPassword sp = new SetPassword(_activity, App.Kp2a, pass, keyfile, new AfterSave(_activity, this, null, new Handler())); | ||||
| 				BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, _activity, sp); | ||||
| 				SetPassword sp = new SetPassword(App.Kp2a, pass, keyfile, new AfterSave(_activity, this, null, new Handler())); | ||||
| 				BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, sp); | ||||
| 				pt.Run(); | ||||
| 			}; | ||||
| 				 | ||||
| @@ -93,7 +93,7 @@ namespace keepass2android | ||||
|  | ||||
| 			readonly SetPasswordDialog _dlg; | ||||
| 			 | ||||
| 			public AfterSave(Activity activity, SetPasswordDialog dlg, FileOnFinish operationFinishedHandler, Handler handler): base(activity, operationFinishedHandler, handler) { | ||||
| 			public AfterSave(Activity activity, SetPasswordDialog dlg, FileOnFinish operationFinishedHandler, Handler handler): base(App.Kp2a, operationFinishedHandler, handler) { | ||||
| 				_operationFinishedHandler = operationFinishedHandler; | ||||
| 				_dlg = dlg; | ||||
| 			} | ||||
|   | ||||
| @@ -21,7 +21,7 @@ namespace keepass2android | ||||
|             private readonly IOConnectionInfo _ioc; | ||||
|  | ||||
|             public SyncOtpAuxFile(Activity activity, IOConnectionInfo ioc) | ||||
|                 : base(activity, null) | ||||
|                 : base(App.Kp2a, null) | ||||
|             { | ||||
|                 _ioc = ioc; | ||||
|             } | ||||
| @@ -54,7 +54,7 @@ namespace keepass2android | ||||
|         { | ||||
|             var filestorage = App.Kp2a.GetFileStorage(App.Kp2a.CurrentDb.Ioc); | ||||
|             OperationWithFinishHandler task; | ||||
|             OnOperationFinishedHandler onOperationFinishedHandler = new ActionOnOperationFinished(_activity, (success, message, activity) => | ||||
|             OnOperationFinishedHandler onOperationFinishedHandler = new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => | ||||
|             { | ||||
|                 new Handler(Looper.MainLooper).Post(() => | ||||
|                 { | ||||
| @@ -71,7 +71,7 @@ namespace keepass2android | ||||
|                 { | ||||
|                     var task2 = new SyncOtpAuxFile(_activity, App.Kp2a.CurrentDb.OtpAuxFileIoc); | ||||
|  | ||||
|                     BackgroundOperationRunner.Instance.Run(_activity, App.Kp2a, task2); | ||||
|                     BackgroundOperationRunner.Instance.Run(App.Kp2a, task2); | ||||
|                 } | ||||
|                 | ||||
|             }); | ||||
| @@ -79,15 +79,15 @@ namespace keepass2android | ||||
|             if (filestorage is CachingFileStorage) | ||||
|             { | ||||
|  | ||||
|                 task = new SynchronizeCachedDatabase(_activity, App.Kp2a, onOperationFinishedHandler); | ||||
|                 task = new SynchronizeCachedDatabase(App.Kp2a, onOperationFinishedHandler); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 //TODO do we want this to run in the background? | ||||
|                 task = new CheckDatabaseForChanges(_activity, App.Kp2a, onOperationFinishedHandler); | ||||
|                 task = new CheckDatabaseForChanges( App.Kp2a, onOperationFinishedHandler); | ||||
|             } | ||||
|  | ||||
|             BackgroundOperationRunner.Instance.Run(_activity, App.Kp2a, task); | ||||
|             BackgroundOperationRunner.Instance.Run(App.Kp2a, task); | ||||
|  | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -576,20 +576,19 @@ namespace keepass2android | ||||
| 			return LocaleManager.LocalizedAppContext.Resources.GetDrawable((int)field.GetValue(null)); | ||||
| 		} | ||||
|  | ||||
| 		public void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey, EventHandler<DialogClickEventArgs> yesHandler, EventHandler<DialogClickEventArgs> noHandler, EventHandler<DialogClickEventArgs> cancelHandler, Context ctx, string messageSuffix) | ||||
| 		public void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey, EventHandler<DialogClickEventArgs> yesHandler, EventHandler<DialogClickEventArgs> noHandler, EventHandler<DialogClickEventArgs> cancelHandler,  string messageSuffix) | ||||
| 		{ | ||||
| 			AskYesNoCancel(titleKey, messageKey, UiStringKey.yes, UiStringKey.no, | ||||
| 				yesHandler, noHandler, cancelHandler, ctx, messageSuffix); | ||||
| 				yesHandler, noHandler, cancelHandler, messageSuffix); | ||||
| 		} | ||||
|  | ||||
| 		public void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey, | ||||
| 			UiStringKey yesString, UiStringKey noString, | ||||
| 			EventHandler<DialogClickEventArgs> yesHandler, | ||||
| 			EventHandler<DialogClickEventArgs> noHandler, | ||||
| 			EventHandler<DialogClickEventArgs> cancelHandler, | ||||
| 			Context ctx, string messageSuffix = "") | ||||
| 			EventHandler<DialogClickEventArgs> cancelHandler, string messageSuffix = "") | ||||
| 		{ | ||||
| 			AskYesNoCancel(titleKey, messageKey, yesString, noString, yesHandler, noHandler, cancelHandler, null, ctx, messageSuffix); | ||||
| 			AskYesNoCancel(titleKey, messageKey, yesString, noString, yesHandler, noHandler, cancelHandler, null, messageSuffix); | ||||
| 		} | ||||
|  | ||||
| 		public void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey, | ||||
| @@ -597,13 +596,12 @@ namespace keepass2android | ||||
| 			EventHandler<DialogClickEventArgs> yesHandler, | ||||
|             EventHandler<DialogClickEventArgs> noHandler, | ||||
|             EventHandler<DialogClickEventArgs> cancelHandler, | ||||
| 			EventHandler dismissHandler, | ||||
|             Context ctx, string messageSuffix = "") | ||||
| 			EventHandler dismissHandler,string messageSuffix = "") | ||||
|         { | ||||
| 			Handler handler = new Handler(Looper.MainLooper); | ||||
| 			handler.Post(() => | ||||
| 				{ | ||||
| 					MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(ctx); | ||||
| 					MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(ActiveContext); | ||||
| 					builder.SetTitle(GetResourceString(titleKey)); | ||||
|  | ||||
| 					builder.SetMessage(GetResourceString(messageKey) + (messageSuffix != "" ? " " + messageSuffix : "")); | ||||
| @@ -638,7 +636,7 @@ namespace keepass2android | ||||
| 							cancelHandler.Invoke(sender, args); | ||||
| 						}; | ||||
|  | ||||
| 						cancelText = ctx.GetString(Android.Resource.String.Cancel); | ||||
| 						cancelText = App.Context.GetString(Android.Resource.String.Cancel); | ||||
| 						builder.SetNeutralButton(cancelText, | ||||
| 												 cancelHandlerWithShow); | ||||
| 					} | ||||
| @@ -653,9 +651,17 @@ namespace keepass2android | ||||
| 					} | ||||
|  | ||||
| 					OnUserInputDialogShow(); | ||||
| 					dialog.Show(); | ||||
|                     try | ||||
|                     { | ||||
|                         dialog.Show(); | ||||
|                     } | ||||
| 					catch (Exception e) | ||||
|                     { | ||||
|                         Kp2aLog.LogUnexpectedError(e); | ||||
|                     } | ||||
|  | ||||
| 					if (yesText.Length + noText.Length + cancelText.Length >= 20) | ||||
|  | ||||
|                     if (yesText.Length + noText.Length + cancelText.Length >= 20) | ||||
| 					{ | ||||
| 						try | ||||
| 						{ | ||||
| @@ -1362,6 +1368,8 @@ namespace keepass2android | ||||
|             } | ||||
|              | ||||
|         } | ||||
|  | ||||
|         public Context ActiveContext { get; set; } | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -1432,7 +1440,10 @@ namespace keepass2android | ||||
|         public void OnAppBackgrounded() | ||||
|         { | ||||
|             Kp2aLog.Log("Going to background"); | ||||
|             BackgroundOperationRunner.Instance.SetNewActiveContext(null, Kp2a); | ||||
|             Kp2a.ActiveContext = null; | ||||
|             BackgroundOperationRunner.Instance.SetNewActiveContext( Kp2a); | ||||
|              | ||||
|  | ||||
|         } | ||||
|  | ||||
|         [Lifecycle.Event.OnStart] | ||||
|   | ||||
| @@ -51,7 +51,8 @@ namespace keepass2android.services | ||||
|                 _cts = new CancellationTokenSource(); | ||||
|                 CreateNotificationChannel(); | ||||
|                 StartForeground(NotificationId, BuildNotification()); | ||||
|                 BackgroundOperationRunner.Instance.SetNewActiveContext(this, App.Kp2a); | ||||
|                 App.Kp2a.ActiveContext = this; | ||||
|                 BackgroundOperationRunner.Instance.SetNewActiveContext(App.Kp2a); | ||||
|                 return StartCommandResult.Sticky; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|   | ||||
| @@ -117,7 +117,7 @@ namespace keepass2android | ||||
|                         var previousUsername = db.KpDatabase.DefaultUserName; | ||||
|                         db.KpDatabase.DefaultUserName = e.NewValue.ToString(); | ||||
|  | ||||
|                         SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(Activity, (success, message, activity) => | ||||
|                         SaveDb save = new SaveDb(App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => | ||||
|                         { | ||||
|                             if (!success) | ||||
|                             { | ||||
| @@ -126,7 +126,7 @@ namespace keepass2android | ||||
|                                 App.Kp2a.ShowMessage(activity, message,  MessageSeverity.Error); | ||||
|                             } | ||||
|                         })); | ||||
|                         BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, Activity, save); | ||||
|                         BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, save); | ||||
|                         pt.Run(); | ||||
|                     }; | ||||
|                 } | ||||
| @@ -144,8 +144,8 @@ namespace keepass2android | ||||
|                 { | ||||
|                     pref.PreferenceClick += (sender, args) => | ||||
|                     { | ||||
|                         BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, Activity, | ||||
|                                         new AddTemplateEntries(Activity, App.Kp2a, new ActionOnOperationFinished(Activity, | ||||
|                         BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a,  | ||||
|                                         new AddTemplateEntries(App.Kp2a, new ActionOnOperationFinished(App.Kp2a, | ||||
|                                             delegate | ||||
|                                             { | ||||
|                                                 pref.Enabled = false; | ||||
| @@ -183,7 +183,7 @@ namespace keepass2android | ||||
|                         String previousName = db.KpDatabase.Name; | ||||
|                         db.KpDatabase.Name = e.NewValue.ToString(); | ||||
|  | ||||
|                         SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(Activity, (success, message, activity) => | ||||
|                         SaveDb save = new SaveDb(App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => | ||||
|                         { | ||||
|                             if (!success) | ||||
|                             { | ||||
| @@ -197,7 +197,7 @@ namespace keepass2android | ||||
|                                 App.Kp2a.UpdateOngoingNotification(); | ||||
|                             } | ||||
|                         })); | ||||
|                         BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, Activity, save); | ||||
|                         BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, save); | ||||
|                         pt.Run(); | ||||
|                     }; | ||||
|                 } | ||||
| @@ -410,7 +410,7 @@ namespace keepass2android | ||||
|                 var previousCipher = db.KpDatabase.DataCipherUuid; | ||||
|                 db.KpDatabase.DataCipherUuid = new PwUuid(MemUtil.HexStringToByteArray((string)preferenceChangeEventArgs.NewValue)); | ||||
|  | ||||
|                 SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(Activity, (success, message, activity) => | ||||
|                 SaveDb save = new SaveDb(App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => | ||||
|                 { | ||||
|                     if (!success) | ||||
|                     { | ||||
| @@ -421,7 +421,7 @@ namespace keepass2android | ||||
|                     preferenceChangeEventArgs.Preference.Summary = | ||||
|                         CipherPool.GlobalPool.GetCipher(db.KpDatabase.DataCipherUuid).DisplayName; | ||||
|                 })); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, Activity, save); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, save); | ||||
|                 pt.Run(); | ||||
|             } | ||||
|  | ||||
| @@ -1071,7 +1071,7 @@ namespace keepass2android | ||||
|  | ||||
|                 Kp2aLog.Log("--new    kdf: " + KdfPool.Get(db.KpDatabase.KdfParameters.KdfUuid) + " " + db.KpDatabase.KdfParameters.KdfUuid.ToHexString()); | ||||
|  | ||||
|                 SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(Activity, (success, message, activity) => | ||||
|                 SaveDb save = new SaveDb(App.Kp2a, App.Kp2a.CurrentDb, new ActionOnOperationFinished(App.Kp2a, (success, message, activity) => | ||||
|                 { | ||||
|                     if (!success) | ||||
|                     { | ||||
| @@ -1082,7 +1082,7 @@ namespace keepass2android | ||||
|                     UpdateKdfScreen(); | ||||
|  | ||||
|                 })); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, Activity, save); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, save); | ||||
|                 pt.Run(); | ||||
|  | ||||
|             } | ||||
|   | ||||
| @@ -18,8 +18,8 @@ namespace keepass2android | ||||
|             private readonly IKp2aApp _app; | ||||
|             private IOConnectionInfo _targetIoc; | ||||
|  | ||||
|             public ExportKeyfile(Activity activity, IKp2aApp app, OnOperationFinishedHandler onOperationFinishedHandler, IOConnectionInfo targetIoc) : base( | ||||
|                 activity, onOperationFinishedHandler) | ||||
|             public ExportKeyfile(IKp2aApp app, OnOperationFinishedHandler onOperationFinishedHandler, IOConnectionInfo targetIoc) : base( | ||||
|                 App.Kp2a, onOperationFinishedHandler) | ||||
|             { | ||||
|                 _app = app; | ||||
|                 _targetIoc = targetIoc; | ||||
| @@ -70,7 +70,7 @@ namespace keepass2android | ||||
|  | ||||
|             protected override void SaveFile(IOConnectionInfo ioc) | ||||
|             { | ||||
|                 var exportKeyfile = new ExportKeyfile(_activity, App.Kp2a, new ActionOnOperationFinished(_activity, | ||||
|                 var exportKeyfile = new ExportKeyfile(App.Kp2a, new ActionOnOperationFinished(App.Kp2a, | ||||
|                     (success, message, context) => | ||||
|                     { | ||||
|                         if (!success) | ||||
| @@ -81,7 +81,7 @@ namespace keepass2android | ||||
|                         (context as Activity)?.Finish(); | ||||
|                     } | ||||
|                 ), ioc); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, _activity, exportKeyfile); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, exportKeyfile); | ||||
|                 pt.Run(); | ||||
|  | ||||
|             } | ||||
|   | ||||
| @@ -113,8 +113,8 @@ namespace keepass2android.settings | ||||
|                 ParamValue = paramValue; | ||||
|  | ||||
|                 Handler handler = new Handler(); | ||||
|                 SaveDb save = new SaveDb((Activity)Context, App.Kp2a, App.Kp2a.CurrentDb, new AfterSave((Activity)Context, handler, oldValue, this)); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, (Activity)Context, save); | ||||
|                 SaveDb save = new SaveDb(App.Kp2a, App.Kp2a.CurrentDb, new AfterSave(App.Kp2a, handler, oldValue, this)); | ||||
|                 BlockingOperationRunner pt = new BlockingOperationRunner(App.Kp2a, save); | ||||
|                 pt.Run(); | ||||
|             }); | ||||
|             db.SetNegativeButton(Android.Resource.String.Cancel, ((sender, args) => { })); | ||||
| @@ -131,13 +131,12 @@ namespace keepass2android.settings | ||||
|  | ||||
| 		private class AfterSave : OnOperationFinishedHandler { | ||||
| 			private readonly ulong _oldParamValue; | ||||
| 			private readonly Context _ctx; | ||||
| 			private readonly KdfNumberDialogPreference _pref; | ||||
|             private readonly IKp2aApp _app; | ||||
|             private readonly KdfNumberDialogPreference _pref; | ||||
| 			 | ||||
| 			public AfterSave(Activity ctx, Handler handler, ulong oldParamValue, KdfNumberDialogPreference pref):base(ctx, handler) { | ||||
|  | ||||
| 				_pref = pref; | ||||
| 				_ctx = ctx; | ||||
| 			public AfterSave(IKp2aApp app, Handler handler, ulong oldParamValue, KdfNumberDialogPreference pref):base(app, handler) { | ||||
|                 _app = app; | ||||
|                 _pref = pref; | ||||
| 				_oldParamValue = oldParamValue; | ||||
| 			} | ||||
| 			 | ||||
| @@ -148,7 +147,7 @@ namespace keepass2android.settings | ||||
| 						_pref.OnPreferenceChangeListener.OnPreferenceChange(_pref, null); | ||||
| 					} | ||||
| 				} else { | ||||
| 					DisplayMessage(_ctx); | ||||
| 					DisplayMessage(_app.ActiveContext); | ||||
|  | ||||
| 					_pref.ParamValue = _oldParamValue; | ||||
|                 } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Philipp Crocoll
					Philipp Crocoll