mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Merge branch 'feature/hughns/qr_code_login' of https://github.com/vector-im/element-android into feature/hughns/qr_code_login
This commit is contained in:
commit
c3669318c1
6 changed files with 41 additions and 18 deletions
|
@ -20,6 +20,7 @@ import com.zhuinden.monarchy.Monarchy
|
||||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
|
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.extensions.orTrue
|
||||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||||
import org.matrix.android.sdk.internal.auth.version.Versions
|
import org.matrix.android.sdk.internal.auth.version.Versions
|
||||||
|
|
|
@ -22,4 +22,5 @@ sealed class QrCodeLoginAction : VectorViewModelAction {
|
||||||
data class OnQrCodeScanned(val qrCode: String) : QrCodeLoginAction()
|
data class OnQrCodeScanned(val qrCode: String) : QrCodeLoginAction()
|
||||||
object GenerateQrCode : QrCodeLoginAction()
|
object GenerateQrCode : QrCodeLoginAction()
|
||||||
object ShowQrCode : QrCodeLoginAction()
|
object ShowQrCode : QrCodeLoginAction()
|
||||||
|
object TryAgain : QrCodeLoginAction()
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,30 +38,33 @@ class QrCodeLoginActivity : SimpleFragmentActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
views.toolbar.visibility = View.GONE
|
views.toolbar.visibility = View.GONE
|
||||||
|
|
||||||
val qrCodeLoginArgs: QrCodeLoginArgs? = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG)
|
|
||||||
if (isFirstCreation()) {
|
if (isFirstCreation()) {
|
||||||
when (qrCodeLoginArgs?.loginType) {
|
navigateToInitialFragment()
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
observeViewEvents()
|
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) {
|
private fun showInstructionsFragment(qrCodeLoginArgs: QrCodeLoginArgs) {
|
||||||
addFragment(
|
addFragment(
|
||||||
views.container,
|
views.container,
|
||||||
|
@ -77,10 +80,15 @@ class QrCodeLoginActivity : SimpleFragmentActivity() {
|
||||||
QrCodeLoginViewEvents.NavigateToStatusScreen -> handleNavigateToStatusScreen()
|
QrCodeLoginViewEvents.NavigateToStatusScreen -> handleNavigateToStatusScreen()
|
||||||
QrCodeLoginViewEvents.NavigateToShowQrCodeScreen -> handleNavigateToShowQrCodeScreen()
|
QrCodeLoginViewEvents.NavigateToShowQrCodeScreen -> handleNavigateToShowQrCodeScreen()
|
||||||
QrCodeLoginViewEvents.NavigateToHomeScreen -> handleNavigateToHomeScreen()
|
QrCodeLoginViewEvents.NavigateToHomeScreen -> handleNavigateToHomeScreen()
|
||||||
|
QrCodeLoginViewEvents.NavigateToInitialScreen -> handleNavigateToInitialScreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleNavigateToInitialScreen() {
|
||||||
|
navigateToInitialFragment()
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleNavigateToShowQrCodeScreen() {
|
private fun handleNavigateToShowQrCodeScreen() {
|
||||||
addFragment(
|
addFragment(
|
||||||
views.container,
|
views.container,
|
||||||
|
|
|
@ -42,6 +42,13 @@ class QrCodeLoginStatusFragment : VectorBaseFragment<FragmentQrCodeLoginStatusBi
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
initCancelButton()
|
initCancelButton()
|
||||||
|
initTryAgainButton()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initTryAgainButton() {
|
||||||
|
views.qrCodeLoginStatusTryAgainButton.debouncedClicks {
|
||||||
|
viewModel.handle(QrCodeLoginAction.TryAgain)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initCancelButton() {
|
private fun initCancelButton() {
|
||||||
|
|
|
@ -22,4 +22,5 @@ sealed class QrCodeLoginViewEvents : VectorViewEvents {
|
||||||
object NavigateToStatusScreen : QrCodeLoginViewEvents()
|
object NavigateToStatusScreen : QrCodeLoginViewEvents()
|
||||||
object NavigateToShowQrCodeScreen : QrCodeLoginViewEvents()
|
object NavigateToShowQrCodeScreen : QrCodeLoginViewEvents()
|
||||||
object NavigateToHomeScreen : QrCodeLoginViewEvents()
|
object NavigateToHomeScreen : QrCodeLoginViewEvents()
|
||||||
|
object NavigateToInitialScreen : QrCodeLoginViewEvents()
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,14 @@ class QrCodeLoginViewModel @AssistedInject constructor(
|
||||||
is QrCodeLoginAction.OnQrCodeScanned -> handleOnQrCodeScanned(action)
|
is QrCodeLoginAction.OnQrCodeScanned -> handleOnQrCodeScanned(action)
|
||||||
QrCodeLoginAction.GenerateQrCode -> handleQrCodeViewStarted()
|
QrCodeLoginAction.GenerateQrCode -> handleQrCodeViewStarted()
|
||||||
QrCodeLoginAction.ShowQrCode -> handleShowQrCode()
|
QrCodeLoginAction.ShowQrCode -> handleShowQrCode()
|
||||||
|
QrCodeLoginAction.TryAgain -> handleTryAgain()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleTryAgain() {
|
||||||
|
_viewEvents.post(QrCodeLoginViewEvents.NavigateToInitialScreen)
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleShowQrCode() {
|
private fun handleShowQrCode() {
|
||||||
_viewEvents.post(QrCodeLoginViewEvents.NavigateToShowQrCodeScreen)
|
_viewEvents.post(QrCodeLoginViewEvents.NavigateToShowQrCodeScreen)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue