From 2b452d6fe5f2a50debbdbc8d8a330627aea78c67 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 7 Oct 2022 19:04:27 +0300 Subject: [PATCH] Implement qr code login failed states. --- .../src/main/res/values/strings.xml | 5 ++++ .../login/qr/QrCodeLoginConnectionStatus.kt | 1 + .../features/login/qr/QrCodeLoginErrorType.kt | 23 ++++++++++++++++ .../login/qr/QrCodeLoginStatusFragment.kt | 27 +++++++++++++++++++ .../features/login/qr/QrCodeLoginViewModel.kt | 12 +++++++++ .../layout/fragment_qr_code_login_status.xml | 12 +++++++++ 6 files changed, 80 insertions(+) create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginErrorType.kt diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 22cddf84ce..86e1afa471 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -3337,6 +3337,10 @@ Use your signed in device to scan the QR code below: Secure connection established Check your signed in device, the code below should be displayed. Confirm that the code below matches with that device: + Unsuccessful connection + Linking with this device is not supported. + The linking wasn’t completed in the required time. + The request was denied on the other device. Open Element on your other device Go to Settings -> Security & Privacy Select \'Link a device\' @@ -3347,5 +3351,6 @@ Connecting to device Signing you in No match? + Try again diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt index 33c734d2f0..f2d50eafc4 100644 --- a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt @@ -20,4 +20,5 @@ sealed class QrCodeLoginConnectionStatus { object ConnectingToDevice : QrCodeLoginConnectionStatus() data class Connected(val securityCode: String) : QrCodeLoginConnectionStatus() object SigningIn : QrCodeLoginConnectionStatus() + data class Failed(val errorType: QrCodeLoginErrorType, val canTryAgain: Boolean) : QrCodeLoginConnectionStatus() } diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginErrorType.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginErrorType.kt new file mode 100644 index 0000000000..9a6cc13de0 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginErrorType.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.login.qr + +enum class QrCodeLoginErrorType { + DEVICE_IS_NOT_SUPPORTED, + TIMEOUT, + REQUEST_WAS_DENIED, +} diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt index 380db73376..26d24d9ed0 100644 --- a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt @@ -55,17 +55,42 @@ class QrCodeLoginStatusFragment : VectorBaseFragment handleConnectionEstablished(it.connectionStatus) QrCodeLoginConnectionStatus.ConnectingToDevice -> handleConnectingToDevice() QrCodeLoginConnectionStatus.SigningIn -> handleSigningIn() + is QrCodeLoginConnectionStatus.Failed -> handleFailed(it.connectionStatus) null -> { /* NOOP */ } } } } + private fun handleFailed(connectionStatus: QrCodeLoginConnectionStatus.Failed) { + views.qrCodeLoginStatusLoadingLayout.isVisible = false + views.qrCodeLoginStatusHeaderView.isVisible = true + views.qrCodeLoginStatusSecurityCode.isVisible = false + views.qrCodeLoginStatusNoMatchLayout.isVisible = false + views.qrCodeLoginStatusCancelButton.isVisible = true + views.qrCodeLoginStatusTryAgainButton.isVisible = connectionStatus.canTryAgain + views.qrCodeLoginStatusHeaderView.setTitle(getString(R.string.qr_code_login_header_failed_title)) + views.qrCodeLoginStatusHeaderView.setDescription(getErrorCode(connectionStatus.errorType)) + views.qrCodeLoginStatusHeaderView.setImage( + imageResource = R.drawable.ic_qr_code_login_failed, + backgroundTintColor = ThemeUtils.getColor(requireContext(), R.attr.colorError) + ) + } + + private fun getErrorCode(errorType: QrCodeLoginErrorType): String { + return when (errorType) { + QrCodeLoginErrorType.DEVICE_IS_NOT_SUPPORTED -> getString(R.string.qr_code_login_header_failed_device_is_not_supported_description) + QrCodeLoginErrorType.TIMEOUT -> getString(R.string.qr_code_login_header_failed_timeout_description) + QrCodeLoginErrorType.REQUEST_WAS_DENIED -> getString(R.string.qr_code_login_header_failed_denied_description) + } + } + private fun handleConnectingToDevice() { views.qrCodeLoginStatusLoadingLayout.isVisible = true views.qrCodeLoginStatusHeaderView.isVisible = false views.qrCodeLoginStatusSecurityCode.isVisible = false views.qrCodeLoginStatusNoMatchLayout.isVisible = false views.qrCodeLoginStatusCancelButton.isVisible = true + views.qrCodeLoginStatusTryAgainButton.isVisible = false views.qrCodeLoginStatusLoadingTextView.setText(R.string.qr_code_login_connecting_to_device) } @@ -75,6 +100,7 @@ class QrCodeLoginStatusFragment : VectorBaseFragment +