Implement try again button action.

This commit is contained in:
Onuray Sahin 2022-10-17 18:32:35 +03:00
parent 552fb9de9a
commit b2dc0b33b5
6 changed files with 41 additions and 18 deletions

View file

@ -20,6 +20,7 @@ import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.extensions.orTrue
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
import org.matrix.android.sdk.internal.auth.version.Versions

View file

@ -22,4 +22,5 @@ sealed class QrCodeLoginAction : VectorViewModelAction {
data class OnQrCodeScanned(val qrCode: String) : QrCodeLoginAction()
object GenerateQrCode : QrCodeLoginAction()
object ShowQrCode : QrCodeLoginAction()
object TryAgain : QrCodeLoginAction()
}

View file

@ -38,30 +38,33 @@ class QrCodeLoginActivity : SimpleFragmentActivity() {
super.onCreate(savedInstanceState)
views.toolbar.visibility = View.GONE
val qrCodeLoginArgs: QrCodeLoginArgs? = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG)
if (isFirstCreation()) {
when (qrCodeLoginArgs?.loginType) {
QrCodeLoginType.LOGIN -> {
showInstructionsFragment(qrCodeLoginArgs)
}
QrCodeLoginType.LINK_A_DEVICE -> {
if (qrCodeLoginArgs.showQrCodeImmediately) {
handleNavigateToShowQrCodeScreen()
} else {
showInstructionsFragment(qrCodeLoginArgs)
}
}
null -> {
Timber.i("QrCodeLoginArgs is null. This is not expected.")
finish()
return
}
}
navigateToInitialFragment()
}
observeViewEvents()
}
private fun navigateToInitialFragment() {
val qrCodeLoginArgs: QrCodeLoginArgs? = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG)
when (qrCodeLoginArgs?.loginType) {
QrCodeLoginType.LOGIN -> {
showInstructionsFragment(qrCodeLoginArgs)
}
QrCodeLoginType.LINK_A_DEVICE -> {
if (qrCodeLoginArgs.showQrCodeImmediately) {
handleNavigateToShowQrCodeScreen()
} else {
showInstructionsFragment(qrCodeLoginArgs)
}
}
null -> {
Timber.i("QrCodeLoginArgs is null. This is not expected.")
finish()
}
}
}
private fun showInstructionsFragment(qrCodeLoginArgs: QrCodeLoginArgs) {
addFragment(
views.container,
@ -77,10 +80,15 @@ class QrCodeLoginActivity : SimpleFragmentActivity() {
QrCodeLoginViewEvents.NavigateToStatusScreen -> handleNavigateToStatusScreen()
QrCodeLoginViewEvents.NavigateToShowQrCodeScreen -> handleNavigateToShowQrCodeScreen()
QrCodeLoginViewEvents.NavigateToHomeScreen -> handleNavigateToHomeScreen()
QrCodeLoginViewEvents.NavigateToInitialScreen -> handleNavigateToInitialScreen()
}
}
}
private fun handleNavigateToInitialScreen() {
navigateToInitialFragment()
}
private fun handleNavigateToShowQrCodeScreen() {
addFragment(
views.container,

View file

@ -42,6 +42,13 @@ class QrCodeLoginStatusFragment : VectorBaseFragment<FragmentQrCodeLoginStatusBi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initCancelButton()
initTryAgainButton()
}
private fun initTryAgainButton() {
views.qrCodeLoginStatusTryAgainButton.debouncedClicks {
viewModel.handle(QrCodeLoginAction.TryAgain)
}
}
private fun initCancelButton() {

View file

@ -22,4 +22,5 @@ sealed class QrCodeLoginViewEvents : VectorViewEvents {
object NavigateToStatusScreen : QrCodeLoginViewEvents()
object NavigateToShowQrCodeScreen : QrCodeLoginViewEvents()
object NavigateToHomeScreen : QrCodeLoginViewEvents()
object NavigateToInitialScreen : QrCodeLoginViewEvents()
}

View file

@ -54,9 +54,14 @@ class QrCodeLoginViewModel @AssistedInject constructor(
is QrCodeLoginAction.OnQrCodeScanned -> handleOnQrCodeScanned(action)
QrCodeLoginAction.GenerateQrCode -> handleQrCodeViewStarted()
QrCodeLoginAction.ShowQrCode -> handleShowQrCode()
QrCodeLoginAction.TryAgain -> handleTryAgain()
}
}
private fun handleTryAgain() {
_viewEvents.post(QrCodeLoginViewEvents.NavigateToInitialScreen)
}
private fun handleShowQrCode() {
_viewEvents.post(QrCodeLoginViewEvents.NavigateToShowQrCodeScreen)
}