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