show save errors as dialogs, closes #339
This commit is contained in:
@@ -99,7 +99,7 @@ namespace keepass2android
|
||||
{
|
||||
Kp2aLog.Log("KeyFileException");
|
||||
Finish(false, /*TODO Localize: use Keepass error text KPRes.KeyFileError (including "or invalid format")*/
|
||||
_app.GetResourceString(UiStringKey.keyfile_does_not_exist), Exception);
|
||||
_app.GetResourceString(UiStringKey.keyfile_does_not_exist), false, Exception);
|
||||
}
|
||||
catch (AggregateException e)
|
||||
{
|
||||
@@ -110,20 +110,20 @@ namespace keepass2android
|
||||
// Override the message shown with the last (hopefully most recent) inner exception
|
||||
Kp2aLog.LogUnexpectedError(innerException);
|
||||
}
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + message, Exception);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + message, false, Exception);
|
||||
return;
|
||||
}
|
||||
catch (DuplicateUuidsException e)
|
||||
{
|
||||
Kp2aLog.Log(e.ToString());
|
||||
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), Exception);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), false, Exception);
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!(e is InvalidCompositeKeyException))
|
||||
Kp2aLog.LogUnexpectedError(e);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, Exception);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, false, Exception);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Android;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
@@ -28,8 +29,14 @@ namespace keepass2android
|
||||
protected bool Success;
|
||||
protected String Message;
|
||||
protected Exception Exception;
|
||||
|
||||
protected OnFinish BaseOnFinish;
|
||||
|
||||
protected bool ImportantMessage
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
protected OnFinish BaseOnFinish;
|
||||
protected Handler Handler;
|
||||
private ProgressDialogStatusLogger _statusLogger = new ProgressDialogStatusLogger(); //default: no logging but not null -> can be used whenever desired
|
||||
private Activity _activeActivity;
|
||||
@@ -77,20 +84,22 @@ namespace keepass2android
|
||||
Handler = null;
|
||||
}
|
||||
|
||||
public void SetResult(bool success, string message, Exception exception) {
|
||||
public void SetResult(bool success, string message, bool importantMessage, Exception exception) {
|
||||
Success = success;
|
||||
Message = message;
|
||||
ImportantMessage = importantMessage;
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
public void SetResult(bool success) {
|
||||
|
||||
|
||||
public void SetResult(bool success) {
|
||||
Success = success;
|
||||
}
|
||||
|
||||
public virtual void Run() {
|
||||
if (BaseOnFinish == null) return;
|
||||
// Pass on result on call finish
|
||||
BaseOnFinish.SetResult(Success, Message, Exception);
|
||||
BaseOnFinish.SetResult(Success, Message, ImportantMessage, Exception);
|
||||
|
||||
if ( Handler != null ) {
|
||||
Handler.Post(BaseOnFinish.Run);
|
||||
@@ -100,14 +109,31 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
protected void DisplayMessage(Context ctx) {
|
||||
DisplayMessage(ctx, Message);
|
||||
DisplayMessage(ctx, Message, ImportantMessage);
|
||||
}
|
||||
|
||||
public static void DisplayMessage(Context ctx, string message)
|
||||
public static void DisplayMessage(Context ctx, string message, bool makeDialog)
|
||||
{
|
||||
if ( !String.IsNullOrEmpty(message) ) {
|
||||
Kp2aLog.Log("OnFinish message: "+message);
|
||||
Toast.MakeText(ctx ?? Application.Context, message, ToastLength.Long).Show();
|
||||
Kp2aLog.Log("OnFinish message: " + message);
|
||||
if (makeDialog && ctx != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||
|
||||
builder.SetMessage(message)
|
||||
.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => ((Dialog)sender).Dismiss())
|
||||
.Show();
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Toast.MakeText(ctx, message, ToastLength.Long).Show();
|
||||
}
|
||||
}
|
||||
else
|
||||
Toast.MakeText(ctx ?? Application.Context, message, ToastLength.Long).Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ namespace keepass2android
|
||||
}
|
||||
}
|
||||
|
||||
protected void Finish(bool result, String message, Exception exception = null) {
|
||||
protected void Finish(bool result, String message, bool importantMessage = false, Exception exception = null) {
|
||||
if ( OnFinishToRun != null ) {
|
||||
OnFinishToRun.SetResult(result, message, exception);
|
||||
OnFinishToRun.SetResult(result, message, importantMessage, exception);
|
||||
OnFinishToRun.Run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1228,7 +1228,7 @@ namespace keepass2android
|
||||
|
||||
ActionOnFinish closeOrShowError = new ActionOnFinish(this, (success, message, activity) =>
|
||||
{
|
||||
OnFinish.DisplayMessage(this, message);
|
||||
OnFinish.DisplayMessage(this, message, true);
|
||||
finishAction((EntryActivity)activity);
|
||||
});
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ namespace keepass2android
|
||||
activity.Finish();
|
||||
} else
|
||||
{
|
||||
OnFinish.DisplayMessage(activity, message);
|
||||
OnFinish.DisplayMessage(activity, message, true);
|
||||
//Re-initialize for editing:
|
||||
State.EditMode.InitializeEntry(State.Entry);
|
||||
}
|
||||
|
||||
@@ -1512,7 +1512,7 @@ namespace keepass2android
|
||||
}
|
||||
else
|
||||
{
|
||||
onFinish.SetResult(false, message, null);
|
||||
onFinish.SetResult(false, message, true, null);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user