2013-02-23 11:43:42 -05:00
|
|
|
/*
|
|
|
|
This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file is based on Keepassdroid, Copyright Brian Pellin.
|
|
|
|
|
|
|
|
Keepass2Android is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Keepass2Android is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using Android.Content;
|
|
|
|
using Android.OS;
|
|
|
|
using Android.Widget;
|
|
|
|
|
|
|
|
namespace keepass2android
|
|
|
|
{
|
|
|
|
public abstract class OnFinish
|
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
protected bool Success;
|
|
|
|
protected String Message;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
protected OnFinish BaseOnFinish;
|
|
|
|
protected Handler Handler;
|
2013-07-09 03:59:17 -04:00
|
|
|
private ProgressDialogStatusLogger _statusLogger = new ProgressDialogStatusLogger(); //default: no logging but not null -> can be used whenever desired
|
|
|
|
|
|
|
|
public ProgressDialogStatusLogger StatusLogger
|
|
|
|
{
|
|
|
|
get { return _statusLogger; }
|
|
|
|
set { _statusLogger = value; }
|
|
|
|
}
|
2013-06-15 06:40:01 -04:00
|
|
|
|
|
|
|
protected OnFinish() {
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2013-06-15 06:40:01 -04:00
|
|
|
|
|
|
|
protected OnFinish(Handler handler) {
|
|
|
|
BaseOnFinish = null;
|
|
|
|
Handler = handler;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2013-06-15 06:40:01 -04:00
|
|
|
|
|
|
|
protected OnFinish(OnFinish finish, Handler handler) {
|
|
|
|
BaseOnFinish = finish;
|
|
|
|
Handler = handler;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2013-06-15 06:40:01 -04:00
|
|
|
|
|
|
|
protected OnFinish(OnFinish finish) {
|
|
|
|
BaseOnFinish = finish;
|
|
|
|
Handler = null;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2013-07-09 03:59:17 -04:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public void SetResult(bool success, String message) {
|
|
|
|
Success = success;
|
|
|
|
Message = message;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public void SetResult(bool success) {
|
|
|
|
Success = success;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public virtual void Run() {
|
2013-06-25 15:27:41 -04:00
|
|
|
if (BaseOnFinish == null) return;
|
|
|
|
// Pass on result on call finish
|
|
|
|
BaseOnFinish.SetResult(Success, Message);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-25 15:27:41 -04:00
|
|
|
if ( Handler != null ) {
|
|
|
|
Handler.Post(BaseOnFinish.Run);
|
|
|
|
} else {
|
|
|
|
BaseOnFinish.Run();
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
protected void DisplayMessage(Context ctx) {
|
|
|
|
DisplayMessage(ctx, Message);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public static void DisplayMessage(Context ctx, string message)
|
2013-05-30 02:29:08 -04:00
|
|
|
{
|
|
|
|
if ( !String.IsNullOrEmpty(message) ) {
|
2013-07-06 10:12:40 -04:00
|
|
|
Kp2aLog.Log("OnFinish message: "+message);
|
2013-05-30 02:29:08 -04:00
|
|
|
Toast.MakeText(ctx, message, ToastLength.Long).Show();
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|