mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 20:07:59 -06:00
[PM-25327] Display default user collections first (#5810)
This commit is contained in:
parent
659bbc5169
commit
e1434dfe21
@ -82,6 +82,7 @@ import com.x8bit.bitwarden.data.vault.repository.model.UpdateSendResult
|
|||||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult
|
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult
|
||||||
import com.x8bit.bitwarden.data.vault.repository.util.sortAlphabetically
|
import com.x8bit.bitwarden.data.vault.repository.util.sortAlphabetically
|
||||||
|
import com.x8bit.bitwarden.data.vault.repository.util.sortAlphabeticallyByType
|
||||||
import com.x8bit.bitwarden.data.vault.repository.util.toDomainsData
|
import com.x8bit.bitwarden.data.vault.repository.util.toDomainsData
|
||||||
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedNetworkFolder
|
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedNetworkFolder
|
||||||
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedNetworkSend
|
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedNetworkSend
|
||||||
@ -1167,7 +1168,7 @@ class VaultRepositoryImpl(
|
|||||||
.fold(
|
.fold(
|
||||||
onSuccess = { collections ->
|
onSuccess = { collections ->
|
||||||
DataState.Loaded(
|
DataState.Loaded(
|
||||||
collections.sortAlphabetically(),
|
collections.sortAlphabeticallyByType(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onFailure = { throwable -> DataState.Error(throwable) },
|
onFailure = { throwable -> DataState.Error(throwable) },
|
||||||
|
|||||||
@ -21,7 +21,7 @@ fun SyncResponseJson.Collection.toEncryptedSdkCollection(): Collection =
|
|||||||
readOnly = this.isReadOnly,
|
readOnly = this.isReadOnly,
|
||||||
manage = this.canManage ?: !this.isReadOnly,
|
manage = this.canManage ?: !this.isReadOnly,
|
||||||
defaultUserCollectionEmail = this.defaultUserCollectionEmail,
|
defaultUserCollectionEmail = this.defaultUserCollectionEmail,
|
||||||
type = this.type.toCollectionType(),
|
type = this.type.toSdkCollectionType(),
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,14 +32,21 @@ fun List<SyncResponseJson.Collection>.toEncryptedSdkCollectionList(): List<Colle
|
|||||||
map { it.toEncryptedSdkCollection() }
|
map { it.toEncryptedSdkCollection() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the data in alphabetical order by name.
|
* Sorts the collections, grouping them by type, with `DEFAULT_USER_COLLECTION` types displayed
|
||||||
|
* first. Within each group, collections are sorted alphabetically by name.
|
||||||
*/
|
*/
|
||||||
@JvmName("toAlphabeticallySortedCollectionList")
|
@JvmName("toAlphabeticallySortedCollectionList")
|
||||||
fun List<CollectionView>.sortAlphabetically(): List<CollectionView> {
|
fun List<CollectionView>.sortAlphabeticallyByType(): List<CollectionView> {
|
||||||
return this.sortedWith(
|
return this.sortedWith(
|
||||||
comparator = { collection1, collection2 ->
|
// DEFAULT_USER_COLLECTION come first
|
||||||
SpecialCharWithPrecedenceComparator.compare(collection1.name, collection2.name)
|
comparator = compareBy<CollectionView> { it.type != CollectionType.DEFAULT_USER_COLLECTION }
|
||||||
},
|
// Then sort by other CollectionType ordinals
|
||||||
|
.thenBy { it.type }
|
||||||
|
// Finally, sort by name within each group
|
||||||
|
.thenComparing(
|
||||||
|
CollectionView::name,
|
||||||
|
SpecialCharWithPrecedenceComparator,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +54,7 @@ fun List<CollectionView>.sortAlphabetically(): List<CollectionView> {
|
|||||||
* Converts a [CollectionType] object to a corresponding
|
* Converts a [CollectionType] object to a corresponding
|
||||||
* Bitwarden SDK [CollectionTypeJson] object.
|
* Bitwarden SDK [CollectionTypeJson] object.
|
||||||
*/
|
*/
|
||||||
fun CollectionTypeJson.toCollectionType(): CollectionType =
|
fun CollectionTypeJson.toSdkCollectionType(): CollectionType =
|
||||||
when (this) {
|
when (this) {
|
||||||
CollectionTypeJson.SHARED_COLLECTION -> CollectionType.SHARED_COLLECTION
|
CollectionTypeJson.SHARED_COLLECTION -> CollectionType.SHARED_COLLECTION
|
||||||
CollectionTypeJson.DEFAULT_USER_COLLECTION -> CollectionType.DEFAULT_USER_COLLECTION
|
CollectionTypeJson.DEFAULT_USER_COLLECTION -> CollectionType.DEFAULT_USER_COLLECTION
|
||||||
|
|||||||
@ -103,7 +103,7 @@ class VaultSdkCollectionExtensionsTest {
|
|||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
fun `toSortAlphabetically should sort collections by name`() {
|
fun `toSortAlphabetically should sort collections by type and name`() {
|
||||||
val list = listOf(
|
val list = listOf(
|
||||||
createMockCollectionView(1).copy(name = "c"),
|
createMockCollectionView(1).copy(name = "c"),
|
||||||
createMockCollectionView(1).copy(name = "B"),
|
createMockCollectionView(1).copy(name = "B"),
|
||||||
@ -111,29 +111,35 @@ class VaultSdkCollectionExtensionsTest {
|
|||||||
createMockCollectionView(1).copy(name = "4"),
|
createMockCollectionView(1).copy(name = "4"),
|
||||||
createMockCollectionView(1).copy(name = "A"),
|
createMockCollectionView(1).copy(name = "A"),
|
||||||
createMockCollectionView(1).copy(name = "#"),
|
createMockCollectionView(1).copy(name = "#"),
|
||||||
createMockCollectionView(1).copy(name = "D"),
|
createMockCollectionView(1).copy(
|
||||||
|
name = "D",
|
||||||
|
type = CollectionType.DEFAULT_USER_COLLECTION,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val expected = listOf(
|
val expected = listOf(
|
||||||
|
createMockCollectionView(1).copy(
|
||||||
|
name = "D",
|
||||||
|
type = CollectionType.DEFAULT_USER_COLLECTION,
|
||||||
|
),
|
||||||
createMockCollectionView(1).copy(name = "#"),
|
createMockCollectionView(1).copy(name = "#"),
|
||||||
createMockCollectionView(1).copy(name = "4"),
|
createMockCollectionView(1).copy(name = "4"),
|
||||||
createMockCollectionView(1).copy(name = "A"),
|
createMockCollectionView(1).copy(name = "A"),
|
||||||
createMockCollectionView(1).copy(name = "B"),
|
createMockCollectionView(1).copy(name = "B"),
|
||||||
createMockCollectionView(1).copy(name = "c"),
|
createMockCollectionView(1).copy(name = "c"),
|
||||||
createMockCollectionView(1).copy(name = "D"),
|
|
||||||
createMockCollectionView(1).copy(name = "z"),
|
createMockCollectionView(1).copy(name = "z"),
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected,
|
expected,
|
||||||
list.sortAlphabetically(),
|
list.sortAlphabeticallyByType(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `toCollectionType should convert CollectionTypeJson to CollectionType`() {
|
fun `toCollectionType should convert CollectionTypeJson to CollectionType`() {
|
||||||
val collectionType = CollectionTypeJson.SHARED_COLLECTION
|
val collectionType = CollectionTypeJson.SHARED_COLLECTION
|
||||||
val sdkCollectionType = collectionType.toCollectionType()
|
val sdkCollectionType = collectionType.toSdkCollectionType()
|
||||||
assertEquals(
|
assertEquals(
|
||||||
CollectionType.SHARED_COLLECTION,
|
CollectionType.SHARED_COLLECTION,
|
||||||
sdkCollectionType,
|
sdkCollectionType,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user