mirror of
https://github.com/bitwarden/android.git
synced 2026-10-23 11:33:22 -05:00
Refactor MigrateToMyItemsViewModel dependencies and sync logic
Objective: Remove unused dependencies and simplify the vault sync invocation during ViewModel initialization. Behavioral changes: The vault sync is now triggered using `sync` instead of `syncForResult` and is no longer wrapped in a `viewModelScope` coroutine, simplifying the initialization flow. Specific changes: - Modify `MigrateToMyItemsViewModel` to remove the unused `VaultMigrationManager` dependency. - Update `MigrateToMyItemsViewModel` constructor to accept `VaultSyncManager` as a parameter rather than a property. - Update the `init` block in `MigrateToMyItemsViewModel` to call `vaultSyncManager.sync(forced = true)` directly without a coroutine wrapper. - Update `MigrateToMyItemsViewModelTest` to remove the mock and constructor usage of `VaultMigrationManager`.
This commit is contained in:
2 files changed
+4
-11
No files matched your search
+4
-8
@@ -9,7 +9,6 @@ import com.bitwarden.ui.util.Text
|
||||
import com.bitwarden.ui.util.asText
|
||||
import com.x8bit.bitwarden.data.platform.manager.event.OrganizationEventManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.OrganizationEvent
|
||||
import com.x8bit.bitwarden.data.vault.manager.VaultMigrationManager
|
||||
import com.x8bit.bitwarden.data.vault.manager.VaultSyncManager
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -28,8 +27,7 @@ private const val KEY_STATE = "state"
|
||||
@HiltViewModel
|
||||
class MigrateToMyItemsViewModel @Inject constructor(
|
||||
private val organizationEventManager: OrganizationEventManager,
|
||||
val vaultMigrationManager: VaultMigrationManager,
|
||||
val vaultSyncManager: VaultSyncManager,
|
||||
vaultSyncManager: VaultSyncManager,
|
||||
savedStateHandle: SavedStateHandle,
|
||||
) : BaseViewModel<MigrateToMyItemsState, MigrateToMyItemsEvent, MigrateToMyItemsAction>(
|
||||
initialState = savedStateHandle[KEY_STATE] ?: run {
|
||||
@@ -46,11 +44,9 @@ class MigrateToMyItemsViewModel @Inject constructor(
|
||||
stateFlow
|
||||
.onEach { savedStateHandle[KEY_STATE] = it }
|
||||
.launchIn(viewModelScope)
|
||||
viewModelScope.launch {
|
||||
// We need to ensure we have the most recent data. No need to do anything
|
||||
// RootNavViewModel will take care of navigating if needed
|
||||
vaultSyncManager.syncForResult(forced = true)
|
||||
}
|
||||
// We need to ensure we have the most recent data. No need to do anything
|
||||
// RootNavViewModel will take care of navigating if needed
|
||||
vaultSyncManager.sync(forced = true)
|
||||
}
|
||||
|
||||
override fun handleAction(action: MigrateToMyItemsAction) {
|
||||
|
||||
-3
@@ -7,7 +7,6 @@ import com.bitwarden.ui.platform.resource.BitwardenString
|
||||
import com.bitwarden.ui.util.asText
|
||||
import com.x8bit.bitwarden.data.platform.manager.event.OrganizationEventManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.OrganizationEvent
|
||||
import com.x8bit.bitwarden.data.vault.manager.VaultMigrationManager
|
||||
import com.x8bit.bitwarden.data.vault.manager.VaultSyncManager
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
@@ -28,7 +27,6 @@ class MigrateToMyItemsViewModelTest : BaseViewModelTest() {
|
||||
private val mockOrganizationEventManager: OrganizationEventManager = mockk {
|
||||
every { trackEvent(any()) } just runs
|
||||
}
|
||||
private val mockVaultMigrationManager: VaultMigrationManager = mockk(relaxed = true)
|
||||
private val mockVaultSyncManager: VaultSyncManager = mockk(relaxed = true)
|
||||
|
||||
@BeforeEach
|
||||
@@ -180,7 +178,6 @@ class MigrateToMyItemsViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
return MigrateToMyItemsViewModel(
|
||||
organizationEventManager = mockOrganizationEventManager,
|
||||
vaultMigrationManager = mockVaultMigrationManager,
|
||||
vaultSyncManager = mockVaultSyncManager,
|
||||
savedStateHandle = savedStateHandle,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user