Autofill: fill emailAddress fields with username
This commit is contained in:
@@ -55,13 +55,15 @@ namespace keepass2android.services.Kp2aAutofill
|
|||||||
|
|
||||||
foreach (string key in pwEntryOutput.OutputStrings.GetKeys())
|
foreach (string key in pwEntryOutput.OutputStrings.GetKeys())
|
||||||
{
|
{
|
||||||
|
|
||||||
FilledAutofillField field =
|
FilledAutofillField field =
|
||||||
new FilledAutofillField
|
new FilledAutofillField
|
||||||
{
|
{
|
||||||
AutofillHints = new[] {GetCanonicalHintFromKp2aField(key)},
|
AutofillHints = GetCanonicalHintsFromKp2aField(key).ToArray(),
|
||||||
TextValue = pwEntryOutput.OutputStrings.ReadSafe(key)
|
TextValue = pwEntryOutput.OutputStrings.ReadSafe(key)
|
||||||
};
|
};
|
||||||
fieldCollection.Add(field);
|
fieldCollection.Add(field);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (IsCreditCard(pwEntry, context) && pwEntry.Expires)
|
if (IsCreditCard(pwEntry, context) && pwEntry.Expires)
|
||||||
{
|
{
|
||||||
@@ -112,42 +114,47 @@ namespace keepass2android.services.Kp2aAutofill
|
|||||||
|| pwEntry.Strings.Exists(context.GetString(Resource.String.TemplateField_CreditCard_CVV));
|
|| pwEntry.Strings.Exists(context.GetString(Resource.String.TemplateField_CreditCard_CVV));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<string, string> keyToHint = BuildKeyToHint();
|
private static readonly Dictionary<string, List<string>> keyToHint = BuildKeyToHints();
|
||||||
|
|
||||||
public static string GetKp2aKeyFromHint(string canonicalHint)
|
public static string GetKp2aKeyFromHint(string canonicalHint)
|
||||||
{
|
{
|
||||||
var key = keyToHint.FirstOrDefault(p => p.Value.Equals(canonicalHint, StringComparison.OrdinalIgnoreCase)).Key;
|
var key = keyToHint.FirstOrDefault(p => p.Value.Contains(canonicalHint)).Key;
|
||||||
if (string.IsNullOrWhiteSpace(key))
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
return canonicalHint;
|
return canonicalHint;
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<string, string> BuildKeyToHint()
|
private static Dictionary<string, List<string>> BuildKeyToHints()
|
||||||
{
|
{
|
||||||
var result = new Dictionary<string, string>
|
var result = new Dictionary<string, List<string>>
|
||||||
{
|
{
|
||||||
{PwDefs.UserNameField, View.AutofillHintUsername},
|
{PwDefs.UserNameField, new List<string>{View.AutofillHintUsername, View.AutofillHintEmailAddress}},
|
||||||
{PwDefs.PasswordField, View.AutofillHintPassword},
|
{PwDefs.PasswordField, new List<string>{View.AutofillHintPassword}},
|
||||||
{PwDefs.UrlField, W3cHints.URL},
|
{PwDefs.UrlField, new List<string>{W3cHints.URL}},
|
||||||
{
|
{
|
||||||
Application.Context.GetString(Resource.String.TemplateField_CreditCard_CVV),
|
Application.Context.GetString(Resource.String.TemplateField_CreditCard_CVV),
|
||||||
View.AutofillHintCreditCardSecurityCode
|
new List<string>{View.AutofillHintCreditCardSecurityCode}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Application.Context.GetString(Resource.String.TemplateField_CreditCard_Owner),
|
Application.Context.GetString(Resource.String.TemplateField_CreditCard_Owner),
|
||||||
W3cHints.CC_NAME
|
new List<string>{W3cHints.CC_NAME}
|
||||||
},
|
},
|
||||||
{Application.Context.GetString(Resource.String.TemplateField_Number), View.AutofillHintCreditCardNumber},
|
{Application.Context.GetString(Resource.String.TemplateField_Number), new List<string>{View.AutofillHintCreditCardNumber}},
|
||||||
{Application.Context.GetString(Resource.String.TemplateField_IdCard_Name), View.AutofillHintName},
|
{Application.Context.GetString(Resource.String.TemplateField_IdCard_Name), new List<string>{View.AutofillHintName}},
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCanonicalHintFromKp2aField(string key)
|
private static List<string> GetCanonicalHintsFromKp2aField(string key)
|
||||||
{
|
{
|
||||||
if (!keyToHint.TryGetValue(key, out string result))
|
List<string> result = new List<string>() {key};
|
||||||
result = key;
|
List<string> hints;
|
||||||
result = result.ToLower();
|
if (keyToHint.TryGetValue(key, out hints))
|
||||||
|
result = hints;
|
||||||
|
for (int i = 0; i < result.Count; i++)
|
||||||
|
{
|
||||||
|
result[i] = result[i].ToLower();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user