Removing non necessary session id arg from ViewAction

This commit is contained in:
Maxime NATUREL 2022-09-19 09:44:46 +02:00
parent e0c4706cf9
commit cf6b8d76a8
4 changed files with 14 additions and 14 deletions

View File

@ -19,5 +19,5 @@ package im.vector.app.features.settings.devices.v2.overview
import im.vector.app.core.platform.VectorViewModelAction
sealed class SessionOverviewAction : VectorViewModelAction {
data class VerifySession(val deviceId: String) : SessionOverviewAction()
object VerifySession : SessionOverviewAction()
}

View File

@ -62,8 +62,9 @@ class SessionOverviewFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initSessionInfoView()
observeViewEvents()
initSessionInfoView()
initVerifyButton()
}
private fun initSessionInfoView() {
@ -72,6 +73,12 @@ class SessionOverviewFragment :
}
}
private fun initVerifyButton() {
views.sessionOverviewInfo.viewVerifyButton.debouncedClicks {
viewModel.handle(SessionOverviewAction.VerifySession)
}
}
private fun observeViewEvents() {
viewModel.observeViewEvents {
when (it) {
@ -96,7 +103,6 @@ class SessionOverviewFragment :
override fun invalidate() = withState(viewModel) { state ->
updateToolbar(state.isCurrentSession)
updateVerifyButton(state.deviceId)
updateEntryDetails(state.deviceId)
if (state.deviceInfo is Success) {
renderSessionInfo(state.isCurrentSession, state.deviceInfo.invoke())
@ -112,12 +118,6 @@ class SessionOverviewFragment :
?.setTitle(titleResId)
}
private fun updateVerifyButton(deviceId: String) {
views.sessionOverviewInfo.viewVerifyButton.debouncedClicks {
viewModel.handle(SessionOverviewAction.VerifySession(deviceId))
}
}
private fun updateEntryDetails(deviceId: String) {
views.sessionOverviewEntryDetails.setOnClickListener {
viewNavigator.navigateToSessionDetails(requireContext(), deviceId)

View File

@ -63,12 +63,12 @@ class SessionOverviewViewModel @AssistedInject constructor(
override fun handle(action: SessionOverviewAction) {
when (action) {
is SessionOverviewAction.VerifySession -> handleVerifySessionAction(action)
is SessionOverviewAction.VerifySession -> handleVerifySessionAction()
}
}
private fun handleVerifySessionAction(verifySession: SessionOverviewAction.VerifySession) {
if (isCurrentSession(verifySession.deviceId)) {
private fun handleVerifySessionAction() = withState { viewState ->
if (isCurrentSession(viewState.deviceId)) {
handleVerifyCurrentSession()
}
}

View File

@ -85,7 +85,7 @@ class SessionOverviewViewModelTest {
val deviceFullInfo = mockk<DeviceFullInfo>()
every { getDeviceFullInfoUseCase.execute(A_SESSION_ID) } returns flowOf(deviceFullInfo)
every { isCurrentSessionUseCase.execute(any()) } returns true
val verifySessionAction = SessionOverviewAction.VerifySession(A_SESSION_ID)
val verifySessionAction = SessionOverviewAction.VerifySession
coEvery { checkIfCurrentSessionCanBeVerifiedUseCase.execute() } returns true
// When
@ -108,7 +108,7 @@ class SessionOverviewViewModelTest {
val deviceFullInfo = mockk<DeviceFullInfo>()
every { getDeviceFullInfoUseCase.execute(A_SESSION_ID) } returns flowOf(deviceFullInfo)
every { isCurrentSessionUseCase.execute(any()) } returns true
val verifySessionAction = SessionOverviewAction.VerifySession(A_SESSION_ID)
val verifySessionAction = SessionOverviewAction.VerifySession
coEvery { checkIfCurrentSessionCanBeVerifiedUseCase.execute() } returns false
// When