display notifications to allow copying TOTP to clipboard when autofilling, closes #1072

This commit is contained in:
Philipp Crocoll
2020-02-15 03:55:43 +01:00
parent 7ba17b8552
commit e51999ea1f
4 changed files with 20 additions and 15 deletions

View File

@@ -92,7 +92,7 @@ namespace keepass2android
{
public const String KeyEntry = "entry";
public const String KeyRefreshPos = "refresh_pos";
public const String KeyCloseAfterCreate = "close_after_create";
public const String KeyActivateKeyboard = "activate_keyboard";
public const String KeyGroupFullPath = "groupfullpath_key";
public const int requestCodeBinaryFilename = 42376;
@@ -480,13 +480,13 @@ namespace keepass2android
internal void StartNotificationsService(bool closeAfterCreate)
internal void StartNotificationsService(bool activateKeyboard)
{
Intent showNotIntent = new Intent(this, typeof (CopyToClipboardService));
showNotIntent.SetAction(Intents.ShowNotification);
showNotIntent.PutExtra(KeyEntry, new ElementAndDatabaseId(App.Kp2a.CurrentDb, Entry).FullId);
_appTask.PopulatePasswordAccessServiceIntent(showNotIntent);
showNotIntent.PutExtra(KeyCloseAfterCreate, closeAfterCreate);
showNotIntent.PutExtra(KeyActivateKeyboard, activateKeyboard);
StartService(showNotIntent);
}

View File

@@ -511,7 +511,8 @@ namespace keepass2android
{
ShowUserNotifications = ShowUserNotificationsMode.Always;
CloseAfterCreate = true;
}
ActivateKeyboard = true;
}
public const String ShowUserNotificationsKey = "ShowUserNotifications";
@@ -520,15 +521,18 @@ namespace keepass2android
public ShowUserNotificationsMode ShowUserNotifications { get; set; }
public const String CloseAfterCreateKey = "CloseAfterCreate";
public const String ActivateKeyboardKey = "ActivateKeyboard";
public bool CloseAfterCreate { get; set; }
public bool CloseAfterCreate { get; set; }
public bool ActivateKeyboard { get; set; }
public override void Setup(Bundle b)
public override void Setup(Bundle b)
{
ShowUserNotifications = (ShowUserNotificationsMode) GetIntFromBundle(b, ShowUserNotificationsKey, (int)ShowUserNotificationsMode.Always);
CloseAfterCreate = GetBoolFromBundle(b, CloseAfterCreateKey, true);
}
ActivateKeyboard = GetBoolFromBundle(b, ActivateKeyboardKey, true);
}
public override IEnumerable<IExtra> Extras
@@ -537,7 +541,8 @@ namespace keepass2android
{
yield return new StringExtra { Key = ShowUserNotificationsKey, Value = ((int)ShowUserNotifications).ToString() };
yield return new StringExtra { Key = CloseAfterCreateKey, Value = CloseAfterCreate.ToString() };
}
yield return new StringExtra { Key = ActivateKeyboardKey, Value = ActivateKeyboard.ToString() };
}
}
public override void CompleteOnCreateEntryActivity(EntryActivity activity)
@@ -550,7 +555,7 @@ namespace keepass2android
|| ((ShowUserNotifications == ShowUserNotificationsMode.WhenTotp) && new Kp2aTotp().TryGetAdapter(new PwEntryOutput(activity.Entry, App.Kp2a.CurrentDb)) != null))
{
//show the notifications
activity.StartNotificationsService(CloseAfterCreate);
activity.StartNotificationsService(ActivateKeyboard);
}
else
{

View File

@@ -347,8 +347,8 @@ namespace keepass2android
if (intent.Action == Intents.ShowNotification)
{
//first time opening the entry -> bring up the notifications
bool closeAfterCreate = intent.GetBooleanExtra(EntryActivity.KeyCloseAfterCreate, false);
DisplayAccessNotifications(entry, closeAfterCreate, searchUrl);
bool activateKeyboard = intent.GetBooleanExtra(EntryActivity.KeyActivateKeyboard, false);
DisplayAccessNotifications(entry, activateKeyboard, searchUrl);
}
else //UpdateKeyboard
{
@@ -429,7 +429,7 @@ namespace keepass2android
public void DisplayAccessNotifications(PwEntryOutput entry, bool closeAfterCreate, string searchUrl)
public void DisplayAccessNotifications(PwEntryOutput entry, bool activateKeyboard, string searchUrl)
{
var hadKeyboardData = ClearNotifications();
@@ -483,7 +483,7 @@ namespace keepass2android
{
//switch rooted
bool onlySwitchOnSearch = prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key), false);
if (closeAfterCreate || (!onlySwitchOnSearch))
if (activateKeyboard || (!onlySwitchOnSearch))
{
ActivateKp2aKeyboard();
}
@@ -492,7 +492,7 @@ namespace keepass2android
{
//if the app is about to be closed again (e.g. after searching for a URL and returning to the browser:
// automatically bring up the Keyboard selection dialog
if ((closeAfterCreate) && prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomatically_key), Resources.GetBoolean(Resource.Boolean.OpenKp2aKeyboardAutomatically_default)))
if ((activateKeyboard) && prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomatically_key), Resources.GetBoolean(Resource.Boolean.OpenKp2aKeyboardAutomatically_default)))
{
ActivateKp2aKeyboard();
}

View File

@@ -30,7 +30,7 @@ namespace keepass2android.services.Kp2aAutofill
//will return the results later
Intent i = new Intent(this, typeof(SelectCurrentDbActivity));
//don't show user notifications when an entry is opened.
var task = new SearchUrlTask() { UrlToSearchFor = requestedUrl, ShowUserNotifications = ShowUserNotificationsMode.WhenTotp, AutoReturnFromQuery = autoReturnFromQuery };
var task = new SearchUrlTask() { UrlToSearchFor = requestedUrl, ShowUserNotifications = ShowUserNotificationsMode.WhenTotp, AutoReturnFromQuery = autoReturnFromQuery, ActivateKeyboard = false };
task.ToIntent(i);
return i;
}