mirror of
https://github.com/bitwarden/android.git
synced 2026-03-19 05:02:48 -05:00
PM-14963: Add toast when login via device succeeds (#4351)
This commit is contained in:
@@ -61,6 +61,7 @@ fun LoginWithDeviceScreen(
|
||||
) {
|
||||
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
val resources = context.resources
|
||||
EventsEffect(viewModel = viewModel) { event ->
|
||||
when (event) {
|
||||
LoginWithDeviceEvent.NavigateBack -> onNavigateBack()
|
||||
@@ -73,7 +74,7 @@ fun LoginWithDeviceScreen(
|
||||
}
|
||||
|
||||
is LoginWithDeviceEvent.ShowToast -> {
|
||||
Toast.makeText(context, event.message, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(context, event.message(resources), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.x8bit.bitwarden.data.auth.repository.util.generateUriForCaptcha
|
||||
import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.model.LoginWithDeviceType
|
||||
import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.util.toAuthRequestType
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.BackgroundEvent
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -252,6 +253,7 @@ class LoginWithDeviceViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
is LoginResult.Success -> {
|
||||
sendEvent(LoginWithDeviceEvent.ShowToast(R.string.login_approved.asText()))
|
||||
mutableStateFlow.update { it.copy(dialogState = null) }
|
||||
}
|
||||
}
|
||||
@@ -494,8 +496,8 @@ sealed class LoginWithDeviceEvent {
|
||||
* Shows a toast with the given [message].
|
||||
*/
|
||||
data class ShowToast(
|
||||
val message: String,
|
||||
) : LoginWithDeviceEvent()
|
||||
val message: Text,
|
||||
) : LoginWithDeviceEvent(), BackgroundEvent
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -162,8 +162,8 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
} returns LoginResult.Success
|
||||
val viewModel = createViewModel()
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(DEFAULT_STATE, awaitItem())
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(DEFAULT_STATE, stateFlow.awaitItem())
|
||||
mutableCreateAuthRequestWithUpdatesFlow.tryEmit(
|
||||
CreateAuthRequestResult.Success(
|
||||
authRequest = AUTH_REQUEST,
|
||||
@@ -181,7 +181,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
message = R.string.logging_in.asText(),
|
||||
),
|
||||
),
|
||||
awaitItem(),
|
||||
stateFlow.awaitItem(),
|
||||
)
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
@@ -191,7 +191,11 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
dialogState = null,
|
||||
loginData = DEFAULT_LOGIN_DATA,
|
||||
),
|
||||
awaitItem(),
|
||||
stateFlow.awaitItem(),
|
||||
)
|
||||
assertEquals(
|
||||
LoginWithDeviceEvent.ShowToast(R.string.login_approved.asText()),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -227,8 +231,8 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
val viewModel = createViewModel(initialState)
|
||||
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(initialState, awaitItem())
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(initialState, stateFlow.awaitItem())
|
||||
mutableCreateAuthRequestWithUpdatesFlow.tryEmit(
|
||||
CreateAuthRequestResult.Success(
|
||||
authRequest = AUTH_REQUEST,
|
||||
@@ -246,7 +250,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
),
|
||||
loginData = DEFAULT_LOGIN_DATA,
|
||||
),
|
||||
awaitItem(),
|
||||
stateFlow.awaitItem(),
|
||||
)
|
||||
assertEquals(
|
||||
initialState.copy(
|
||||
@@ -256,7 +260,11 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
dialogState = null,
|
||||
loginData = DEFAULT_LOGIN_DATA,
|
||||
),
|
||||
awaitItem(),
|
||||
stateFlow.awaitItem(),
|
||||
)
|
||||
assertEquals(
|
||||
LoginWithDeviceEvent.ShowToast(R.string.login_approved.asText()),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user