diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt index 0e923b4c9b..1118c5dc5b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt @@ -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() } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt index 98f4eb823b..4c83408fe7 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt @@ -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) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index 5b51483afe..bcf7542783 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -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() } } diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt index f25c25bb8e..71978129d3 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt @@ -85,7 +85,7 @@ class SessionOverviewViewModelTest { val deviceFullInfo = mockk() 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() 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