Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59d362a4 authored by Qinmei Du's avatar Qinmei Du
Browse files

Change the sorting logic to only sort by lastUsed on primary selection screen...

Change the sorting logic to only sort by lastUsed on primary selection screen and only show at most 4 items

screencast: https://drive.google.com/file/d/1UnOGsUKi_MmcaZSwq2UgRxnkmLPc03Xg/view?usp=sharing&resourcekey=0-Sg46xXpyt81uZd_-XLwBVg

Test: deployed locally

Bug: 253157237
Change-Id: I1970fa4f282b18696fc2400e3e2fba5c4b2889fa
parent c106493d
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -214,17 +214,21 @@ class CredentialManagerRepo(
      GetCredentialProviderData.Builder("io.enpass.app")
        .setCredentialEntries(
          listOf<Entry>(
              newGetEntry(
                  "key1", "subkey-1", TYPE_PASSWORD_CREDENTIAL, "Password",
                  "elisa.family@outlook.com", null, 3L
              ),
            newGetEntry(
              "key1", "subkey-1", TYPE_PUBLIC_KEY_CREDENTIAL, "Passkey",
              "elisa.bakery@gmail.com", "Elisa Beckett", 300L
              "elisa.bakery@gmail.com", "Elisa Beckett", 0L
            ),
            newGetEntry(
              "key1", "subkey-2", TYPE_PASSWORD_CREDENTIAL, "Password",
              "elisa.bakery@gmail.com", null, 300L
              "elisa.bakery@gmail.com", null, 10L
            ),
            newGetEntry(
              "key1", "subkey-3", TYPE_PASSWORD_CREDENTIAL, "Password",
              "elisa.family@outlook.com", null, 100L
              "key1", "subkey-3", TYPE_PUBLIC_KEY_CREDENTIAL, "Passkey",
              "elisa.family@outlook.com", "Elisa Beckett", 1L
            ),
          )
        ).setAuthenticationEntry(
@@ -247,12 +251,12 @@ class CredentialManagerRepo(
        .setCredentialEntries(
          listOf<Entry>(
            newGetEntry(
              "key1", "subkey-1", TYPE_PASSWORD_CREDENTIAL, "Password",
              "elisa.family@outlook.com", null, 600L
              "key1", "subkey-2", TYPE_PASSWORD_CREDENTIAL, "Password",
              "elisa.family@outlook.com", null, 4L
            ),
            newGetEntry(
              "key1", "subkey-2", TYPE_PUBLIC_KEY_CREDENTIAL, "Passkey",
              "elisa.family@outlook.com", null, 100L
                  "key1", "subkey-3", TYPE_PASSWORD_CREDENTIAL, "Password",
                  "elisa.work@outlook.com", null, 11L
            ),
          )
        ).setAuthenticationEntry(
+49 −17
Original line number Diff line number Diff line
@@ -146,13 +146,19 @@ fun PrimarySelectionCard(
                textAlign = TextAlign.Center,
                style = MaterialTheme.typography.headlineSmall,
                text = stringResource(
                    if (sortedUserNameToCredentialEntryList.size == 1) {
                        if (sortedUserNameToCredentialEntryList.first().sortedCredentialEntryList
                                .first().credentialType
                    if (sortedUserNameToCredentialEntryList
                            .size == 1 && authenticationEntryList.isEmpty()
                    ) {
                        if (sortedUserNameToCredentialEntryList.first()
                                .sortedCredentialEntryList.first().credentialType
                            == PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL
                        )
                            R.string.get_dialog_title_use_passkey_for
                        ) R.string.get_dialog_title_use_passkey_for
                        else R.string.get_dialog_title_use_sign_in_for
                    } else if (
                        sortedUserNameToCredentialEntryList
                            .isEmpty() && authenticationEntryList.size == 1
                    ) {
                        R.string.get_dialog_title_use_sign_in_for
                    } else R.string.get_dialog_title_choose_sign_in_for,
                    requestDisplayInfo.appDomainName
                ),
@@ -164,9 +170,14 @@ fun PrimarySelectionCard(
                    .padding(horizontal = 24.dp)
                    .align(alignment = Alignment.CenterHorizontally)
            ) {
                val usernameForCredentialSize = sortedUserNameToCredentialEntryList
                    .size
                val authenticationEntrySize = authenticationEntryList.size
                LazyColumn(
                    verticalArrangement = Arrangement.spacedBy(2.dp)
                ) {
                    // Show max 4 entries in this primary page
                    if (usernameForCredentialSize + authenticationEntrySize <= 4) {
                        items(sortedUserNameToCredentialEntryList) {
                            CredentialEntryRow(
                                credentialEntryInfo = it.sortedCredentialEntryList.first(),
@@ -179,6 +190,27 @@ fun PrimarySelectionCard(
                                onEntrySelected = onEntrySelected,
                            )
                        }
                    } else if (usernameForCredentialSize < 4) {
                        items(sortedUserNameToCredentialEntryList) {
                            CredentialEntryRow(
                                credentialEntryInfo = it.sortedCredentialEntryList.first(),
                                onEntrySelected = onEntrySelected,
                            )
                        }
                        items(authenticationEntryList.take(4 - usernameForCredentialSize)) {
                            AuthenticationEntryRow(
                                authenticationEntryInfo = it,
                                onEntrySelected = onEntrySelected,
                            )
                        }
                    } else {
                        items(sortedUserNameToCredentialEntryList.take(4)) {
                            CredentialEntryRow(
                                credentialEntryInfo = it.sortedCredentialEntryList.first(),
                                onEntrySelected = onEntrySelected,
                            )
                        }
                    }
                }
            }
            Divider(
@@ -257,7 +289,7 @@ fun AllSignInOptionCard(
                        )
                    }
                    // Locked password manager
                    if (!authenticationEntryList.isEmpty()) {
                    if (authenticationEntryList.isNotEmpty()) {
                        item {
                            LockedCredentials(
                                authenticationEntryList = authenticationEntryList,
+3 −3
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ private fun toProviderDisplayInfo(
  Preconditions.checkState(remoteEntryList.size <= 1)

  // Compose sortedUserNameToCredentialEntryList
  val comparator = CredentialEntryInfoComparator()
  val comparator = CredentialEntryInfoComparatorByTypeThenTimestamp()
  // Sort per username
  userNameToCredentialEntryMap.values.forEach {
    it.sortWith(comparator)
@@ -191,7 +191,7 @@ private fun toProviderDisplayInfo(
  val sortedUserNameToCredentialEntryList = userNameToCredentialEntryMap.map {
    PerUserNameCredentialEntryList(it.key, it.value)
  }.sortedWith(
    compareBy(comparator) { it.sortedCredentialEntryList.first() }
    compareByDescending{ it.sortedCredentialEntryList.first().lastUsedTimeMillis }
  )

  return ProviderDisplayInfo(
@@ -219,7 +219,7 @@ private fun toGetScreenState(
    GetScreenState.REMOTE_ONLY else GetScreenState.PRIMARY_SELECTION
}

internal class CredentialEntryInfoComparator : Comparator<CredentialEntryInfo> {
internal class CredentialEntryInfoComparatorByTypeThenTimestamp : Comparator<CredentialEntryInfo> {
  override fun compare(p0: CredentialEntryInfo, p1: CredentialEntryInfo): Int {
    // First prefer passkey type for its security benefits
    if (p0.credentialType != p1.credentialType) {