mirror of
https://github.com/bitwarden/android.git
synced 2026-06-08 23:16:33 -05:00
BIT-467: Implement Lock Now functionality (#327)
This commit is contained in:
committed by
Álison Fernandes
parent
a7dc5fe08f
commit
c72053f935
@@ -53,6 +53,11 @@ interface VaultRepository {
|
||||
*/
|
||||
fun getVaultFolderStateFlow(folderId: String): StateFlow<DataState<FolderView?>>
|
||||
|
||||
/**
|
||||
* Locks the vault for the current user if currently unlocked.
|
||||
*/
|
||||
fun lockVaultForCurrentUser()
|
||||
|
||||
/**
|
||||
* Locks the vault for the user with the given [userId] if necessary.
|
||||
*/
|
||||
|
||||
@@ -159,6 +159,12 @@ class VaultRepositoryImpl constructor(
|
||||
initialValue = DataState.Loading,
|
||||
)
|
||||
|
||||
override fun lockVaultForCurrentUser() {
|
||||
authDiskSource.userState?.activeUserId?.let {
|
||||
lockVaultIfNecessary(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun lockVaultIfNecessary(userId: String) {
|
||||
setVaultToLocked(userId = userId)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
@@ -24,6 +25,7 @@ private const val KEY_STATE = "state"
|
||||
@HiltViewModel
|
||||
class AccountSecurityViewModel @Inject constructor(
|
||||
private val authRepository: AuthRepository,
|
||||
private val vaultRepository: VaultRepository,
|
||||
savedStateHandle: SavedStateHandle,
|
||||
) : BaseViewModel<AccountSecurityState, AccountSecurityEvent, AccountSecurityAction>(
|
||||
initialState = savedStateHandle[KEY_STATE]
|
||||
@@ -99,8 +101,7 @@ class AccountSecurityViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleLockNowClick() {
|
||||
// TODO BIT-467: Lock the app
|
||||
sendEvent(AccountSecurityEvent.ShowToast("Lock the app.".asText()))
|
||||
vaultRepository.lockVaultForCurrentUser()
|
||||
}
|
||||
|
||||
private fun handleLoginRequestToggle(action: AccountSecurityAction.LoginRequestToggle) {
|
||||
|
||||
Reference in New Issue
Block a user