Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -4,7 +4,6 @@ import android.os.Parcelable
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.bitwarden.annotation.OmitFromCoverage
import com.bitwarden.core.data.manager.model.FlagKey
import com.bitwarden.core.data.repository.model.DataState
import com.bitwarden.data.repository.util.baseIconUrl
import com.bitwarden.data.repository.util.baseWebSendUrl
Expand All @@ -30,7 +29,6 @@ import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilitySele
import com.x8bit.bitwarden.data.autofill.manager.AutofillSelectionManager
import com.x8bit.bitwarden.data.autofill.model.AutofillSelectionData
import com.x8bit.bitwarden.data.autofill.util.login
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
Expand Down Expand Up @@ -104,7 +102,6 @@ class SearchViewModel @Inject constructor(
settingsRepo: SettingsRepository,
snackbarRelayManager: SnackbarRelayManager<SnackbarRelay>,
specialCircumstanceManager: SpecialCircumstanceManager,
featureFlagManager: FeatureFlagManager,
) : BaseViewModel<SearchState, SearchEvent, SearchAction>(
// We load the state from the savedStateHandle for testing purposes.
initialState = savedStateHandle[KEY_STATE]
Expand Down Expand Up @@ -140,7 +137,6 @@ class SearchViewModel @Inject constructor(
hasMasterPassword = userState.activeAccount.hasMasterPassword,
isPremium = userState.activeAccount.isPremium,
restrictItemTypesPolicyOrgIds = persistentListOf(),
isArchiveEnabled = featureFlagManager.getFeatureFlag(FlagKey.ArchiveItems),
)
},
) {
Expand Down Expand Up @@ -180,12 +176,6 @@ class SearchViewModel @Inject constructor(
.map { SearchAction.Internal.SnackbarDataReceived(it) }
.onEach(::sendAction)
.launchIn(viewModelScope)

featureFlagManager
.getFeatureFlagFlow(FlagKey.ArchiveItems)
.map { SearchAction.Internal.ArchiveItemsFlagUpdateReceive(it) }
.onEach(::sendAction)
.launchIn(viewModelScope)
}

override fun handleAction(action: SearchAction) {
Expand Down Expand Up @@ -640,10 +630,6 @@ class SearchViewModel @Inject constructor(
handleDecryptCipherErrorReceive(action)
}

is SearchAction.Internal.ArchiveItemsFlagUpdateReceive -> {
handleArchiveItemsFlagUpdateReceive(action)
}

is SearchAction.Internal.ArchiveCipherReceive -> handleArchiveCipherReceive(action)
is SearchAction.Internal.UnarchiveCipherReceive -> handleUnarchiveCipherReceive(action)
}
Expand All @@ -663,12 +649,6 @@ class SearchViewModel @Inject constructor(
}
}

private fun handleArchiveItemsFlagUpdateReceive(
action: SearchAction.Internal.ArchiveItemsFlagUpdateReceive,
) {
mutableStateFlow.update { it.copy(isArchiveEnabled = action.isEnabled) }
}

