Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
[components] Autofill: Show fallback if login is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo authored and mergify[bot] committed Feb 25, 2021
1 parent b6c9549 commit 8da64a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ private fun createLoginsResponse(

logins.forEach { login ->
val usernamePresentation = RemoteViews(context.packageName, android.R.layout.simple_list_item_1)
usernamePresentation.setTextViewText(android.R.id.text1, login.username)
usernamePresentation.setTextViewText(android.R.id.text1, login.usernamePresentationOrFallback(context))
val passwordPresentation = RemoteViews(context.packageName, android.R.layout.simple_list_item_1)
passwordPresentation.setTextViewText(android.R.id.text1, "Password for ${login.username}")
passwordPresentation.setTextViewText(android.R.id.text1, login.passwordPresentation(context))

val dataset = Dataset.Builder()

Expand All @@ -132,3 +132,18 @@ private fun createLoginsResponse(

return builder.build()
}

private fun Login.usernamePresentationOrFallback(context: Context): String {
return if (username.isNotEmpty()) {
username
} else {
context.getString(R.string.mozac_feature_autofill_popup_no_username)
}
}

private fun Login.passwordPresentation(context: Context): String {
return context.getString(
R.string.mozac_feature_autofill_popup_password,
usernamePresentationOrFallback(context)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@
a username or password can be autofilled for the highlighted text field. %1$s will be replaced
with the name of the browser application (e.g. Firefox) -->
<string name="mozac_feature_autofill_popup_unlock_application">Unlock %1$s</string>

<!-- Autofill: Text shown in popup in third-party app if we found a matching account, but no
username is saved (e.g. we only have a password). This text will be shown in place where otherwise
the username would be displayed. -->
<string name="mozac_feature_autofill_popup_no_username">(No username)</string>

<!-- Autofill: Text shown in popup in third-party app to autofill the password for an account.
%1$s will be replaced with the login/username of the account. -->
<string name="mozac_feature_autofill_popup_password">Password for %1$s</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class DummyLoginsStorage : LoginsStorage {
origin = "twitter.com",
username = "NotAnAccount",
password = "NotReallyAPassword"
),
Login(
guid = "8034a37f-5f9e-4136-95b2-e0293116b322",
origin = "twitter.com",
username = "",
password = "NotReallyAPassword"
)
)

Expand Down

0 comments on commit 8da64a1

Please sign in to comment.