mirror of
https://github.com/bitwarden/android.git
synced 2026-06-08 08:06:32 -05:00
BIT-406: Allow item listing screen to display Collections data (#394)
This commit is contained in:
committed by
Álison Fernandes
parent
41a0817c5a
commit
9a05b7168e
@@ -11,6 +11,7 @@ import com.x8bit.bitwarden.ui.platform.theme.TransitionProviders
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultItemListingType
|
||||
|
||||
private const val CARD: String = "card"
|
||||
private const val COLLECTION: String = "collection"
|
||||
private const val FOLDER: String = "folder"
|
||||
private const val IDENTITY: String = "identity"
|
||||
private const val LOGIN: String = "login"
|
||||
@@ -92,6 +93,7 @@ fun NavController.navigateToVaultItemListing(
|
||||
private fun VaultItemListingType.toTypeString(): String {
|
||||
return when (this) {
|
||||
is VaultItemListingType.Card -> CARD
|
||||
is VaultItemListingType.Collection -> COLLECTION
|
||||
is VaultItemListingType.Folder -> FOLDER
|
||||
is VaultItemListingType.Identity -> IDENTITY
|
||||
is VaultItemListingType.Login -> LOGIN
|
||||
@@ -102,6 +104,7 @@ private fun VaultItemListingType.toTypeString(): String {
|
||||
|
||||
private fun VaultItemListingType.toIdOrNull(): String? =
|
||||
when (this) {
|
||||
is VaultItemListingType.Collection -> collectionId
|
||||
is VaultItemListingType.Folder -> folderId
|
||||
is VaultItemListingType.Card -> null
|
||||
is VaultItemListingType.Identity -> null
|
||||
@@ -121,6 +124,7 @@ private fun determineVaultItemListingType(
|
||||
SECURE_NOTE -> VaultItemListingType.SecureNote
|
||||
TRASH -> VaultItemListingType.Trash
|
||||
FOLDER -> VaultItemListingType.Folder(folderId = id)
|
||||
COLLECTION -> VaultItemListingType.Collection(collectionId = requireNotNull(id))
|
||||
// This should never occur, vaultItemListingTypeString must match
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
|
||||
@@ -151,6 +151,8 @@ class VaultItemListingViewModel @Inject constructor(
|
||||
.updateWithAdditionalDataIfNecessary(
|
||||
folderList = vaultData
|
||||
.folderViewList,
|
||||
collectionList = vaultData
|
||||
.collectionViewList,
|
||||
),
|
||||
viewState = vaultData
|
||||
.cipherViewList
|
||||
@@ -305,6 +307,23 @@ data class VaultItemListingState(
|
||||
override val hasFab: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
/**
|
||||
* A Collection item listing.
|
||||
*
|
||||
* @property collectionId the ID of the collection.
|
||||
* @property collectionName the name of the collection.
|
||||
*/
|
||||
data class Collection(
|
||||
val collectionId: String,
|
||||
// The collectionName will always initially be an empty string
|
||||
val collectionName: String = "",
|
||||
) : ItemListingType() {
|
||||
override val titleText: Text
|
||||
get() = collectionName.asText()
|
||||
override val hasFab: Boolean
|
||||
get() = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.x8bit.bitwarden.ui.vault.feature.itemlisting.util
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.bitwarden.core.CipherType
|
||||
import com.bitwarden.core.CipherView
|
||||
import com.bitwarden.core.CollectionView
|
||||
import com.bitwarden.core.FolderView
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.VaultItemListingState
|
||||
@@ -19,6 +20,10 @@ fun CipherView.determineListingPredicate(
|
||||
type == CipherType.CARD && deletedDate == null
|
||||
}
|
||||
|
||||
is VaultItemListingState.ItemListingType.Collection -> {
|
||||
itemListingType.collectionId in this.collectionIds && deletedDate == null
|
||||
}
|
||||
|
||||
is VaultItemListingState.ItemListingType.Folder -> {
|
||||
folderId == itemListingType.folderId && deletedDate == null
|
||||
}
|
||||
@@ -53,9 +58,17 @@ fun List<CipherView>.toViewState(): VaultItemListingState.ViewState =
|
||||
/** * Updates a [VaultItemListingState.ItemListingType] with the given data if necessary. */
|
||||
fun VaultItemListingState.ItemListingType.updateWithAdditionalDataIfNecessary(
|
||||
folderList: List<FolderView>,
|
||||
collectionList: List<CollectionView>,
|
||||
): VaultItemListingState.ItemListingType =
|
||||
when (this) {
|
||||
is VaultItemListingState.ItemListingType.Card -> this
|
||||
is VaultItemListingState.ItemListingType.Collection -> copy(
|
||||
collectionName = collectionList
|
||||
.find { it.id == collectionId }
|
||||
?.name
|
||||
.orEmpty(),
|
||||
)
|
||||
|
||||
is VaultItemListingState.ItemListingType.Folder -> copy(
|
||||
folderName = folderList
|
||||
.find { it.id == folderId }
|
||||
|
||||
@@ -17,4 +17,7 @@ fun VaultItemListingType.toItemListingType(): VaultItemListingState.ItemListingT
|
||||
is VaultItemListingType.Login -> VaultItemListingState.ItemListingType.Login
|
||||
is VaultItemListingType.SecureNote -> VaultItemListingState.ItemListingType.SecureNote
|
||||
is VaultItemListingType.Trash -> VaultItemListingState.ItemListingType.Trash
|
||||
is VaultItemListingType.Collection -> {
|
||||
VaultItemListingState.ItemListingType.Collection(collectionId = collectionId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,9 +123,10 @@ class VaultViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleCollectionItemClick(action: VaultAction.CollectionClick) {
|
||||
// TODO: Navigate to the listing screen for collections (BIT-406).
|
||||
sendEvent(
|
||||
VaultEvent.ShowToast(message = "Not yet implemented."),
|
||||
VaultEvent.NavigateToItemListing(
|
||||
VaultItemListingType.Collection(action.collectionItem.id),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,4 +36,11 @@ sealed class VaultItemListingType {
|
||||
* @param folderId the id of the folder, a null value indicates a, "no folder" grouping.
|
||||
*/
|
||||
data class Folder(val folderId: String?) : VaultItemListingType()
|
||||
|
||||
/**
|
||||
* A Collection listing.
|
||||
*
|
||||
* @param collectionId the ID of the collection.
|
||||
*/
|
||||
data class Collection(val collectionId: String) : VaultItemListingType()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user