refactoring of ProgressTask and OnFinish classes, allowing to access the currently active activity from the task handlers. This fixes #33 and is required to correctly manage the activity recreation caused by the NFC activity coming to foreground with KeepassXC challenge (#4)
This commit is contained in:
@@ -30,8 +30,12 @@ namespace keepass2android
|
|||||||
readonly IKp2aApp _app;
|
readonly IKp2aApp _app;
|
||||||
private readonly Handler _handler;
|
private readonly Handler _handler;
|
||||||
private string _message = "";
|
private string _message = "";
|
||||||
|
private string _submessage;
|
||||||
|
|
||||||
public ProgressDialogStatusLogger() {
|
public String SubMessage => _submessage;
|
||||||
|
public String Message => _message;
|
||||||
|
|
||||||
|
public ProgressDialogStatusLogger() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +60,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
public void UpdateSubMessage(String submessage)
|
public void UpdateSubMessage(String submessage)
|
||||||
{
|
{
|
||||||
|
_submessage = submessage;
|
||||||
if (_app != null && _progressDialog != null && _handler != null)
|
if (_app != null && _progressDialog != null && _handler != null)
|
||||||
{
|
{
|
||||||
_handler.Post(() =>
|
_handler.Post(() =>
|
||||||
|
@@ -25,33 +25,94 @@ namespace keepass2android
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class to run a task while a progress dialog is shown
|
/// Class to run a task while a progress dialog is shown
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProgressTask {
|
public class ProgressTask
|
||||||
private readonly Handler _handler;
|
{
|
||||||
|
//for handling Activity recreation situations, we need access to the currently active task. It must hold that there is no more than one active task.
|
||||||
|
private static ProgressTask _currentTask = null;
|
||||||
|
|
||||||
|
public static void SetNewActiveActivity(Activity activeActivity)
|
||||||
|
{
|
||||||
|
if (_currentTask != null)
|
||||||
|
{
|
||||||
|
_currentTask.ActiveActivity = activeActivity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void RemoveActiveActivity(Activity activity)
|
||||||
|
{
|
||||||
|
if ((_currentTask != null) && (_currentTask._activeActivity == activity))
|
||||||
|
_currentTask.ActiveActivity = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Activity ActiveActivity
|
||||||
|
{
|
||||||
|
get { return _activeActivity; }
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
_activeActivity = value;
|
||||||
|
if (_task != null)
|
||||||
|
_task.ActiveActivity = _activeActivity;
|
||||||
|
if (_activeActivity != null)
|
||||||
|
{
|
||||||
|
SetupProgressDialog(_app);
|
||||||
|
_progressDialog.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Handler _handler;
|
||||||
private readonly RunnableOnFinish _task;
|
private readonly RunnableOnFinish _task;
|
||||||
private readonly IProgressDialog _progressDialog;
|
private IProgressDialog _progressDialog;
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
private Thread _thread;
|
private Thread _thread;
|
||||||
|
private Activity _activeActivity;
|
||||||
|
private ProgressDialogStatusLogger _progressDialogStatusLogger;
|
||||||
|
|
||||||
public ProgressTask(IKp2aApp app, Context ctx, RunnableOnFinish task) {
|
public ProgressTask(IKp2aApp app, Activity activity, RunnableOnFinish task)
|
||||||
|
{
|
||||||
|
_activeActivity = activity;
|
||||||
_task = task;
|
_task = task;
|
||||||
_handler = app.UiThreadHandler;
|
_handler = app.UiThreadHandler;
|
||||||
_app = app;
|
_app = app;
|
||||||
|
|
||||||
// Show process dialog
|
SetupProgressDialog(app);
|
||||||
_progressDialog = app.CreateProgressDialog(ctx);
|
|
||||||
_progressDialog.SetTitle(_app.GetResourceString(UiStringKey.progress_title));
|
// Set code to run when this is finished
|
||||||
_progressDialog.SetMessage("Initializing...");
|
_task.OnFinishToRun = new AfterTask(activity, task.OnFinishToRun, _handler, this);
|
||||||
|
|
||||||
// Set code to run when this is finished
|
_task.SetStatusLogger(_progressDialogStatusLogger);
|
||||||
_task.OnFinishToRun = new AfterTask(task.OnFinishToRun, _handler, _progressDialog);
|
|
||||||
_task.SetStatusLogger(new ProgressDialogStatusLogger(_app, _handler, _progressDialog));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run() {
|
private void SetupProgressDialog(IKp2aApp app)
|
||||||
// Show process dialog
|
{
|
||||||
_progressDialog.Show();
|
string currentMessage = "Initializing...";
|
||||||
|
string currentSubmessage = "";
|
||||||
|
|
||||||
|
if (_progressDialogStatusLogger != null)
|
||||||
|
{
|
||||||
|
currentMessage = _progressDialogStatusLogger.Message;
|
||||||
|
currentSubmessage = _progressDialogStatusLogger.SubMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Show process dialog
|
||||||
|
_progressDialog = app.CreateProgressDialog(_activeActivity);
|
||||||
|
_progressDialog.SetTitle(_app.GetResourceString(UiStringKey.progress_title));
|
||||||
|
_progressDialogStatusLogger = new ProgressDialogStatusLogger(_app, _handler, _progressDialog);
|
||||||
|
_progressDialogStatusLogger.UpdateMessage(currentMessage);
|
||||||
|
_progressDialogStatusLogger.UpdateSubMessage(currentSubmessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run(bool allowOverwriteCurrentTask = false)
|
||||||
|
{
|
||||||
|
if ((!allowOverwriteCurrentTask) && (_currentTask != null))
|
||||||
|
throw new Exception("Cannot start another ProgressTask while ProgressTask is already running! " + _task.GetType().Name + "/" + _currentTask._task.GetType().Name);
|
||||||
|
_currentTask = this;
|
||||||
|
|
||||||
|
// Show process dialog
|
||||||
|
_progressDialog.Show();
|
||||||
|
|
||||||
|
|
||||||
// Start Thread to Run task
|
// Start Thread to Run task
|
||||||
@@ -66,11 +127,11 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class AfterTask : OnFinish {
|
private class AfterTask : OnFinish {
|
||||||
readonly IProgressDialog _progressDialog;
|
readonly ProgressTask _progressTask;
|
||||||
|
|
||||||
public AfterTask (OnFinish finish, Handler handler, IProgressDialog pd): base(finish, handler)
|
public AfterTask (Activity activity, OnFinish finish, Handler handler, ProgressTask pt): base(activity, finish, handler)
|
||||||
{
|
{
|
||||||
_progressDialog = pd;
|
_progressTask = pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Run() {
|
public override void Run() {
|
||||||
@@ -79,17 +140,19 @@ namespace keepass2android
|
|||||||
if (Handler != null) //can be null in tests
|
if (Handler != null) //can be null in tests
|
||||||
{
|
{
|
||||||
// Remove the progress dialog
|
// Remove the progress dialog
|
||||||
Handler.Post(delegate { _progressDialog.Dismiss(); });
|
Handler.Post(delegate { _progressTask._progressDialog.Dismiss(); });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_progressDialog.Dismiss();
|
_progressTask._progressDialog.Dismiss();
|
||||||
}
|
}
|
||||||
|
_currentTask = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,8 +18,8 @@ namespace keepass2android
|
|||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
|
|
||||||
|
|
||||||
public CheckDatabaseForChanges(Context context, IKp2aApp app, OnFinish finish)
|
public CheckDatabaseForChanges(Activity context, IKp2aApp app, OnFinish finish)
|
||||||
: base(finish)
|
: base(context, finish)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_app = app;
|
_app = app;
|
||||||
|
@@ -21,7 +21,6 @@ using System.IO;
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Android.Content;
|
|
||||||
using Java.Lang;
|
using Java.Lang;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Keys;
|
using KeePassLib.Keys;
|
||||||
@@ -218,7 +217,7 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SaveData(Context ctx) {
|
public void SaveData() {
|
||||||
|
|
||||||
KpDatabase.UseFileTransactions = _app.GetBooleanPreference(PreferenceKey.UseFileTransactions);
|
KpDatabase.UseFileTransactions = _app.GetBooleanPreference(PreferenceKey.UseFileTransactions);
|
||||||
using (IWriteTransaction trans = _app.GetFileStorage(Ioc).OpenWriteTransaction(Ioc, KpDatabase.UseFileTransactions))
|
using (IWriteTransaction trans = _app.GetFileStorage(Ioc).OpenWriteTransaction(Ioc, KpDatabase.UseFileTransactions))
|
||||||
|
@@ -11,12 +11,12 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
public class SynchronizeCachedDatabase: RunnableOnFinish
|
public class SynchronizeCachedDatabase: RunnableOnFinish
|
||||||
{
|
{
|
||||||
private readonly Context _context;
|
private readonly Activity _context;
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
private SaveDb _saveDb;
|
private SaveDb _saveDb;
|
||||||
|
|
||||||
public SynchronizeCachedDatabase(Context context, IKp2aApp app, OnFinish finish)
|
public SynchronizeCachedDatabase(Activity context, IKp2aApp app, OnFinish finish)
|
||||||
: base(finish)
|
: base(context, finish)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_app = app;
|
_app = app;
|
||||||
@@ -59,7 +59,7 @@ namespace keepass2android
|
|||||||
if (cachingFileStorage.HasLocalChanges(ioc))
|
if (cachingFileStorage.HasLocalChanges(ioc))
|
||||||
{
|
{
|
||||||
//conflict! need to merge
|
//conflict! need to merge
|
||||||
_saveDb = new SaveDb(_context, _app, new ActionOnFinish((success, result) =>
|
_saveDb = new SaveDb(_context, _app, new ActionOnFinish(ActiveActivity, (success, result, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
|
@@ -16,41 +16,37 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
|
|
||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
{
|
{
|
||||||
public class ActionOnFinish: OnFinish
|
public class ActionOnFinish: OnFinish
|
||||||
{
|
{
|
||||||
public delegate void ActionToPerformOnFinsh(bool success, String message);
|
public delegate void ActionToPerformOnFinsh(bool success, String message, Activity activeActivity);
|
||||||
|
|
||||||
readonly ActionToPerformOnFinsh _actionToPerform;
|
readonly ActionToPerformOnFinsh _actionToPerform;
|
||||||
|
|
||||||
public ActionOnFinish(ActionToPerformOnFinsh actionToPerform) : base(null, null)
|
public ActionOnFinish(Activity activity, ActionToPerformOnFinsh actionToPerform) : base(activity, null, null)
|
||||||
{
|
{
|
||||||
_actionToPerform = actionToPerform;
|
_actionToPerform = actionToPerform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionOnFinish(ActionToPerformOnFinsh actionToPerform, OnFinish finish) : base(finish)
|
public ActionOnFinish(Activity activity, ActionToPerformOnFinsh actionToPerform, OnFinish finish) : base(activity, finish)
|
||||||
{
|
{
|
||||||
_actionToPerform = actionToPerform;
|
_actionToPerform = actionToPerform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionOnFinish(ActionToPerformOnFinsh actionToPerform, Handler handler) : base(handler)
|
|
||||||
{
|
|
||||||
_actionToPerform = actionToPerform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Run()
|
public override void Run()
|
||||||
{
|
{
|
||||||
if (Message == null)
|
if (Message == null)
|
||||||
Message = "";
|
Message = "";
|
||||||
if (Handler != null)
|
if (Handler != null)
|
||||||
{
|
{
|
||||||
Handler.Post(() => {_actionToPerform(Success, Message);});
|
Handler.Post(() => {_actionToPerform(Success, Message, ActiveActivity);});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_actionToPerform(Success, Message);
|
_actionToPerform(Success, Message, ActiveActivity);
|
||||||
base.Run();
|
base.Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
|
||||||
@@ -29,20 +30,20 @@ namespace keepass2android
|
|||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
private readonly PwEntry _entry;
|
private readonly PwEntry _entry;
|
||||||
private readonly PwGroup _parentGroup;
|
private readonly PwGroup _parentGroup;
|
||||||
private readonly Context _ctx;
|
private readonly Activity _ctx;
|
||||||
|
|
||||||
public static AddEntry GetInstance(Context ctx, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish) {
|
public static AddEntry GetInstance(Activity ctx, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish) {
|
||||||
|
|
||||||
return new AddEntry(ctx, app, entry, parentGroup, finish);
|
return new AddEntry(ctx, app, entry, parentGroup, finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AddEntry(Context ctx, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish):base(finish) {
|
protected AddEntry(Activity ctx, IKp2aApp app, PwEntry entry, PwGroup parentGroup, OnFinish finish):base(ctx, finish) {
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_parentGroup = parentGroup;
|
_parentGroup = parentGroup;
|
||||||
_app = app;
|
_app = app;
|
||||||
_entry = entry;
|
_entry = entry;
|
||||||
|
|
||||||
_onFinishToRun = new AfterAdd(app.GetDb(), entry, OnFinishToRun);
|
_onFinishToRun = new AfterAdd(ctx, app.GetDb(), entry, OnFinishToRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ namespace keepass2android
|
|||||||
private readonly Database _db;
|
private readonly Database _db;
|
||||||
private readonly PwEntry _entry;
|
private readonly PwEntry _entry;
|
||||||
|
|
||||||
public AfterAdd(Database db, PwEntry entry, OnFinish finish):base(finish) {
|
public AfterAdd(Activity activity, Database db, PwEntry entry, OnFinish finish):base(activity, finish) {
|
||||||
_db = db;
|
_db = db;
|
||||||
_entry = entry;
|
_entry = entry;
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
|
||||||
@@ -34,16 +35,16 @@ namespace keepass2android
|
|||||||
internal PwGroup Group;
|
internal PwGroup Group;
|
||||||
internal PwGroup Parent;
|
internal PwGroup Parent;
|
||||||
protected bool DontSave;
|
protected bool DontSave;
|
||||||
readonly Context _ctx;
|
readonly Activity _ctx;
|
||||||
|
|
||||||
|
|
||||||
public static AddGroup GetInstance(Context ctx, IKp2aApp app, string name, int iconid, PwUuid groupCustomIconId, PwGroup parent, OnFinish finish, bool dontSave) {
|
public static AddGroup GetInstance(Activity ctx, IKp2aApp app, string name, int iconid, PwUuid groupCustomIconId, PwGroup parent, OnFinish finish, bool dontSave) {
|
||||||
return new AddGroup(ctx, app, name, iconid, groupCustomIconId, parent, finish, dontSave);
|
return new AddGroup(ctx, app, name, iconid, groupCustomIconId, parent, finish, dontSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private AddGroup(Context ctx, IKp2aApp app, String name, int iconid, PwUuid groupCustomIconId, PwGroup parent, OnFinish finish, bool dontSave)
|
private AddGroup(Activity ctx, IKp2aApp app, String name, int iconid, PwUuid groupCustomIconId, PwGroup parent, OnFinish finish, bool dontSave)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_name = name;
|
_name = name;
|
||||||
@@ -53,7 +54,7 @@ namespace keepass2android
|
|||||||
DontSave = dontSave;
|
DontSave = dontSave;
|
||||||
_app = app;
|
_app = app;
|
||||||
|
|
||||||
_onFinishToRun = new AfterAdd(this, OnFinishToRun);
|
_onFinishToRun = new AfterAdd(ctx, this, OnFinishToRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ namespace keepass2android
|
|||||||
private class AfterAdd : OnFinish {
|
private class AfterAdd : OnFinish {
|
||||||
readonly AddGroup _addGroup;
|
readonly AddGroup _addGroup;
|
||||||
|
|
||||||
public AfterAdd(AddGroup addGroup,OnFinish finish): base(finish) {
|
public AfterAdd(Activity activity, AddGroup addGroup,OnFinish finish): base(activity, finish) {
|
||||||
_addGroup = addGroup;
|
_addGroup = addGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ This file is part of Keepass2Android, Copyright 2016 Philipp Crocoll. This file
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Security;
|
using KeePassLib.Security;
|
||||||
@@ -128,10 +129,10 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
private readonly Context _ctx;
|
private readonly Activity _ctx;
|
||||||
|
|
||||||
public AddTemplateEntries(Context ctx, IKp2aApp app, OnFinish finish)
|
public AddTemplateEntries(Activity ctx, IKp2aApp app, OnFinish finish)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_app = app;
|
_app = app;
|
||||||
@@ -358,7 +359,7 @@ namespace keepass2android
|
|||||||
private readonly Database _db;
|
private readonly Database _db;
|
||||||
private readonly List<PwEntry> _entries;
|
private readonly List<PwEntry> _entries;
|
||||||
|
|
||||||
public AfterAdd(Database db, List<PwEntry> entries, OnFinish finish):base(finish) {
|
public AfterAdd(Activity activity, Database db, List<PwEntry> entries, OnFinish finish):base(activity, finish) {
|
||||||
_db = db;
|
_db = db;
|
||||||
_entries = entries;
|
_entries = entries;
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ namespace keepass2android.database.edit
|
|||||||
{
|
{
|
||||||
public class CopyEntry: AddEntry
|
public class CopyEntry: AddEntry
|
||||||
{
|
{
|
||||||
public CopyEntry(Context ctx, IKp2aApp app, PwEntry entry, OnFinish finish)
|
public CopyEntry(Activity ctx, IKp2aApp app, PwEntry entry, OnFinish finish)
|
||||||
: base(ctx, app, CreateCopy(entry, app), entry.ParentGroup, finish)
|
: base(ctx, app, CreateCopy(entry, app), entry.ParentGroup, finish)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Cryptography.KeyDerivation;
|
using KeePassLib.Cryptography.KeyDerivation;
|
||||||
@@ -31,19 +32,19 @@ namespace keepass2android
|
|||||||
|
|
||||||
private readonly IOConnectionInfo _ioc;
|
private readonly IOConnectionInfo _ioc;
|
||||||
private readonly bool _dontSave;
|
private readonly bool _dontSave;
|
||||||
private readonly Context _ctx;
|
private readonly Activity _ctx;
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
private CompositeKey _key;
|
private CompositeKey _key;
|
||||||
|
|
||||||
public CreateDb(IKp2aApp app, Context ctx, IOConnectionInfo ioc, OnFinish finish, bool dontSave): base(finish) {
|
public CreateDb(IKp2aApp app, Activity ctx, IOConnectionInfo ioc, OnFinish finish, bool dontSave): base(ctx, finish) {
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_ioc = ioc;
|
_ioc = ioc;
|
||||||
_dontSave = dontSave;
|
_dontSave = dontSave;
|
||||||
_app = app;
|
_app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateDb(IKp2aApp app, Context ctx, IOConnectionInfo ioc, OnFinish finish, bool dontSave, CompositeKey key)
|
public CreateDb(IKp2aApp app, Activity ctx, IOConnectionInfo ioc, OnFinish finish, bool dontSave, CompositeKey key)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_ioc = ioc;
|
_ioc = ioc;
|
||||||
|
@@ -17,6 +17,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Interfaces;
|
using KeePassLib.Interfaces;
|
||||||
@@ -28,8 +29,8 @@ namespace keepass2android
|
|||||||
private readonly PwEntry _entry;
|
private readonly PwEntry _entry;
|
||||||
private UiStringKey _statusMessage;
|
private UiStringKey _statusMessage;
|
||||||
|
|
||||||
public DeleteEntry(Context ctx, IKp2aApp app, PwEntry entry, OnFinish finish):base(finish, app) {
|
public DeleteEntry(Activity activiy, IKp2aApp app, PwEntry entry, OnFinish finish):base(activiy, finish, app) {
|
||||||
Ctx = ctx;
|
Ctx = activiy;
|
||||||
Db = app.GetDb();
|
Db = app.GetDb();
|
||||||
_entry = entry;
|
_entry = entry;
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
|
||||||
@@ -28,10 +29,10 @@ namespace keepass2android
|
|||||||
private PwGroup _group;
|
private PwGroup _group;
|
||||||
protected bool DontSave;
|
protected bool DontSave;
|
||||||
|
|
||||||
public DeleteGroup(Context ctx, IKp2aApp app, PwGroup group, OnFinish finish)
|
public DeleteGroup(Activity activity, IKp2aApp app, PwGroup group, OnFinish finish)
|
||||||
: base(finish, app)
|
: base(activity, finish, app)
|
||||||
{
|
{
|
||||||
SetMembers(ctx, app, group, false);
|
SetMembers(activity, app, group, false);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
public DeleteGroup(Context ctx, Database db, PwGroup group, Activity act, OnFinish finish, bool dontSave)
|
public DeleteGroup(Context ctx, Database db, PwGroup group, Activity act, OnFinish finish, bool dontSave)
|
||||||
@@ -44,9 +45,9 @@ namespace keepass2android
|
|||||||
SetMembers(ctx, db, group, null, dontSave);
|
SetMembers(ctx, db, group, null, dontSave);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
private void SetMembers(Context ctx, IKp2aApp app, PwGroup group, bool dontSave)
|
private void SetMembers(Activity activity, IKp2aApp app, PwGroup group, bool dontSave)
|
||||||
{
|
{
|
||||||
base.SetMembers(ctx, app.GetDb());
|
base.SetMembers(activity, app.GetDb());
|
||||||
|
|
||||||
_group = group;
|
_group = group;
|
||||||
DontSave = dontSave;
|
DontSave = dontSave;
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Interfaces;
|
using KeePassLib.Interfaces;
|
||||||
@@ -11,11 +12,11 @@ namespace keepass2android
|
|||||||
private readonly List<IStructureItem> _elementsToDelete;
|
private readonly List<IStructureItem> _elementsToDelete;
|
||||||
private readonly bool _canRecycle;
|
private readonly bool _canRecycle;
|
||||||
|
|
||||||
public DeleteMultipleItems(Context ctx, Database db, List<IStructureItem> elementsToDelete, OnFinish finish, IKp2aApp app)
|
public DeleteMultipleItems(Activity activity, Database db, List<IStructureItem> elementsToDelete, OnFinish finish, IKp2aApp app)
|
||||||
: base(finish, app)
|
: base(activity, finish, app)
|
||||||
{
|
{
|
||||||
_elementsToDelete = elementsToDelete;
|
_elementsToDelete = elementsToDelete;
|
||||||
SetMembers(ctx, db);
|
SetMembers(activity, db);
|
||||||
|
|
||||||
//determine once. The property is queried for each delete operation, but might return false
|
//determine once. The property is queried for each delete operation, but might return false
|
||||||
//after one entry/group is deleted (and thus in recycle bin and thus can't be recycled anymore)
|
//after one entry/group is deleted (and thus in recycle bin and thus can't be recycled anymore)
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
|
||||||
@@ -7,8 +8,8 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
public abstract class DeleteRunnable : RunnableOnFinish
|
public abstract class DeleteRunnable : RunnableOnFinish
|
||||||
{
|
{
|
||||||
protected DeleteRunnable(OnFinish finish, IKp2aApp app)
|
protected DeleteRunnable(Activity activity, OnFinish finish, IKp2aApp app)
|
||||||
: base(finish)
|
: base(activity, finish)
|
||||||
{
|
{
|
||||||
App = app;
|
App = app;
|
||||||
}
|
}
|
||||||
@@ -17,11 +18,11 @@ namespace keepass2android
|
|||||||
|
|
||||||
protected Database Db;
|
protected Database Db;
|
||||||
|
|
||||||
protected Context Ctx;
|
protected Activity Ctx;
|
||||||
|
|
||||||
protected void SetMembers(Context ctx, Database db)
|
protected void SetMembers(Activity activity, Database db)
|
||||||
{
|
{
|
||||||
Ctx = ctx;
|
Ctx = activity;
|
||||||
Db = db;
|
Db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +210,7 @@ namespace keepass2android
|
|||||||
Android.Util.Log.Debug("KP2A", "Calling PerformDelete..");
|
Android.Util.Log.Debug("KP2A", "Calling PerformDelete..");
|
||||||
PerformDelete(touchedGroups, permanentlyDeletedGroups);
|
PerformDelete(touchedGroups, permanentlyDeletedGroups);
|
||||||
|
|
||||||
_onFinishToRun = new ActionOnFinish((success, message) =>
|
_onFinishToRun = new ActionOnFinish(ActiveActivity,(success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
|
@@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
|
||||||
@@ -32,10 +33,10 @@ namespace keepass2android
|
|||||||
private readonly PwIcon _iconId;
|
private readonly PwIcon _iconId;
|
||||||
private readonly PwUuid _customIconId;
|
private readonly PwUuid _customIconId;
|
||||||
internal PwGroup Group;
|
internal PwGroup Group;
|
||||||
readonly Context _ctx;
|
readonly Activity _ctx;
|
||||||
|
|
||||||
public EditGroup(Context ctx, IKp2aApp app, String name, PwIcon iconid, PwUuid customIconId, PwGroup group, OnFinish finish)
|
public EditGroup(Activity ctx, IKp2aApp app, String name, PwIcon iconid, PwUuid customIconId, PwGroup group, OnFinish finish)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_name = name;
|
_name = name;
|
||||||
@@ -44,7 +45,7 @@ namespace keepass2android
|
|||||||
_customIconId = customIconId;
|
_customIconId = customIconId;
|
||||||
_app = app;
|
_app = app;
|
||||||
|
|
||||||
_onFinishToRun = new AfterEdit(this, OnFinishToRun);
|
_onFinishToRun = new AfterEdit(ctx, this, OnFinishToRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -64,8 +65,8 @@ namespace keepass2android
|
|||||||
private class AfterEdit : OnFinish {
|
private class AfterEdit : OnFinish {
|
||||||
readonly EditGroup _editGroup;
|
readonly EditGroup _editGroup;
|
||||||
|
|
||||||
public AfterEdit(EditGroup editGroup, OnFinish finish)
|
public AfterEdit(Activity ctx, EditGroup editGroup, OnFinish finish)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_editGroup = editGroup;
|
_editGroup = editGroup;
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
|
|
||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,7 @@ namespace keepass2android
|
|||||||
public abstract class FileOnFinish : OnFinish {
|
public abstract class FileOnFinish : OnFinish {
|
||||||
private String _filename = "";
|
private String _filename = "";
|
||||||
|
|
||||||
protected FileOnFinish(FileOnFinish finish):base(finish) {
|
protected FileOnFinish(Activity activity, FileOnFinish finish):base(activity, finish) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Filename
|
public string Filename
|
||||||
|
@@ -20,6 +20,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Android.App;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Keys;
|
using KeePassLib.Keys;
|
||||||
using KeePassLib.Serialization;
|
using KeePassLib.Serialization;
|
||||||
@@ -35,7 +36,7 @@ namespace keepass2android
|
|||||||
private readonly bool _rememberKeyfile;
|
private readonly bool _rememberKeyfile;
|
||||||
IDatabaseFormat _format;
|
IDatabaseFormat _format;
|
||||||
|
|
||||||
public LoadDb(IKp2aApp app, IOConnectionInfo ioc, Task<MemoryStream> databaseData, CompositeKey compositeKey, String keyfileOrProvider, OnFinish finish): base(finish)
|
public LoadDb(Activity activity, IKp2aApp app, IOConnectionInfo ioc, Task<MemoryStream> databaseData, CompositeKey compositeKey, String keyfileOrProvider, OnFinish finish): base(activity, finish)
|
||||||
{
|
{
|
||||||
_app = app;
|
_app = app;
|
||||||
_ioc = ioc;
|
_ioc = ioc;
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Interfaces;
|
using KeePassLib.Interfaces;
|
||||||
@@ -12,10 +13,10 @@ namespace keepass2android.database.edit
|
|||||||
{
|
{
|
||||||
private readonly List<IStructureItem> _elementsToMove;
|
private readonly List<IStructureItem> _elementsToMove;
|
||||||
private readonly PwGroup _targetGroup;
|
private readonly PwGroup _targetGroup;
|
||||||
private readonly Context _ctx;
|
private readonly Activity _ctx;
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
|
|
||||||
public MoveElements(List<IStructureItem> elementsToMove, PwGroup targetGroup, Context ctx, IKp2aApp app, OnFinish finish) : base(finish)
|
public MoveElements(List<IStructureItem> elementsToMove, PwGroup targetGroup, Activity ctx, IKp2aApp app, OnFinish finish) : base(ctx, finish)
|
||||||
{
|
{
|
||||||
_elementsToMove = elementsToMove;
|
_elementsToMove = elementsToMove;
|
||||||
_targetGroup = targetGroup;
|
_targetGroup = targetGroup;
|
||||||
@@ -82,7 +83,7 @@ namespace keepass2android.database.edit
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_onFinishToRun = new ActionOnFinish((success, message) =>
|
_onFinishToRun = new ActionOnFinish(ActiveActivity, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{ // Let's not bother recovering from a failure.
|
{ // Let's not bother recovering from a failure.
|
||||||
|
@@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
@@ -31,27 +32,47 @@ namespace keepass2android
|
|||||||
protected OnFinish BaseOnFinish;
|
protected OnFinish BaseOnFinish;
|
||||||
protected Handler Handler;
|
protected Handler Handler;
|
||||||
private ProgressDialogStatusLogger _statusLogger = new ProgressDialogStatusLogger(); //default: no logging but not null -> can be used whenever desired
|
private ProgressDialogStatusLogger _statusLogger = new ProgressDialogStatusLogger(); //default: no logging but not null -> can be used whenever desired
|
||||||
|
private Activity _activeActivity;
|
||||||
|
|
||||||
public ProgressDialogStatusLogger StatusLogger
|
|
||||||
|
public ProgressDialogStatusLogger StatusLogger
|
||||||
{
|
{
|
||||||
get { return _statusLogger; }
|
get { return _statusLogger; }
|
||||||
set { _statusLogger = value; }
|
set { _statusLogger = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Activity ActiveActivity
|
||||||
|
{
|
||||||
|
get { return _activeActivity; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_activeActivity = value;
|
||||||
|
if (BaseOnFinish != null)
|
||||||
|
{
|
||||||
|
BaseOnFinish.ActiveActivity = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected OnFinish(Handler handler) {
|
|
||||||
|
protected OnFinish(Activity activeActivity, Handler handler)
|
||||||
|
{
|
||||||
|
ActiveActivity = activeActivity;
|
||||||
BaseOnFinish = null;
|
BaseOnFinish = null;
|
||||||
Handler = handler;
|
Handler = handler;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OnFinish(OnFinish finish, Handler handler) {
|
protected OnFinish(Activity activeActivity, OnFinish finish, Handler handler)
|
||||||
|
{
|
||||||
|
ActiveActivity = activeActivity;
|
||||||
BaseOnFinish = finish;
|
BaseOnFinish = finish;
|
||||||
Handler = handler;
|
Handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OnFinish(OnFinish finish) {
|
protected OnFinish(Activity activeActivity, OnFinish finish)
|
||||||
|
{
|
||||||
|
ActiveActivity = activeActivity;
|
||||||
BaseOnFinish = finish;
|
BaseOnFinish = finish;
|
||||||
Handler = null;
|
Handler = null;
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,8 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
|
using Android.Content;
|
||||||
|
|
||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
{
|
{
|
||||||
@@ -23,8 +25,11 @@ namespace keepass2android
|
|||||||
|
|
||||||
protected OnFinish _onFinishToRun;
|
protected OnFinish _onFinishToRun;
|
||||||
public ProgressDialogStatusLogger StatusLogger = new ProgressDialogStatusLogger(); //default: empty but not null
|
public ProgressDialogStatusLogger StatusLogger = new ProgressDialogStatusLogger(); //default: empty but not null
|
||||||
|
private Activity _activeActivity;
|
||||||
|
|
||||||
protected RunnableOnFinish(OnFinish finish) {
|
protected RunnableOnFinish(Activity activeActivity, OnFinish finish)
|
||||||
|
{
|
||||||
|
_activeActivity = activeActivity;
|
||||||
_onFinishToRun = finish;
|
_onFinishToRun = finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +39,18 @@ namespace keepass2android
|
|||||||
set { _onFinishToRun = value; }
|
set { _onFinishToRun = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Finish(bool result, String message, Exception exception = null) {
|
public Activity ActiveActivity
|
||||||
|
{
|
||||||
|
get { return _activeActivity; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_activeActivity = value;
|
||||||
|
if (_onFinishToRun != null)
|
||||||
|
_onFinishToRun.ActiveActivity = _activeActivity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void Finish(bool result, String message, Exception exception = null) {
|
||||||
if ( OnFinishToRun != null ) {
|
if ( OnFinishToRun != null ) {
|
||||||
OnFinishToRun.SetResult(result, message, exception);
|
OnFinishToRun.SetResult(result, message, exception);
|
||||||
OnFinishToRun.Run();
|
OnFinishToRun.Run();
|
||||||
@@ -56,7 +72,7 @@ namespace keepass2android
|
|||||||
StatusLogger = status;
|
StatusLogger = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public void Run();
|
public abstract void Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Java.Lang;
|
using Java.Lang;
|
||||||
@@ -42,8 +43,8 @@ namespace keepass2android
|
|||||||
private readonly Context _ctx;
|
private readonly Context _ctx;
|
||||||
private Thread _workerThread;
|
private Thread _workerThread;
|
||||||
|
|
||||||
public SaveDb(Context ctx, IKp2aApp app, OnFinish finish, bool dontSave)
|
public SaveDb(Activity ctx, IKp2aApp app, OnFinish finish, bool dontSave)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_app = app;
|
_app = app;
|
||||||
@@ -58,8 +59,8 @@ namespace keepass2android
|
|||||||
/// <param name="finish"></param>
|
/// <param name="finish"></param>
|
||||||
/// <param name="dontSave"></param>
|
/// <param name="dontSave"></param>
|
||||||
/// <param name="streamForOrigFile">Stream for reading the data from the (changed) original location</param>
|
/// <param name="streamForOrigFile">Stream for reading the data from the (changed) original location</param>
|
||||||
public SaveDb(Context ctx, IKp2aApp app, OnFinish finish, bool dontSave, Stream streamForOrigFile)
|
public SaveDb(Activity ctx, IKp2aApp app, OnFinish finish, bool dontSave, Stream streamForOrigFile)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_app = app;
|
_app = app;
|
||||||
@@ -67,8 +68,8 @@ namespace keepass2android
|
|||||||
_streamForOrigFile = streamForOrigFile;
|
_streamForOrigFile = streamForOrigFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaveDb(Context ctx, IKp2aApp app, OnFinish finish)
|
public SaveDb(Activity ctx, IKp2aApp app, OnFinish finish)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_app = app;
|
_app = app;
|
||||||
@@ -248,7 +249,7 @@ namespace keepass2android
|
|||||||
private void PerformSaveWithoutCheck(IFileStorage fileStorage, IOConnectionInfo ioc)
|
private void PerformSaveWithoutCheck(IFileStorage fileStorage, IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
StatusLogger.UpdateSubMessage("");
|
StatusLogger.UpdateSubMessage("");
|
||||||
_app.GetDb().SaveData(_ctx);
|
_app.GetDb().SaveData();
|
||||||
_app.GetDb().LastFileVersion = fileStorage.GetCurrentFileVersionFast(ioc);
|
_app.GetDb().LastFileVersion = fileStorage.GetCurrentFileVersionFast(ioc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Keys;
|
using KeePassLib.Keys;
|
||||||
@@ -27,9 +28,9 @@ namespace keepass2android
|
|||||||
private readonly String _keyfile;
|
private readonly String _keyfile;
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
private readonly bool _dontSave;
|
private readonly bool _dontSave;
|
||||||
private readonly Context _ctx;
|
private readonly Activity _ctx;
|
||||||
|
|
||||||
public SetPassword(Context ctx, IKp2aApp app, String password, String keyfile, OnFinish finish): base(finish) {
|
public SetPassword(Activity ctx, IKp2aApp app, String password, String keyfile, OnFinish finish): base(ctx, finish) {
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_app = app;
|
_app = app;
|
||||||
_password = password;
|
_password = password;
|
||||||
@@ -37,8 +38,8 @@ namespace keepass2android
|
|||||||
_dontSave = false;
|
_dontSave = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SetPassword(Context ctx, IKp2aApp app, String password, String keyfile, OnFinish finish, bool dontSave)
|
public SetPassword(Activity ctx, IKp2aApp app, String password, String keyfile, OnFinish finish, bool dontSave)
|
||||||
: base(finish)
|
: base(ctx, finish)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_app = app;
|
_app = app;
|
||||||
@@ -72,7 +73,7 @@ namespace keepass2android
|
|||||||
pm.MasterKey = newKey;
|
pm.MasterKey = newKey;
|
||||||
|
|
||||||
// Save Database
|
// Save Database
|
||||||
_onFinishToRun = new AfterSave(previousKey, previousMasterKeyChanged, pm, OnFinishToRun);
|
_onFinishToRun = new AfterSave(ActiveActivity, previousKey, previousMasterKeyChanged, pm, OnFinishToRun);
|
||||||
SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, _dontSave);
|
SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, _dontSave);
|
||||||
save.SetStatusLogger(StatusLogger);
|
save.SetStatusLogger(StatusLogger);
|
||||||
save.Run();
|
save.Run();
|
||||||
@@ -83,7 +84,7 @@ namespace keepass2android
|
|||||||
private readonly DateTime _previousKeyChanged;
|
private readonly DateTime _previousKeyChanged;
|
||||||
private readonly PwDatabase _db;
|
private readonly PwDatabase _db;
|
||||||
|
|
||||||
public AfterSave(CompositeKey backup, DateTime previousKeyChanged, PwDatabase db, OnFinish finish): base(finish) {
|
public AfterSave(Activity activity, CompositeKey backup, DateTime previousKeyChanged, PwDatabase db, OnFinish finish): base(activity, finish) {
|
||||||
_previousKeyChanged = previousKeyChanged;
|
_previousKeyChanged = previousKeyChanged;
|
||||||
_backup = backup;
|
_backup = backup;
|
||||||
_db = db;
|
_db = db;
|
||||||
|
@@ -15,6 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
|
||||||
@@ -23,13 +24,13 @@ namespace keepass2android
|
|||||||
|
|
||||||
public class UpdateEntry : RunnableOnFinish {
|
public class UpdateEntry : RunnableOnFinish {
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
private readonly Context _ctx;
|
private readonly Activity _ctx;
|
||||||
|
|
||||||
public UpdateEntry(Context ctx, IKp2aApp app, PwEntry oldE, PwEntry newE, OnFinish finish):base(finish) {
|
public UpdateEntry(Activity ctx, IKp2aApp app, PwEntry oldE, PwEntry newE, OnFinish finish):base(ctx, finish) {
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_app = app;
|
_app = app;
|
||||||
|
|
||||||
_onFinishToRun = new AfterUpdate(oldE, newE, app, finish);
|
_onFinishToRun = new AfterUpdate(ctx, oldE, newE, app, finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ namespace keepass2android
|
|||||||
private readonly PwEntry _updatedEntry;
|
private readonly PwEntry _updatedEntry;
|
||||||
private readonly IKp2aApp _app;
|
private readonly IKp2aApp _app;
|
||||||
|
|
||||||
public AfterUpdate(PwEntry backup, PwEntry updatedEntry, IKp2aApp app, OnFinish finish):base(finish) {
|
public AfterUpdate(Activity activity, PwEntry backup, PwEntry updatedEntry, IKp2aApp app, OnFinish finish):base(activity, finish) {
|
||||||
_backup = backup;
|
_backup = backup;
|
||||||
_updatedEntry = updatedEntry;
|
_updatedEntry = updatedEntry;
|
||||||
_app = app;
|
_app = app;
|
||||||
|
@@ -22,8 +22,12 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
|
|
||||||
public class CancelDialog : Dialog {
|
public class CancelDialog : Dialog {
|
||||||
public CancelDialog(Context context): base(context) {
|
protected readonly Activity _activity;
|
||||||
}
|
|
||||||
|
public CancelDialog(Activity activity): base(activity)
|
||||||
|
{
|
||||||
|
_activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Canceled { get; private set; }
|
public bool Canceled { get; private set; }
|
||||||
|
|
||||||
|
@@ -411,15 +411,15 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var task = new CreateNewFilename(new ActionOnFinish((success, messageOrFilename) =>
|
var task = new CreateNewFilename(this, new ActionOnFinish(this, (success, messageOrFilename, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
Toast.MakeText(this, messageOrFilename, ToastLength.Long).Show();
|
Toast.MakeText(activity, messageOrFilename, ToastLength.Long).Show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ioc = new IOConnectionInfo { Path = ConvertFilenameToIocPath(messageOrFilename) };
|
_ioc = new IOConnectionInfo { Path = ConvertFilenameToIocPath(messageOrFilename) };
|
||||||
UpdateIocView();
|
((CreateDatabaseActivity)activity)?.UpdateIocView();
|
||||||
|
|
||||||
}), filename);
|
}), filename);
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@ namespace keepass2android
|
|||||||
private readonly IOConnectionInfo _ioc;
|
private readonly IOConnectionInfo _ioc;
|
||||||
|
|
||||||
public LaunchGroupActivity(IOConnectionInfo ioc, CreateDatabaseActivity activity)
|
public LaunchGroupActivity(IOConnectionInfo ioc, CreateDatabaseActivity activity)
|
||||||
: base(null)
|
: base(activity, null)
|
||||||
{
|
{
|
||||||
_activity = activity;
|
_activity = activity;
|
||||||
_ioc = ioc;
|
_ioc = ioc;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using KeePassLib.Serialization;
|
using KeePassLib.Serialization;
|
||||||
|
|
||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
@@ -7,8 +8,8 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
private readonly string _filename;
|
private readonly string _filename;
|
||||||
|
|
||||||
public CreateNewFilename(OnFinish finish, string filename)
|
public CreateNewFilename(Activity activity, OnFinish finish, string filename)
|
||||||
: base(finish)
|
: base(activity,finish)
|
||||||
{
|
{
|
||||||
_filename = filename;
|
_filename = filename;
|
||||||
}
|
}
|
||||||
|
@@ -1056,7 +1056,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal void AddUrlToEntry(string url, Action finishAction)
|
internal void AddUrlToEntry(string url, Action<EntryActivity> finishAction)
|
||||||
{
|
{
|
||||||
PwEntry initialEntry = Entry.CloneDeep();
|
PwEntry initialEntry = Entry.CloneDeep();
|
||||||
|
|
||||||
@@ -1084,10 +1084,10 @@ namespace keepass2android
|
|||||||
|
|
||||||
//save the entry:
|
//save the entry:
|
||||||
|
|
||||||
ActionOnFinish closeOrShowError = new ActionOnFinish((success, message) =>
|
ActionOnFinish closeOrShowError = new ActionOnFinish(this, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
OnFinish.DisplayMessage(this, message);
|
OnFinish.DisplayMessage(this, message);
|
||||||
finishAction();
|
finishAction((EntryActivity)activity);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@@ -413,20 +413,20 @@ namespace keepass2android
|
|||||||
|
|
||||||
RunnableOnFinish runnable;
|
RunnableOnFinish runnable;
|
||||||
|
|
||||||
ActionOnFinish closeOrShowError = new ActionOnFinish((success, message) => {
|
ActionOnFinish closeOrShowError = new ActionOnFinish(this, (success, message, activity) => {
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
Finish();
|
activity.Finish();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
OnFinish.DisplayMessage(this, message);
|
OnFinish.DisplayMessage(activity, message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ActionOnFinish afterAddEntry = new ActionOnFinish((success, message) =>
|
ActionOnFinish afterAddEntry = new ActionOnFinish(this, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (success)
|
if (success)
|
||||||
_appTask.AfterAddNewEntry(this, newEntry);
|
_appTask.AfterAddNewEntry((EntryEditActivity)activity, newEntry);
|
||||||
},closeOrShowError);
|
},closeOrShowError);
|
||||||
|
|
||||||
if ( State.IsNew ) {
|
if ( State.IsNew ) {
|
||||||
|
@@ -119,11 +119,11 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var task = new CreateNewFilename(new ActionOnFinish((success, messageOrFilename) =>
|
var task = new CreateNewFilename(this, new ActionOnFinish(this, (success, messageOrFilename, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
Toast.MakeText(this, messageOrFilename, ToastLength.Long).Show();
|
Toast.MakeText(activity, messageOrFilename, ToastLength.Long).Show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ExportTo(new IOConnectionInfo { Path = ConvertFilenameToIocPath(messageOrFilename) });
|
ExportTo(new IOConnectionInfo { Path = ConvertFilenameToIocPath(messageOrFilename) });
|
||||||
@@ -162,15 +162,15 @@ namespace keepass2android
|
|||||||
|
|
||||||
private void ExportTo(IOConnectionInfo ioc)
|
private void ExportTo(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
var exportDb = new ExportDb(App.Kp2a, new ActionOnFinish(delegate(bool success, string message)
|
var exportDb = new ExportDb(this, App.Kp2a, new ActionOnFinish(this, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
Toast.MakeText(this, message, ToastLength.Long).Show();
|
Toast.MakeText(activity, message, ToastLength.Long).Show();
|
||||||
else
|
else
|
||||||
Toast.MakeText(this, GetString(Resource.String.export_database_successful), ToastLength.Long).Show();
|
Toast.MakeText(activity, GetString(Resource.String.export_database_successful), ToastLength.Long).Show();
|
||||||
Finish();
|
activity.Finish();
|
||||||
}
|
}
|
||||||
), _ffp[_fileFormatIndex], ioc);
|
), _ffp[_fileFormatIndex], ioc);
|
||||||
ProgressTask pt = new ProgressTask(App.Kp2a, this, exportDb);
|
ProgressTask pt = new ProgressTask(App.Kp2a, this, exportDb);
|
||||||
pt.Run();
|
pt.Run();
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ namespace keepass2android
|
|||||||
private readonly FileFormatProvider _fileFormat;
|
private readonly FileFormatProvider _fileFormat;
|
||||||
private IOConnectionInfo _targetIoc;
|
private IOConnectionInfo _targetIoc;
|
||||||
|
|
||||||
public ExportDb(IKp2aApp app, OnFinish onFinish, FileFormatProvider fileFormat, IOConnectionInfo targetIoc) : base(onFinish)
|
public ExportDb(Activity activity, IKp2aApp app, OnFinish onFinish, FileFormatProvider fileFormat, IOConnectionInfo targetIoc) : base(activity, onFinish)
|
||||||
{
|
{
|
||||||
_app = app;
|
_app = app;
|
||||||
this._fileFormat = fileFormat;
|
this._fileFormat = fileFormat;
|
||||||
|
@@ -230,11 +230,8 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
//yes
|
//yes
|
||||||
ProgressTask pt = new ProgressTask(App.Kp2a, this,
|
ProgressTask pt = new ProgressTask(App.Kp2a, this,
|
||||||
new AddTemplateEntries(this, App.Kp2a, new ActionOnFinish(
|
new AddTemplateEntries(this, App.Kp2a, new ActionOnFinish(this,
|
||||||
delegate
|
(success, message, activity) => ((GroupActivity)activity)?.StartAddEntry())));
|
||||||
{
|
|
||||||
StartAddEntry();
|
|
||||||
})));
|
|
||||||
pt.Run();
|
pt.Run();
|
||||||
},
|
},
|
||||||
(o, args) =>
|
(o, args) =>
|
||||||
|
@@ -616,7 +616,13 @@ namespace keepass2android
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var moveElement = new MoveElements(elementsToMove.ToList(), Group, this, App.Kp2a, new ActionOnFinish((success, message) => { StopMovingElements(); if (!String.IsNullOrEmpty(message)) Toast.MakeText(this, message, ToastLength.Long).Show(); }));
|
var moveElement = new MoveElements(elementsToMove.ToList(), Group, this, App.Kp2a, new ActionOnFinish(this,
|
||||||
|
(success, message, activity) =>
|
||||||
|
{
|
||||||
|
((GroupBaseActivity)activity)?.StopMovingElements();
|
||||||
|
if (!String.IsNullOrEmpty(message))
|
||||||
|
Toast.MakeText(activity, message, ToastLength.Long).Show();
|
||||||
|
}));
|
||||||
var progressTask = new ProgressTask(App.Kp2a, this, moveElement);
|
var progressTask = new ProgressTask(App.Kp2a, this, moveElement);
|
||||||
progressTask.Run();
|
progressTask.Run();
|
||||||
|
|
||||||
@@ -867,8 +873,8 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
private readonly IOConnectionInfo _ioc;
|
private readonly IOConnectionInfo _ioc;
|
||||||
|
|
||||||
public SyncOtpAuxFile(IOConnectionInfo ioc)
|
public SyncOtpAuxFile(Activity activity, IOConnectionInfo ioc)
|
||||||
: base(null)
|
: base(activity,null)
|
||||||
{
|
{
|
||||||
_ioc = ioc;
|
_ioc = ioc;
|
||||||
}
|
}
|
||||||
@@ -900,19 +906,19 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
var filestorage = App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc);
|
var filestorage = App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc);
|
||||||
RunnableOnFinish task;
|
RunnableOnFinish task;
|
||||||
OnFinish onFinish = new ActionOnFinish((success, message) =>
|
OnFinish onFinish = new ActionOnFinish(this, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(message))
|
if (!String.IsNullOrEmpty(message))
|
||||||
Toast.MakeText(this, message, ToastLength.Long).Show();
|
Toast.MakeText(activity, message, ToastLength.Long).Show();
|
||||||
|
|
||||||
// Tell the adapter to refresh it's list
|
// Tell the adapter to refresh it's list
|
||||||
BaseAdapter adapter = (BaseAdapter)ListAdapter;
|
BaseAdapter adapter = (BaseAdapter)((GroupBaseActivity)activity)?.ListAdapter;
|
||||||
adapter.NotifyDataSetChanged();
|
adapter?.NotifyDataSetChanged();
|
||||||
|
|
||||||
if (App.Kp2a.GetDb().OtpAuxFileIoc != null)
|
if (App.Kp2a.GetDb().OtpAuxFileIoc != null)
|
||||||
{
|
{
|
||||||
var task2 = new SyncOtpAuxFile(App.Kp2a.GetDb().OtpAuxFileIoc);
|
var task2 = new SyncOtpAuxFile(this, App.Kp2a.GetDb().OtpAuxFileIoc);
|
||||||
new ProgressTask(App.Kp2a, this, task2).Run();
|
new ProgressTask(App.Kp2a, activity, task2).Run(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -982,33 +988,28 @@ namespace keepass2android
|
|||||||
|
|
||||||
public class RefreshTask : OnFinish
|
public class RefreshTask : OnFinish
|
||||||
{
|
{
|
||||||
readonly GroupBaseActivity _act;
|
|
||||||
public RefreshTask(Handler handler, GroupBaseActivity act)
|
public RefreshTask(Handler handler, GroupBaseActivity act)
|
||||||
: base(handler)
|
: base(act, handler)
|
||||||
{
|
{
|
||||||
_act = act;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Run()
|
public override void Run()
|
||||||
{
|
{
|
||||||
if (Success)
|
if (Success)
|
||||||
{
|
{
|
||||||
_act.RefreshIfDirty();
|
((GroupBaseActivity)ActiveActivity)?.RefreshIfDirty();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisplayMessage(_act);
|
DisplayMessage(ActiveActivity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class AfterDeleteGroup : OnFinish
|
public class AfterDeleteGroup : OnFinish
|
||||||
{
|
{
|
||||||
readonly GroupBaseActivity _act;
|
|
||||||
|
|
||||||
public AfterDeleteGroup(Handler handler, GroupBaseActivity act)
|
public AfterDeleteGroup(Handler handler, GroupBaseActivity act)
|
||||||
: base(handler)
|
: base(act, handler)
|
||||||
{
|
{
|
||||||
_act = act;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1016,13 +1017,13 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
if (Success)
|
if (Success)
|
||||||
{
|
{
|
||||||
_act.RefreshIfDirty();
|
((GroupBaseActivity)ActiveActivity)?.RefreshIfDirty();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Handler.Post(() =>
|
Handler.Post(() =>
|
||||||
{
|
{
|
||||||
Toast.MakeText(_act, "Unrecoverable error: " + Message, ToastLength.Long).Show();
|
Toast.MakeText(ActiveActivity, "Unrecoverable error: " + Message, ToastLength.Long).Show();
|
||||||
});
|
});
|
||||||
|
|
||||||
App.Kp2a.LockDatabase(false);
|
App.Kp2a.LockDatabase(false);
|
||||||
|
@@ -27,7 +27,7 @@ using KeePassLib.Utility;
|
|||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
{
|
{
|
||||||
[Activity(Label = "@string/app_name", Theme = "@style/Dialog")]
|
[Activity(Label = "@string/app_name", Theme = "@style/Dialog")]
|
||||||
public class GroupEditActivity : LifecycleDebugActivity
|
public class GroupEditActivity : LifecycleAwareActivity
|
||||||
{
|
{
|
||||||
public const String KeyParent = "parent";
|
public const String KeyParent = "parent";
|
||||||
public const String KeyName = "name";
|
public const String KeyName = "name";
|
||||||
|
@@ -74,7 +74,7 @@ namespace keepass2android
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Activity(Label = AppNames.AppName, MainLauncher = false, Theme = "@style/MyTheme_Blue")]
|
[Activity(Label = AppNames.AppName, MainLauncher = false, Theme = "@style/MyTheme_Blue")]
|
||||||
[IntentFilter(new[] { Intent.ActionMain }, Categories = new[] { "android.intent.category.LAUNCHER", "android.intent.category.MULTIWINDOW_LAUNCHER" })]
|
[IntentFilter(new[] { Intent.ActionMain }, Categories = new[] { "android.intent.category.LAUNCHER", "android.intent.category.MULTIWINDOW_LAUNCHER" })]
|
||||||
public class KeePass : LifecycleDebugActivity, IDialogInterfaceOnDismissListener
|
public class KeePass : LifecycleAwareActivity, IDialogInterfaceOnDismissListener
|
||||||
{
|
{
|
||||||
public const Result ExitNormal = Result.FirstUser;
|
public const Result ExitNormal = Result.FirstUser;
|
||||||
public const Result ExitLock = Result.FirstUser+1;
|
public const Result ExitLock = Result.FirstUser+1;
|
||||||
|
@@ -24,15 +24,15 @@ using Android.Support.V7.App;
|
|||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
{
|
{
|
||||||
|
|
||||||
public abstract class LifecycleDebugActivity : AppCompatActivity
|
public abstract class LifecycleAwareActivity : AppCompatActivity
|
||||||
{
|
{
|
||||||
protected LifecycleDebugActivity (IntPtr javaReference, JniHandleOwnership transfer)
|
protected LifecycleAwareActivity (IntPtr javaReference, JniHandleOwnership transfer)
|
||||||
: base(javaReference, transfer)
|
: base(javaReference, transfer)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LifecycleDebugActivity()
|
protected LifecycleAwareActivity()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +63,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
protected override void OnStart()
|
protected override void OnStart()
|
||||||
{
|
{
|
||||||
|
ProgressTask.SetNewActiveActivity(this);
|
||||||
base.OnStart();
|
base.OnStart();
|
||||||
Kp2aLog.Log(ClassName+".OnStart");
|
Kp2aLog.Log(ClassName+".OnStart");
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,8 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
base.OnStop();
|
base.OnStop();
|
||||||
Kp2aLog.Log(ClassName+".OnStop");
|
Kp2aLog.Log(ClassName+".OnStop");
|
||||||
}
|
ProgressTask.RemoveActiveActivity(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -27,7 +27,7 @@ namespace keepass2android
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for activities. Notifies the TimeoutHelper whether the app is active or not.
|
/// Base class for activities. Notifies the TimeoutHelper whether the app is active or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LockingActivity : LifecycleDebugActivity {
|
public class LockingActivity : LifecycleAwareActivity {
|
||||||
|
|
||||||
public LockingActivity (IntPtr javaReference, JniHandleOwnership transfer)
|
public LockingActivity (IntPtr javaReference, JniHandleOwnership transfer)
|
||||||
: base(javaReference, transfer)
|
: base(javaReference, transfer)
|
||||||
|
@@ -310,7 +310,7 @@ namespace keepass2android
|
|||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
OnFinish onFinish = new AfterLoad(handler, this, _ioConnection);
|
OnFinish onFinish = new AfterLoad(handler, this, _ioConnection);
|
||||||
_performingLoad = true;
|
_performingLoad = true;
|
||||||
LoadDb task = new LoadDb(App.Kp2a, _ioConnection, _loadDbFileTask, compositeKey, _keyFileOrProvider, onFinish);
|
LoadDb task = new LoadDb(this, App.Kp2a, _ioConnection, _loadDbFileTask, compositeKey, _keyFileOrProvider, onFinish);
|
||||||
_loadDbFileTask = null; // prevent accidental re-use
|
_loadDbFileTask = null; // prevent accidental re-use
|
||||||
new ProgressTask(App.Kp2a, this, task).Run();
|
new ProgressTask(App.Kp2a, this, task).Run();
|
||||||
}
|
}
|
||||||
@@ -1453,7 +1453,7 @@ namespace keepass2android
|
|||||||
LoadDb task = (KeyProviderType == KeyProviders.Otp)
|
LoadDb task = (KeyProviderType == KeyProviders.Otp)
|
||||||
? new SaveOtpAuxFileAndLoadDb(App.Kp2a, _ioConnection, _loadDbFileTask, compositeKey, _keyFileOrProvider,
|
? new SaveOtpAuxFileAndLoadDb(App.Kp2a, _ioConnection, _loadDbFileTask, compositeKey, _keyFileOrProvider,
|
||||||
onFinish, this)
|
onFinish, this)
|
||||||
: new LoadDb(App.Kp2a, _ioConnection, _loadDbFileTask, compositeKey, _keyFileOrProvider, onFinish);
|
: new LoadDb(this, App.Kp2a, _ioConnection, _loadDbFileTask, compositeKey, _keyFileOrProvider, onFinish);
|
||||||
_loadDbFileTask = null; // prevent accidental re-use
|
_loadDbFileTask = null; // prevent accidental re-use
|
||||||
|
|
||||||
SetNewDefaultFile();
|
SetNewDefaultFile();
|
||||||
@@ -2028,7 +2028,7 @@ namespace keepass2android
|
|||||||
readonly PasswordActivity _act;
|
readonly PasswordActivity _act;
|
||||||
private readonly IOConnectionInfo _ioConnection;
|
private readonly IOConnectionInfo _ioConnection;
|
||||||
|
|
||||||
public AfterLoad(Handler handler, PasswordActivity act, IOConnectionInfo ioConnection):base(handler)
|
public AfterLoad(Handler handler, PasswordActivity act, IOConnectionInfo ioConnection):base(act, handler)
|
||||||
{
|
{
|
||||||
_act = act;
|
_act = act;
|
||||||
_ioConnection = ioConnection;
|
_ioConnection = ioConnection;
|
||||||
@@ -2172,7 +2172,7 @@ namespace keepass2android
|
|||||||
private readonly PasswordActivity _act;
|
private readonly PasswordActivity _act;
|
||||||
|
|
||||||
|
|
||||||
public SaveOtpAuxFileAndLoadDb(IKp2aApp app, IOConnectionInfo ioc, Task<MemoryStream> databaseData, CompositeKey compositeKey, string keyfileOrProvider, OnFinish finish, PasswordActivity act) : base(app, ioc, databaseData, compositeKey, keyfileOrProvider, finish)
|
public SaveOtpAuxFileAndLoadDb(IKp2aApp app, IOConnectionInfo ioc, Task<MemoryStream> databaseData, CompositeKey compositeKey, string keyfileOrProvider, OnFinish finish, PasswordActivity act) : base(act, app, ioc, databaseData, compositeKey, keyfileOrProvider, finish)
|
||||||
{
|
{
|
||||||
_act = act;
|
_act = act;
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ namespace keepass2android
|
|||||||
WindowSoftInputMode = SoftInput.AdjustResize,
|
WindowSoftInputMode = SoftInput.AdjustResize,
|
||||||
MainLauncher = false,
|
MainLauncher = false,
|
||||||
Theme = "@style/MyTheme_Blue")]
|
Theme = "@style/MyTheme_Blue")]
|
||||||
public class QuickUnlock : LifecycleDebugActivity, IFingerprintAuthCallback
|
public class QuickUnlock : LifecycleAwareActivity, IFingerprintAuthCallback
|
||||||
{
|
{
|
||||||
private IOConnectionInfo _ioc;
|
private IOConnectionInfo _ioc;
|
||||||
private QuickUnlockBroadcastReceiver _intentReceiver;
|
private QuickUnlockBroadcastReceiver _intentReceiver;
|
||||||
|
@@ -15,6 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Android.Preferences;
|
using Android.Preferences;
|
||||||
@@ -25,10 +26,13 @@ namespace keepass2android
|
|||||||
|
|
||||||
public class SetPasswordDialog : CancelDialog
|
public class SetPasswordDialog : CancelDialog
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
internal String Keyfile;
|
||||||
|
|
||||||
internal String Keyfile;
|
public SetPasswordDialog(Activity activity):base(activity)
|
||||||
|
{
|
||||||
public SetPasswordDialog(Context context):base(context) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,8 +71,8 @@ namespace keepass2android
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPassword sp = new SetPassword(Context, App.Kp2a, pass, keyfile, new AfterSave(this, null, new Handler()));
|
SetPassword sp = new SetPassword(_activity, App.Kp2a, pass, keyfile, new AfterSave(_activity, this, null, new Handler()));
|
||||||
ProgressTask pt = new ProgressTask(App.Kp2a, Context, sp);
|
ProgressTask pt = new ProgressTask(App.Kp2a, _activity, sp);
|
||||||
pt.Run();
|
pt.Run();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,7 +92,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
readonly SetPasswordDialog _dlg;
|
readonly SetPasswordDialog _dlg;
|
||||||
|
|
||||||
public AfterSave(SetPasswordDialog dlg, FileOnFinish finish, Handler handler): base(finish, handler) {
|
public AfterSave(Activity activity, SetPasswordDialog dlg, FileOnFinish finish, Handler handler): base(activity, finish, handler) {
|
||||||
_finish = finish;
|
_finish = finish;
|
||||||
_dlg = dlg;
|
_dlg = dlg;
|
||||||
}
|
}
|
||||||
|
@@ -489,6 +489,10 @@ namespace keepass2android
|
|||||||
|
|
||||||
public override void CompleteOnCreateEntryActivity(EntryActivity activity)
|
public override void CompleteOnCreateEntryActivity(EntryActivity activity)
|
||||||
{
|
{
|
||||||
|
Context ctx = activity;
|
||||||
|
if (ctx == null)
|
||||||
|
ctx = Application.Context;
|
||||||
|
|
||||||
if (ShowUserNotifications)
|
if (ShowUserNotifications)
|
||||||
{
|
{
|
||||||
//show the notifications
|
//show the notifications
|
||||||
@@ -579,7 +583,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
builder.SetPositiveButton(activity.GetString(Resource.String.yes), (dlgSender, dlgEvt) =>
|
builder.SetPositiveButton(activity.GetString(Resource.String.yes), (dlgSender, dlgEvt) =>
|
||||||
{
|
{
|
||||||
activity.AddUrlToEntry(url, () => base.CompleteOnCreateEntryActivity(activity));
|
activity.AddUrlToEntry(url, (EntryActivity thenActiveActivity) => base.CompleteOnCreateEntryActivity(thenActiveActivity));
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.SetNegativeButton(activity.GetString(Resource.String.no), (dlgSender, dlgEvt) =>
|
builder.SetNegativeButton(activity.GetString(Resource.String.no), (dlgSender, dlgEvt) =>
|
||||||
|
@@ -303,7 +303,7 @@
|
|||||||
<Compile Include="services\CopyToClipboardService.cs" />
|
<Compile Include="services\CopyToClipboardService.cs" />
|
||||||
<Compile Include="search\SearchActivity.cs" />
|
<Compile Include="search\SearchActivity.cs" />
|
||||||
<Compile Include="QuickUnlock.cs" />
|
<Compile Include="QuickUnlock.cs" />
|
||||||
<Compile Include="LifecycleDebugActivity.cs" />
|
<Compile Include="LifecycleAwareActivity.cs" />
|
||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
<Compile Include="EntryEditActivityState.cs" />
|
<Compile Include="EntryEditActivityState.cs" />
|
||||||
<Compile Include="AttachmentContentProvider.cs" />
|
<Compile Include="AttachmentContentProvider.cs" />
|
||||||
|
@@ -561,12 +561,12 @@ namespace keepass2android
|
|||||||
var previousCipher = db.KpDatabase.DataCipherUuid;
|
var previousCipher = db.KpDatabase.DataCipherUuid;
|
||||||
db.KpDatabase.DataCipherUuid = new PwUuid(MemUtil.HexStringToByteArray((string)preferenceChangeEventArgs.NewValue));
|
db.KpDatabase.DataCipherUuid = new PwUuid(MemUtil.HexStringToByteArray((string)preferenceChangeEventArgs.NewValue));
|
||||||
|
|
||||||
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish((success, message) =>
|
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish(Activity, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
db.KpDatabase.DataCipherUuid = previousCipher;
|
db.KpDatabase.DataCipherUuid = previousCipher;
|
||||||
Toast.MakeText(Activity, message, ToastLength.Long).Show();
|
Toast.MakeText(activity, message, ToastLength.Long).Show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
preferenceChangeEventArgs.Preference.Summary =
|
preferenceChangeEventArgs.Preference.Summary =
|
||||||
@@ -626,12 +626,12 @@ namespace keepass2android
|
|||||||
|
|
||||||
Kp2aLog.Log("--new kdf: " + KdfPool.Get(db.KpDatabase.KdfParameters.KdfUuid) + " " + db.KpDatabase.KdfParameters.KdfUuid.ToHexString());
|
Kp2aLog.Log("--new kdf: " + KdfPool.Get(db.KpDatabase.KdfParameters.KdfUuid) + " " + db.KpDatabase.KdfParameters.KdfUuid.ToHexString());
|
||||||
|
|
||||||
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish((success, message) =>
|
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish(Activity, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
db.KpDatabase.KdfParameters = previousKdfParams;
|
db.KpDatabase.KdfParameters = previousKdfParams;
|
||||||
Toast.MakeText(Activity, message, ToastLength.Long).Show();
|
Toast.MakeText(activity, message, ToastLength.Long).Show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UpdateKdfScreen();
|
UpdateKdfScreen();
|
||||||
@@ -670,7 +670,7 @@ namespace keepass2android
|
|||||||
pref.PreferenceClick += (sender, args) =>
|
pref.PreferenceClick += (sender, args) =>
|
||||||
{
|
{
|
||||||
ProgressTask pt = new ProgressTask(App.Kp2a, Activity,
|
ProgressTask pt = new ProgressTask(App.Kp2a, Activity,
|
||||||
new AddTemplateEntries(Activity, App.Kp2a, new ActionOnFinish(
|
new AddTemplateEntries(Activity, App.Kp2a, new ActionOnFinish(Activity,
|
||||||
delegate
|
delegate
|
||||||
{
|
{
|
||||||
pref.Enabled = false;
|
pref.Enabled = false;
|
||||||
@@ -709,13 +709,13 @@ namespace keepass2android
|
|||||||
String previousName = db.KpDatabase.Name;
|
String previousName = db.KpDatabase.Name;
|
||||||
db.KpDatabase.Name = e.NewValue.ToString();
|
db.KpDatabase.Name = e.NewValue.ToString();
|
||||||
|
|
||||||
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish((success, message) =>
|
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish(Activity, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
db.KpDatabase.Name = previousName;
|
db.KpDatabase.Name = previousName;
|
||||||
db.KpDatabase.NameChanged = previousNameChanged;
|
db.KpDatabase.NameChanged = previousNameChanged;
|
||||||
Toast.MakeText(Activity, message, ToastLength.Long).Show();
|
Toast.MakeText(activity, message, ToastLength.Long).Show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -747,13 +747,13 @@ namespace keepass2android
|
|||||||
String previousUsername = db.KpDatabase.DefaultUserName;
|
String previousUsername = db.KpDatabase.DefaultUserName;
|
||||||
db.KpDatabase.DefaultUserName = e.NewValue.ToString();
|
db.KpDatabase.DefaultUserName = e.NewValue.ToString();
|
||||||
|
|
||||||
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish((success, message) =>
|
SaveDb save = new SaveDb(Activity, App.Kp2a, new ActionOnFinish(Activity, (success, message, activity) =>
|
||||||
{
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
db.KpDatabase.DefaultUserName = previousUsername;
|
db.KpDatabase.DefaultUserName = previousUsername;
|
||||||
db.KpDatabase.DefaultUserNameChanged = previousUsernameChanged;
|
db.KpDatabase.DefaultUserNameChanged = previousUsernameChanged;
|
||||||
Toast.MakeText(Activity, message, ToastLength.Long).Show();
|
Toast.MakeText(activity, message, ToastLength.Long).Show();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save);
|
ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save);
|
||||||
|
@@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
@@ -88,8 +89,8 @@ namespace keepass2android.settings
|
|||||||
ParamValue = paramValue;
|
ParamValue = paramValue;
|
||||||
|
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
SaveDb save = new SaveDb(Context, App.Kp2a, new KdfNumberParamPreference.AfterSave(Context, handler, oldValue, this));
|
SaveDb save = new SaveDb((Activity)Context, App.Kp2a, new KdfNumberParamPreference.AfterSave((Activity)Context, handler, oldValue, this));
|
||||||
ProgressTask pt = new ProgressTask(App.Kp2a, Context, save);
|
ProgressTask pt = new ProgressTask(App.Kp2a, (Activity)Context, save);
|
||||||
pt.Run();
|
pt.Run();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,7 +102,7 @@ namespace keepass2android.settings
|
|||||||
private readonly Context _ctx;
|
private readonly Context _ctx;
|
||||||
private readonly KdfNumberParamPreference _pref;
|
private readonly KdfNumberParamPreference _pref;
|
||||||
|
|
||||||
public AfterSave(Context ctx, Handler handler, ulong oldRounds, KdfNumberParamPreference pref):base(handler) {
|
public AfterSave(Activity ctx, Handler handler, ulong oldRounds, KdfNumberParamPreference pref):base(ctx, handler) {
|
||||||
|
|
||||||
_pref = pref;
|
_pref = pref;
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
|
Reference in New Issue
Block a user