start implementing notifications when searching, e.g. for Autofill
This commit is contained in:
@@ -139,7 +139,7 @@ namespace keepass2android
|
|||||||
//will return the results later
|
//will return the results later
|
||||||
Intent i = new Intent(this, typeof (SelectCurrentDbActivity));
|
Intent i = new Intent(this, typeof (SelectCurrentDbActivity));
|
||||||
//don't show user notifications when an entry is opened.
|
//don't show user notifications when an entry is opened.
|
||||||
var task = new SearchUrlTask() {UrlToSearchFor = _requestedUrl, ShowUserNotifications = false};
|
var task = new SearchUrlTask() {UrlToSearchFor = _requestedUrl, ShowUserNotifications = ShowUserNotificationsMode.WhenTotp};
|
||||||
task.ToIntent(i);
|
task.ToIntent(i);
|
||||||
StartActivityForResult(i, RequestCodeQuery);
|
StartActivityForResult(i, RequestCodeQuery);
|
||||||
_startedQuery = true;
|
_startedQuery = true;
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace keepass2android
|
|||||||
createUrlEntry.Visibility = ViewStates.Visible;
|
createUrlEntry.Visibility = ViewStates.Visible;
|
||||||
createUrlEntry.Click += (sender, e) =>
|
createUrlEntry.Click += (sender, e) =>
|
||||||
{
|
{
|
||||||
GroupActivity.Launch(this, new CreateEntryThenCloseTask { Url = url, ShowUserNotifications = (AppTask as SelectEntryTask)?.ShowUserNotifications ?? true }, new ActivityLaunchModeRequestCode(0));
|
GroupActivity.Launch(this, new CreateEntryThenCloseTask { Url = url, ShowUserNotifications = (AppTask as SelectEntryTask)?.ShowUserNotifications ?? ShowUserNotificationsMode.Always }, new ActivityLaunchModeRequestCode(0));
|
||||||
Toast.MakeText(this, GetString(Resource.String.select_group_then_add, new Java.Lang.Object[] { GetString(Resource.String.add_entry) }), ToastLength.Long).Show();
|
Toast.MakeText(this, GetString(Resource.String.select_group_then_add, new Java.Lang.Object[] { GetString(Resource.String.add_entry) }), ToastLength.Long).Show();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Android.App;
|
using Android.App;
|
||||||
|
using KeePassLib;
|
||||||
using KeePassLib.Utility;
|
using KeePassLib.Utility;
|
||||||
using PluginTOTP;
|
using PluginTOTP;
|
||||||
|
|
||||||
@@ -12,18 +13,27 @@ namespace keepass2android
|
|||||||
|
|
||||||
readonly ITotpPluginAdapter[] _pluginAdapters = new ITotpPluginAdapter[] { new TrayTotpPluginAdapter(), new KeeOtpPluginAdapter(), new KeeWebOtpPluginAdapter() };
|
readonly ITotpPluginAdapter[] _pluginAdapters = new ITotpPluginAdapter[] { new TrayTotpPluginAdapter(), new KeeOtpPluginAdapter(), new KeeWebOtpPluginAdapter() };
|
||||||
|
|
||||||
|
public ITotpPluginAdapter TryGetAdapter(PwEntryOutput entry)
|
||||||
|
{
|
||||||
|
if (entry == null)
|
||||||
|
return null;
|
||||||
|
foreach (ITotpPluginAdapter adapter in _pluginAdapters)
|
||||||
|
{
|
||||||
|
TotpData totpData = adapter.GetTotpData(App.Kp2a.LastOpenedEntry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()), Application.Context, false);
|
||||||
|
if (totpData.IsTotpEnry)
|
||||||
|
{
|
||||||
|
return adapter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void OnOpenEntry()
|
public void OnOpenEntry()
|
||||||
{
|
{
|
||||||
if (App.Kp2a.LastOpenedEntry == null)
|
var adapter = TryGetAdapter(App.Kp2a.LastOpenedEntry);
|
||||||
return;
|
if (adapter != null)
|
||||||
foreach (ITotpPluginAdapter adapter in _pluginAdapters)
|
new UpdateTotpTimerTask(Application.Context, adapter).Run();
|
||||||
{
|
}
|
||||||
TotpData totpData = adapter.GetTotpData(App.Kp2a.LastOpenedEntry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()), Application.Context, false);
|
|
||||||
if (totpData.IsTotpEnry)
|
|
||||||
{
|
|
||||||
new UpdateTotpTimerTask(Application.Context, adapter).Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,7 +348,28 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
protected static bool GetBoolFromBundle(Bundle b, string key, bool defaultValue)
|
||||||
|
{
|
||||||
|
bool boolValue;
|
||||||
|
if (!Boolean.TryParse(b.GetString(key), out boolValue))
|
||||||
|
{
|
||||||
|
boolValue = defaultValue;
|
||||||
|
}
|
||||||
|
return boolValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static int GetIntFromBundle(Bundle b, string key, int defaultValue)
|
||||||
|
{
|
||||||
|
int intValue;
|
||||||
|
if (!Int32.TryParse(b.GetString(key), out intValue))
|
||||||
|
{
|
||||||
|
intValue = defaultValue;
|
||||||
|
}
|
||||||
|
return intValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of AppTask for "no task currently active" (Null pattern)
|
/// Implementation of AppTask for "no task currently active" (Null pattern)
|
||||||
@@ -474,21 +495,29 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
public enum ShowUserNotificationsMode
|
||||||
/// User is about to select an entry for use in another app
|
{
|
||||||
/// </summary>
|
Never,
|
||||||
public class SelectEntryTask: AppTask
|
WhenTotp,
|
||||||
|
Always
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// User is about to select an entry for use in another app
|
||||||
|
/// </summary>
|
||||||
|
public class SelectEntryTask: AppTask
|
||||||
{
|
{
|
||||||
public SelectEntryTask()
|
public SelectEntryTask()
|
||||||
{
|
{
|
||||||
ShowUserNotifications = true;
|
ShowUserNotifications = ShowUserNotificationsMode.Always;
|
||||||
CloseAfterCreate = true;
|
CloseAfterCreate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public const String ShowUserNotificationsKey = "ShowUserNotifications";
|
public const String ShowUserNotificationsKey = "ShowUserNotifications";
|
||||||
|
|
||||||
public bool ShowUserNotifications { get; set; }
|
|
||||||
|
|
||||||
|
public ShowUserNotificationsMode ShowUserNotifications { get; set; }
|
||||||
|
|
||||||
public const String CloseAfterCreateKey = "CloseAfterCreate";
|
public const String CloseAfterCreateKey = "CloseAfterCreate";
|
||||||
|
|
||||||
@@ -497,25 +526,16 @@ namespace keepass2android
|
|||||||
|
|
||||||
public override void Setup(Bundle b)
|
public override void Setup(Bundle b)
|
||||||
{
|
{
|
||||||
ShowUserNotifications = GetBoolFromBundle(b, ShowUserNotificationsKey, true);
|
ShowUserNotifications = (ShowUserNotificationsMode) GetIntFromBundle(b, ShowUserNotificationsKey, (int)ShowUserNotificationsMode.Always);
|
||||||
CloseAfterCreate = GetBoolFromBundle(b, CloseAfterCreateKey, true);
|
CloseAfterCreate = GetBoolFromBundle(b, CloseAfterCreateKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool GetBoolFromBundle(Bundle b, string key, bool defaultValue)
|
|
||||||
{
|
|
||||||
bool boolValue;
|
|
||||||
if (!Boolean.TryParse(b.GetString(key), out boolValue))
|
|
||||||
{
|
|
||||||
boolValue = defaultValue;
|
|
||||||
}
|
|
||||||
return boolValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IEnumerable<IExtra> Extras
|
public override IEnumerable<IExtra> Extras
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
yield return new StringExtra { Key = ShowUserNotificationsKey, Value = ShowUserNotifications.ToString() };
|
yield return new StringExtra { Key = ShowUserNotificationsKey, Value = ((int)ShowUserNotifications).ToString() };
|
||||||
yield return new StringExtra { Key = CloseAfterCreateKey, Value = CloseAfterCreate.ToString() };
|
yield return new StringExtra { Key = CloseAfterCreateKey, Value = CloseAfterCreate.ToString() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -526,7 +546,8 @@ namespace keepass2android
|
|||||||
if (ctx == null)
|
if (ctx == null)
|
||||||
ctx = Application.Context;
|
ctx = Application.Context;
|
||||||
|
|
||||||
if (ShowUserNotifications)
|
if ((ShowUserNotifications == ShowUserNotificationsMode.Always)
|
||||||
|
|| ((ShowUserNotifications == ShowUserNotificationsMode.WhenTotp) && new Kp2aTotp().TryGetAdapter(new PwEntryOutput(activity.Entry, App.Kp2a.CurrentDb)) != null))
|
||||||
{
|
{
|
||||||
//show the notifications
|
//show the notifications
|
||||||
activity.StartNotificationsService(CloseAfterCreate);
|
activity.StartNotificationsService(CloseAfterCreate);
|
||||||
@@ -604,7 +625,7 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
public CreateEntryThenCloseTask()
|
public CreateEntryThenCloseTask()
|
||||||
{
|
{
|
||||||
ShowUserNotifications = true;
|
ShowUserNotifications = ShowUserNotificationsMode.Always;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanActivateSearchViewOnStart
|
public override bool CanActivateSearchViewOnStart
|
||||||
@@ -644,17 +665,13 @@ namespace keepass2android
|
|||||||
|
|
||||||
public IList<string> ProtectedFieldsList { get; set; }
|
public IList<string> ProtectedFieldsList { get; set; }
|
||||||
|
|
||||||
public bool ShowUserNotifications { get; set; }
|
public ShowUserNotificationsMode ShowUserNotifications { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public override void Setup(Bundle b)
|
public override void Setup(Bundle b)
|
||||||
{
|
{
|
||||||
bool showUserNotification;
|
|
||||||
if (!Boolean.TryParse(b.GetString(ShowUserNotificationsKey), out showUserNotification))
|
ShowUserNotifications = (ShowUserNotificationsMode)GetIntFromBundle(b,ShowUserNotificationsKey, (int)ShowUserNotificationsMode.Always);
|
||||||
{
|
|
||||||
showUserNotification = true; //default to true
|
|
||||||
}
|
|
||||||
ShowUserNotifications = showUserNotification;
|
|
||||||
|
|
||||||
Url = b.GetString(UrlKey);
|
Url = b.GetString(UrlKey);
|
||||||
AllFields = b.GetString(AllFieldsKey);
|
AllFields = b.GetString(AllFieldsKey);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace keepass2android.services.Kp2aAutofill
|
|||||||
//will return the results later
|
//will return the results later
|
||||||
Intent i = new Intent(this, typeof(SelectCurrentDbActivity));
|
Intent i = new Intent(this, typeof(SelectCurrentDbActivity));
|
||||||
//don't show user notifications when an entry is opened.
|
//don't show user notifications when an entry is opened.
|
||||||
var task = new SearchUrlTask() { UrlToSearchFor = requestedUrl, ShowUserNotifications = false, AutoReturnFromQuery = autoReturnFromQuery };
|
var task = new SearchUrlTask() { UrlToSearchFor = requestedUrl, ShowUserNotifications = ShowUserNotificationsMode.WhenTotp, AutoReturnFromQuery = autoReturnFromQuery };
|
||||||
task.ToIntent(i);
|
task.ToIntent(i);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user