private fun handleArchiveCipherReceive(action: SearchAction.Internal.ArchiveCipherReceive) {
when (val result = action.result) {
is ArchiveCipherResult.Error -> {
Expand Down Expand Up @@ -1017,7 +997,6 @@ class SearchViewModel @Inject constructor(
isIconLoadingDisabled = state.isIconLoadingDisabled,
isAutofill = state.isAutofill,
isPremiumUser = state.isPremium,
isArchiveEnabled = state.isArchiveEnabled,
)
}

Expand Down Expand Up @@ -1084,7 +1063,6 @@ data class SearchState(
val hasMasterPassword: Boolean,
val isPremium: Boolean,
val restrictItemTypesPolicyOrgIds: ImmutableList<String>,
val isArchiveEnabled: Boolean,
) : Parcelable {

/**
Expand Down Expand Up @@ -1537,13 +1515,6 @@ sealed class SearchAction {
data class DecryptCipherErrorReceive(
val error: Throwable?,
) : Internal()

/**
* Indicates that the Archive Items flag has been updated.
*/
data class ArchiveItemsFlagUpdateReceive(
val isEnabled: Boolean,
) : Internal()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ fun List<CipherListView>.toViewState(
isIconLoadingDisabled: Boolean,
isAutofill: Boolean,
isPremiumUser: Boolean,
isArchiveEnabled: Boolean,
): SearchState.ViewState =
when {
searchTerm.isEmpty() -> SearchState.ViewState.Empty(message = null)
Expand All @@ -176,7 +175,6 @@ fun List<CipherListView>.toViewState(
isIconLoadingDisabled = isIconLoadingDisabled,
isAutofill = isAutofill,
isPremiumUser = isPremiumUser,
isArchiveEnabled = isArchiveEnabled,
),
)
}
Expand All @@ -188,14 +186,12 @@ fun List<CipherListView>.toViewState(
}
}

@Suppress("LongParameterList")
private fun List<CipherListView>.toDisplayItemList(
baseIconUrl: String,
hasMasterPassword: Boolean,
isIconLoadingDisabled: Boolean,
isAutofill: Boolean,
isPremiumUser: Boolean,
isArchiveEnabled: Boolean,
): ImmutableList<SearchState.DisplayItem> =
this
.map {
Expand All @@ -205,20 +201,17 @@ private fun List<CipherListView>.toDisplayItemList(
isIconLoadingDisabled = isIconLoadingDisabled,
isAutofill = isAutofill,
isPremiumUser = isPremiumUser,
isArchiveEnabled = isArchiveEnabled,
)
}
.sortAlphabetically()
.toImmutableList()

@Suppress("LongParameterList")
private fun CipherListView.toDisplayItem(
baseIconUrl: String,
hasMasterPassword: Boolean,
isIconLoadingDisabled: Boolean,
isAutofill: Boolean,
isPremiumUser: Boolean,
isArchiveEnabled: Boolean,
): SearchState.DisplayItem =
SearchState.DisplayItem(
id = id.orEmpty(),
Expand All @@ -234,7 +227,6 @@ private fun CipherListView.toDisplayItem(
overflowOptions = toOverflowActions(
hasMasterPassword = hasMasterPassword,
isPremiumUser = isPremiumUser,
isArchiveEnabled = isArchiveEnabled,
),
overflowTestTag = "CipherOptionsButton",
totpCode = login?.totp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.credentials.CreatePublicKeyCredentialRequest
import androidx.credentials.provider.CallingAppInfo
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.bitwarden.core.data.manager.model.FlagKey
import com.bitwarden.core.data.manager.toast.ToastManager
import com.bitwarden.core.data.repository.model.DataState
import com.bitwarden.core.data.repository.util.takeUntilLoaded
Expand Down Expand Up @@ -34,7 +33,6 @@ import com.x8bit.bitwarden.data.credentials.manager.BitwardenCredentialManager
import com.x8bit.bitwarden.data.credentials.model.CreateCredentialRequest
import com.x8bit.bitwarden.data.credentials.model.Fido2RegisterCredentialResult
import com.x8bit.bitwarden.data.credentials.model.UserVerificationRequirement
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.FirstTimeActionManager
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager
Expand Down Expand Up @@ -119,7 +117,6 @@ private const val KEY_STATE = "state"
@Suppress("TooManyFunctions", "LargeClass", "LongParameterList", "LongMethod")
class VaultAddEditViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
featureFlagManager: FeatureFlagManager,
generatorRepository: GeneratorRepository,
private val snackbarRelayManager: SnackbarRelayManager<SnackbarRelay>,
private val toastManager: ToastManager,
Expand Down Expand Up @@ -177,7 +174,6 @@ class VaultAddEditViewModel @Inject constructor(
}

VaultAddEditState(
isArchiveEnabled = featureFlagManager.getFeatureFlag(FlagKey.ArchiveItems),
vaultAddEditType = vaultAddEditType,
cipherType = vaultCipherType,
viewState = when (vaultAddEditType) {
Expand Down Expand Up @@ -273,12 +269,6 @@ class VaultAddEditViewModel @Inject constructor(
.onEach(::sendAction)
.launchIn(viewModelScope)

featureFlagManager
.getFeatureFlagFlow(FlagKey.ArchiveItems)
.map { VaultAddEditAction.Internal.ArchiveItemsFlagUpdateReceive(it) }
.onEach(::sendAction)
.launchIn(viewModelScope)

snackbarRelayManager
.getSnackbarDataFlow(SnackbarRelay.CIPHER_MOVED_TO_ORGANIZATION)
.map { VaultAddEditAction.Internal.SnackbarDataReceived(it) }
Expand Down Expand Up @@ -1649,10 +1639,6 @@ class VaultAddEditViewModel @Inject constructor(
handleUnarchiveCipherReceive(action)
}

is VaultAddEditAction.Internal.ArchiveItemsFlagUpdateReceive -> {
handleArchiveItemsFlagUpdateReceive(action)
}

is VaultAddEditAction.Internal.DeleteCipherReceive -> handleDeleteCipherReceive(action)
is VaultAddEditAction.Internal.TotpCodeReceive -> handleVaultTotpCodeReceive(action)
is VaultAddEditAction.Internal.VaultDataReceive -> handleVaultDataReceive(action)
Expand Down Expand Up @@ -1864,12 +1850,6 @@ class VaultAddEditViewModel @Inject constructor(
}
}

private fun handleArchiveItemsFlagUpdateReceive(
action: VaultAddEditAction.Internal.ArchiveItemsFlagUpdateReceive,
) {
mutableStateFlow.update { it.copy(isArchiveEnabled = action.isEnabled) }
}

private fun handleDeleteCipherReceive(action: VaultAddEditAction.Internal.DeleteCipherReceive) {
when (val result = action.result) {
is DeleteCipherResult.Error -> {
Expand Down Expand Up @@ -2427,7 +2407,6 @@ data class VaultAddEditState(
val createCredentialRequest: CreateCredentialRequest? = null,
val defaultUriMatchType: UriMatchType,
private val shouldShowCoachMarkTour: Boolean,
private val isArchiveEnabled: Boolean,
) : Parcelable {

/**
Expand Down Expand Up @@ -2484,8 +2463,7 @@ data class VaultAddEditState(
* Helper to determine if the UI should display the archive button.
*/
val displayArchiveButton: Boolean
get() = isArchiveEnabled &&
isEditItemMode &&
get() = isEditItemMode &&
(viewState as? ViewState.Content)
?.common
?.originalCipher
Expand All @@ -2495,8 +2473,7 @@ data class VaultAddEditState(
* Helper to determine if the UI should display the unarchive button.
*/
val displayUnarchiveButton: Boolean
get() = isArchiveEnabled &&
isEditItemMode &&
get() = isEditItemMode &&
(viewState as? ViewState.Content)
?.common
?.originalCipher
Expand Down Expand Up @@ -3834,12 +3811,5 @@ sealed class VaultAddEditAction {
data class AvailableFoldersReceive(
val folderData: DataState<List<FolderView>>,
) : Internal()

/**
* Indicates that the Archive Items flag has been updated.
*/
data class ArchiveItemsFlagUpdateReceive(
val isEnabled: Boolean,
) : Internal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.net.Uri
import android.os.Parcelable
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.bitwarden.core.data.manager.model.FlagKey
import com.bitwarden.core.data.repository.model.DataState
import com.bitwarden.core.data.repository.util.combineDataStates
import com.bitwarden.core.data.repository.util.mapNullable
Expand All @@ -27,7 +26,6 @@ import com.bitwarden.vault.CipherView
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.BreachCountResult
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
import com.x8bit.bitwarden.data.platform.manager.event.OrganizationEventManager
import com.x8bit.bitwarden.data.platform.manager.model.OrganizationEvent
Expand Down Expand Up @@ -82,7 +80,6 @@ class VaultItemViewModel @Inject constructor(
private val environmentRepository: EnvironmentRepository,
private val settingsRepository: SettingsRepository,
private val snackbarRelayManager: SnackbarRelayManager<SnackbarRelay>,
featureFlagManager: FeatureFlagManager,
) : BaseViewModel<VaultItemState, VaultItemEvent, VaultItemAction>(
// We load the state from the savedStateHandle for testing purposes.
initialState = savedStateHandle[KEY_STATE] ?: run {
Expand All @@ -95,7 +92,6 @@ class VaultItemViewModel @Inject constructor(
baseIconUrl = environmentRepository.environment.environmentUrlData.baseIconUrl,
isIconLoadingDisabled = settingsRepository.isIconLoadingDisabled,
hasPremium = authRepository.userStateFlow.value?.activeAccount?.isPremium == true,
isArchiveEnabled = featureFlagManager.getFeatureFlag(FlagKey.ArchiveItems),
)
},
) {
Expand Down Expand Up @@ -232,12 +228,6 @@ class VaultItemViewModel @Inject constructor(
.map { VaultItemAction.Internal.SnackbarDataReceived(it) }
.onEach(::sendAction)
.launchIn(viewModelScope)

featureFlagManager
.getFeatureFlagFlow(FlagKey.ArchiveItems)
.map { VaultItemAction.Internal.ArchiveItemsFlagUpdateReceive(it) }
.onEach(::sendAction)
.launchIn(viewModelScope)
}

override fun handleAction(action: VaultItemAction) {
Expand Down Expand Up @@ -1063,10 +1053,6 @@ class VaultItemViewModel @Inject constructor(
handleIsIconLoadingDisabledUpdateReceive(action)
}

is VaultItemAction.Internal.ArchiveItemsFlagUpdateReceive -> {
handleArchiveItemsFlagUpdateReceive(action)
}

is VaultItemAction.Internal.ArchiveCipherReceive -> handleArchiveCipherReceive(action)
is VaultItemAction.Internal.UnarchiveCipherReceive -> {
handleUnarchiveCipherReceive(action)
Expand Down Expand Up @@ -1302,12 +1288,6 @@ class VaultItemViewModel @Inject constructor(
mutableStateFlow.update { it.copy(isIconLoadingDisabled = action.isDisabled) }
}

private fun handleArchiveItemsFlagUpdateReceive(
action: VaultItemAction.Internal.ArchiveItemsFlagUpdateReceive,
) {
mutableStateFlow.update { it.copy(isArchiveEnabled = action.isEnabled) }
}

private fun handleArchiveCipherReceive(action: VaultItemAction.Internal.ArchiveCipherReceive) {
when (val result = action.result) {
is ArchiveCipherResult.Error -> {
Expand Down Expand Up @@ -1446,7 +1426,6 @@ data class VaultItemState(
val dialog: DialogState?,
val baseIconUrl: String,
val isIconLoadingDisabled: Boolean,
val isArchiveEnabled: Boolean,
val hasPremium: Boolean,
) : Parcelable {

Expand Down Expand Up @@ -1513,21 +1492,19 @@ data class VaultItemState(
* Helper to determine if the UI should display the archive button.
*/
val displayArchiveButton: Boolean
get() = isArchiveEnabled &&
viewState.asContentOrNull()
?.common
?.currentCipher
?.isActive == true
get() = viewState.asContentOrNull()
?.common
?.currentCipher
?.isActive == true

/**
* Helper to determine if the UI should display the unarchive button.
*/
val displayUnarchiveButton: Boolean
get() = isArchiveEnabled &&
viewState.asContentOrNull()
?.common
?.currentCipher
?.let { it.archivedDate != null && it.deletedDate == null } == true
get() = viewState.asContentOrNull()
?.common
?.currentCipher
?.let { it.archivedDate != null && it.deletedDate == null } == true

val canAssignToCollections: Boolean
get() = viewState.asContentOrNull()
Expand Down Expand Up @@ -2372,13 +2349,6 @@ sealed class VaultItemAction {
val data: BitwardenSnackbarData,
) : Internal()

/**
* Indicates that the Archive Items flag has been updated.
*/
data class ArchiveItemsFlagUpdateReceive(
val isEnabled: Boolean,
) : Internal()

/**
* Indicates that the archive cipher result has been received.
*/
Expand Down
Loading
Loading