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.App;
|
|
|
|
using Android.OS;
|
|
|
|
using KeePassLib.Interfaces;
|
|
|
|
|
|
|
|
namespace keepass2android
|
|
|
|
{
|
2013-06-15 16:02:48 -04:00
|
|
|
/// <summary>
|
|
|
|
/// StatusLogger implementation which shows the progress in a progress dialog
|
|
|
|
/// </summary>
|
2013-07-09 03:59:17 -04:00
|
|
|
public class ProgressDialogStatusLogger: IStatusLogger {
|
2013-06-25 15:27:41 -04:00
|
|
|
private readonly IProgressDialog _progressDialog;
|
2013-06-15 06:40:01 -04:00
|
|
|
readonly IKp2aApp _app;
|
|
|
|
private readonly Handler _handler;
|
2013-07-09 03:59:17 -04:00
|
|
|
private string _message = "";
|
|
|
|
|
|
|
|
public ProgressDialogStatusLogger() {
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-09 03:59:17 -04:00
|
|
|
public ProgressDialogStatusLogger(IKp2aApp app, Handler handler, IProgressDialog pd) {
|
2013-06-15 06:40:01 -04:00
|
|
|
_app = app;
|
|
|
|
_progressDialog = pd;
|
|
|
|
_handler = handler;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public void UpdateMessage(UiStringKey stringKey) {
|
2013-07-09 03:59:17 -04:00
|
|
|
if (_app != null)
|
|
|
|
UpdateMessage(_app.GetResourceString(stringKey));
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public void UpdateMessage (String message)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-07-09 03:59:17 -04:00
|
|
|
_message = message;
|
2013-06-15 06:40:01 -04:00
|
|
|
if ( _app!= null && _progressDialog != null && _handler != null ) {
|
|
|
|
_handler.Post(() => {_progressDialog.SetMessage(message); } );
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 03:59:17 -04:00
|
|
|
public void UpdateSubMessage(String submessage)
|
|
|
|
{
|
|
|
|
if (_app != null && _progressDialog != null && _handler != null)
|
|
|
|
{
|
|
|
|
_handler.Post(() =>
|
|
|
|
{
|
2013-07-11 11:27:10 -04:00
|
|
|
if (!String.IsNullOrEmpty(submessage))
|
2013-07-09 03:59:17 -04:00
|
|
|
{
|
|
|
|
_progressDialog.SetMessage(_message + " (" + submessage + ")");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_progressDialog.SetMessage(_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
#region IStatusLogger implementation
|
|
|
|
|
|
|
|
public void StartLogging (string strOperation, bool bWriteOperationToLog)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void EndLogging ()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool SetProgress (uint uPercent)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool SetText (string strNewText, LogStatusType lsType)
|
|
|
|
{
|
2013-07-09 03:59:17 -04:00
|
|
|
if (strNewText.StartsWith("KP2AKEY_"))
|
|
|
|
{
|
|
|
|
UiStringKey key;
|
|
|
|
if (Enum.TryParse(strNewText.Substring("KP2AKEY_".Length), true, out key))
|
|
|
|
{
|
|
|
|
UpdateMessage(_app.GetResourceString(key), lsType);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UpdateMessage(strNewText, lsType);
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-09 03:59:17 -04:00
|
|
|
private void UpdateMessage(string message, LogStatusType lsType)
|
|
|
|
{
|
|
|
|
if (lsType == LogStatusType.AdditionalInfo)
|
|
|
|
{
|
|
|
|
UpdateSubMessage(message);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UpdateMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
public bool ContinueWork ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|