Bug fixes:

- ShowUserNotifications now correctly defaults to true in CreateEntryThenCloseTask
 - fixed message of donation dialog
 - fixed problem with exception in TrayTotpHandler when displaying toast
This commit is contained in:
Philipp Crocoll
2014-06-05 21:40:43 +02:00
parent 073ae00a6d
commit 388dfd6fb0
7 changed files with 31 additions and 10 deletions

View File

@@ -7,6 +7,6 @@ namespace PluginTOTP
interface ITotpPluginAdapter interface ITotpPluginAdapter
{ {
TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx); TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx, bool muteWarnings);
} }
} }

View File

@@ -19,7 +19,7 @@ namespace PluginTOTP
const string SizeParameter = "size"; const string SizeParameter = "size";
public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx) public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx, bool muteWarnings)
{ {
return new KeeOtpHandler(entryFields, ctx).GetData(); return new KeeOtpHandler(entryFields, ctx).GetData();
} }

View File

@@ -17,7 +17,7 @@ namespace keepass2android
{ {
foreach (ITotpPluginAdapter adapter in _pluginAdapters) foreach (ITotpPluginAdapter adapter in _pluginAdapters)
{ {
TotpData totpData = adapter.GetTotpData(App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()), Application.Context); TotpData totpData = adapter.GetTotpData(App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()), Application.Context, false);
if (totpData.IsTotpEnry) if (totpData.IsTotpEnry)
{ {
new UpdateTotpTimerTask(Application.Context, adapter).Run(); new UpdateTotpTimerTask(Application.Context, adapter).Run();

View File

@@ -1,30 +1,34 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Android.Content; using Android.Content;
using Android.OS;
using Android.Preferences; using Android.Preferences;
using Android.Widget; using Android.Widget;
using KeePassLib.Collections;
using keepass2android; using keepass2android;
namespace PluginTOTP namespace PluginTOTP
{ {
class TrayTotpPluginAdapter : ITotpPluginAdapter class TrayTotpPluginAdapter : ITotpPluginAdapter
{ {
public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx) public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx, bool muteWarnings)
{ {
return new TrayTotpHandler(ctx).GetTotpData(entryFields); return new TrayTotpHandler(ctx, new Handler(Looper.MainLooper), muteWarnings).GetTotpData(entryFields);
} }
private class TrayTotpHandler private class TrayTotpHandler
{ {
private readonly Context _ctx; private readonly Context _ctx;
private readonly Handler _uiThreadHandler;
private readonly bool _muteWarnings;
private string SeedFieldName { get { return PreferenceManager.GetDefaultSharedPreferences(_ctx).GetString(_ctx.GetString(Resource.String.TrayTotp_SeedField_key), "TOTP Seed"); } } private string SeedFieldName { get { return PreferenceManager.GetDefaultSharedPreferences(_ctx).GetString(_ctx.GetString(Resource.String.TrayTotp_SeedField_key), "TOTP Seed"); } }
private string SettingsFieldName { get { return PreferenceManager.GetDefaultSharedPreferences(_ctx).GetString(_ctx.GetString(Resource.String.TrayTotp_SettingsField_key), "TOTP Settings"); } } private string SettingsFieldName { get { return PreferenceManager.GetDefaultSharedPreferences(_ctx).GetString(_ctx.GetString(Resource.String.TrayTotp_SettingsField_key), "TOTP Settings"); } }
public TrayTotpHandler(Context ctx) public TrayTotpHandler(Context ctx, Handler uiThreadHandler, bool muteWarnings)
{ {
_ctx = ctx; _ctx = ctx;
_uiThreadHandler = uiThreadHandler;
_muteWarnings = muteWarnings;
} }
/// <summary> /// <summary>
@@ -156,7 +160,18 @@ namespace PluginTOTP
private void ShowWarning(string warning) private void ShowWarning(string warning)
{ {
Toast.MakeText(_ctx, warning, ToastLength.Short).Show(); if (_muteWarnings)
return;
try
{
_uiThreadHandler.Post(() => Toast.MakeText(_ctx, warning, ToastLength.Short).Show());
}
catch (Exception e)
{
Kp2aLog.Log(e.ToString());
//ignore, it's only a warning
}
} }
private bool SeedValidate(IDictionary<string, string> entryFields, out string invalidCharacters) private bool SeedValidate(IDictionary<string, string> entryFields, out string invalidCharacters)

View File

@@ -31,7 +31,8 @@ namespace PluginTOTP
return; //DB was locked return; //DB was locked
Dictionary<string, string> entryFields = App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()); Dictionary<string, string> entryFields = App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString());
TotpData totpData = _adapter.GetTotpData(entryFields, _context); //mute warnings to avoid repeated display of the toasts
TotpData totpData = _adapter.GetTotpData(entryFields, _context, true /*mute warnings*/);
if (totpData.IsTotpEnry) if (totpData.IsTotpEnry)
{ {
//generate a new totp //generate a new totp

View File

@@ -357,7 +357,7 @@ namespace keepass2android
if ((bool) args.NewValue) if ((bool) args.NewValue)
{ {
new AlertDialog.Builder(ctx) new AlertDialog.Builder(ctx)
.SetTitle(AppNames.AppName) .SetTitle(ctx.GetString(AppNames.AppNameResource))
.SetCancelable(false) .SetCancelable(false)
.SetPositiveButton(Android.Resource.String.Ok, delegate(object o, DialogClickEventArgs eventArgs) .SetPositiveButton(Android.Resource.String.Ok, delegate(object o, DialogClickEventArgs eventArgs)
{ {

View File

@@ -586,6 +586,11 @@ namespace keepass2android
/// </summary> /// </summary>
public class CreateEntryThenCloseTask: AppTask public class CreateEntryThenCloseTask: AppTask
{ {
public CreateEntryThenCloseTask()
{
ShowUserNotifications = true;
}
/// <summary> /// <summary>
/// extra key if only a URL is passed. optional. /// extra key if only a URL is passed. optional.
/// </summary> /// </summary>