Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-10071] Sort search items with same logic as displayed items #3683

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
import com.x8bit.bitwarden.data.platform.repository.model.DataState
import com.x8bit.bitwarden.data.platform.repository.util.baseIconUrl
import com.x8bit.bitwarden.data.platform.repository.util.baseWebSendUrl
import com.x8bit.bitwarden.data.platform.util.CompareStringSpecialCharWithPrecedence
import com.x8bit.bitwarden.data.vault.datasource.network.model.PolicyTypeJson
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
import com.x8bit.bitwarden.data.vault.repository.model.DeleteSendResult
Expand Down Expand Up @@ -802,6 +803,16 @@ data class SearchState(
) : Parcelable
}

/**
* Sort a list of [SearchState.DisplayItem] by their titles alphabetically giving digits and
* special characters higher precedence.
*/
fun List<SearchState.DisplayItem>.sortAlphabetically(): List<SearchState.DisplayItem> {
return this.sortedWith { item1, item2 ->
CompareStringSpecialCharWithPrecedence.compare(item1.title, item2.title)
}
}

/**
* Represents the difference between searching sends and searching vault items.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.x8bit.bitwarden.ui.platform.components.model.IconData
import com.x8bit.bitwarden.ui.platform.feature.search.SearchState
import com.x8bit.bitwarden.ui.platform.feature.search.SearchTypeData
import com.x8bit.bitwarden.ui.platform.feature.search.model.AutofillSelectionOption
import com.x8bit.bitwarden.ui.platform.feature.search.sortAlphabetically
import com.x8bit.bitwarden.ui.platform.util.toFormattedPattern
import com.x8bit.bitwarden.ui.tools.feature.send.util.toLabelIcons
import com.x8bit.bitwarden.ui.tools.feature.send.util.toOverflowActions
Expand Down Expand Up @@ -159,7 +160,7 @@ fun List<CipherView>.toViewState(
isIconLoadingDisabled = isIconLoadingDisabled,
isAutofill = isAutofill,
isPremiumUser = isPremiumUser,
),
).sortAlphabetically(),
)
}

Expand Down Expand Up @@ -314,7 +315,7 @@ fun List<SendView>.toViewState(
displayItems = toDisplayItemList(
baseWebSendUrl = baseWebSendUrl,
clock = clock,
),
).sortAlphabetically(),
)
}

Expand All @@ -334,7 +335,7 @@ private fun List<SendView>.toDisplayItemList(
baseWebSendUrl = baseWebSendUrl,
clock = clock,
)
}
}.sortAlphabetically()
david-livefront marked this conversation as resolved.
Show resolved Hide resolved

private fun SendView.toDisplayItem(
baseWebSendUrl: String,
Expand Down