From 06c0d615a262d1766d91baeaec15c1feb66793b6 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 3 Oct 2022 13:55:46 +0300 Subject: [PATCH 01/37] Create base classes. --- vector/src/main/AndroidManifest.xml | 1 + .../features/login/qr/QrCodeLoginActivity.kt | 36 +++++++++++++++++++ .../app/features/login/qr/QrCodeLoginArgs.kt | 25 +++++++++++++ .../app/features/login/qr/QrCodeLoginType.kt | 22 ++++++++++++ .../login/qr/QrCodeLoginViewEvents.kt | 23 ++++++++++++ .../features/login/qr/QrCodeLoginViewState.kt | 28 +++++++++++++++ 6 files changed, 135 insertions(+) create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginActivity.kt create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginArgs.kt create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginType.kt create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewEvents.kt create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewState.kt diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index dbc6458713..1b26f814e6 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -318,6 +318,7 @@ + diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginActivity.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginActivity.kt new file mode 100644 index 0000000000..e0a5d244e1 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginActivity.kt @@ -0,0 +1,36 @@ +/* + * 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 + +import android.content.Context +import android.content.Intent +import dagger.hilt.android.AndroidEntryPoint +import im.vector.app.core.platform.SimpleFragmentActivity + +@AndroidEntryPoint +class QrCodeLoginActivity : SimpleFragmentActivity() { + + companion object { + private const val EXTRA_QR_CODE_LOGIN_ARGS = "EXTRA_QR_CODE_LOGIN_ARGS" + + fun getIntent(context: Context, qrCodeLoginArgs: QrCodeLoginArgs): Intent { + return Intent(context, QrCodeLoginActivity::class.java).apply { + putExtra(EXTRA_QR_CODE_LOGIN_ARGS, qrCodeLoginArgs) + } + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginArgs.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginArgs.kt new file mode 100644 index 0000000000..2f40b3ec4d --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginArgs.kt @@ -0,0 +1,25 @@ +/* + * 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 + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +data class QrCodeLoginArgs( + val loginType: QrCodeLoginType, +) : Parcelable diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginType.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginType.kt new file mode 100644 index 0000000000..b4bb5b667f --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginType.kt @@ -0,0 +1,22 @@ +/* + * 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 QrCodeLoginType { + LOGIN, + LINK_A_DEVICE, +} diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewEvents.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewEvents.kt new file mode 100644 index 0000000000..f5228f1d41 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewEvents.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 + +import im.vector.app.core.platform.VectorViewEvents + +sealed class QrCodeLoginViewEvents : VectorViewEvents { + +} diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewState.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewState.kt new file mode 100644 index 0000000000..5ee9ab33d8 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewState.kt @@ -0,0 +1,28 @@ +/* + * 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 + +import com.airbnb.mvrx.MavericksState + +data class QrCodeLoginViewState( + val loginType: QrCodeLoginType, +) : MavericksState { + + constructor(args: QrCodeLoginArgs) : this( + loginType = args.loginType, + ) +} From 6fbdd87dcf0e206b37efae285b77899446ce66ca Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 4 Oct 2022 17:05:42 +0300 Subject: [PATCH 02/37] Create custom view for header section. --- .../src/main/res/values/strings.xml | 4 ++ .../stylable_qr_code_login_header_view.xml | 11 +++ .../login/qr/QrCodeLoginHeaderView.kt | 69 +++++++++++++++++++ .../qr/QrCodeLoginInstructionsFragment.kt | 29 ++++++++ .../fragment_qr_code_login_instructions.xml | 20 ++++++ .../res/layout/view_qr_code_login_header.xml | 48 +++++++++++++ 6 files changed, 181 insertions(+) create mode 100644 library/ui-styles/src/main/res/values/stylable_qr_code_login_header_view.xml create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginHeaderView.kt create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsFragment.kt create mode 100644 vector/src/main/res/layout/fragment_qr_code_login_instructions.xml create mode 100644 vector/src/main/res/layout/view_qr_code_login_header.xml diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 4ff7aae750..8520bfbed4 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -3323,5 +3323,9 @@ Tap top right to see the option to feedback. Try it out + + + Scan QR code + Use the camera on this device to scan the QR code shown on your other device: diff --git a/library/ui-styles/src/main/res/values/stylable_qr_code_login_header_view.xml b/library/ui-styles/src/main/res/values/stylable_qr_code_login_header_view.xml new file mode 100644 index 0000000000..99f56084d9 --- /dev/null +++ b/library/ui-styles/src/main/res/values/stylable_qr_code_login_header_view.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginHeaderView.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginHeaderView.kt new file mode 100644 index 0000000000..315369c462 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginHeaderView.kt @@ -0,0 +1,69 @@ +/* + * 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 + +import android.content.Context +import android.content.res.ColorStateList +import android.content.res.TypedArray +import android.util.AttributeSet +import android.view.LayoutInflater +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.res.use +import im.vector.app.R +import im.vector.app.databinding.ViewQrCodeLoginHeaderBinding + +class QrCodeLoginHeaderView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + private val binding = ViewQrCodeLoginHeaderBinding.inflate( + LayoutInflater.from(context), + this + ) + + init { + context.obtainStyledAttributes( + attrs, + R.styleable.QrCodeLoginHeaderView, + 0, + 0 + ).use { + setTitle(it) + setDescription(it) + setImage(it) + } + } + + private fun setTitle(typedArray: TypedArray) { + val title = typedArray.getString(R.styleable.QrCodeLoginHeaderView_qrCodeLoginHeaderTitle) + binding.qrCodeLoginHeaderTitleTextView.text = title + } + + private fun setDescription(typedArray: TypedArray) { + val description = typedArray.getString(R.styleable.QrCodeLoginHeaderView_qrCodeLoginHeaderDescription) + binding.qrCodeLoginHeaderDescriptionTextView.text = description + } + + private fun setImage(typedArray: TypedArray) { + val imageResource = typedArray.getResourceId(R.styleable.QrCodeLoginHeaderView_qrCodeLoginHeaderImageResource, 0) + val backgroundTint = typedArray.getColor(R.styleable.QrCodeLoginHeaderView_qrCodeLoginHeaderImageBackgroundTint, 0) + binding.qrCodeLoginHeaderImageView.setImageResource(imageResource) + binding.qrCodeLoginHeaderImageView.backgroundTintList = ColorStateList.valueOf(backgroundTint) + } +} diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsFragment.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsFragment.kt new file mode 100644 index 0000000000..68848fad04 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsFragment.kt @@ -0,0 +1,29 @@ +/* + * 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 + +import android.view.LayoutInflater +import android.view.ViewGroup +import im.vector.app.core.platform.VectorBaseFragment +import im.vector.app.databinding.FragmentQrCodeLoginInstructionsBinding + +class QrCodeLoginInstructionsFragment : VectorBaseFragment() { + + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentQrCodeLoginInstructionsBinding { + return FragmentQrCodeLoginInstructionsBinding.inflate(inflater, container, false) + } +} diff --git a/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml b/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml new file mode 100644 index 0000000000..3f085b0aee --- /dev/null +++ b/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/vector/src/main/res/layout/view_qr_code_login_header.xml b/vector/src/main/res/layout/view_qr_code_login_header.xml new file mode 100644 index 0000000000..4a734ec21e --- /dev/null +++ b/vector/src/main/res/layout/view_qr_code_login_header.xml @@ -0,0 +1,48 @@ + + + + + + + + + + From 4fdb4e8c79fa0cc70d619e3cd193ac8baa6836bd Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 5 Oct 2022 13:23:39 +0300 Subject: [PATCH 03/37] Create custom view for instructions section. --- .../src/main/res/values/strings.xml | 11 +- .../stylable_qr_code_instructions_view.xml | 11 ++ .../login/qr/QrCodeLoginInstructionsView.kt | 61 ++++++++ ..._qr_code_login_instruction_with_border.xml | 14 ++ .../fragment_qr_code_login_instructions.xml | 14 ++ .../view_qr_code_login_instructions.xml | 132 ++++++++++++++++++ 6 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 library/ui-styles/src/main/res/values/stylable_qr_code_instructions_view.xml create mode 100644 vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsView.kt create mode 100644 vector/src/main/res/drawable/circle_qr_code_login_instruction_with_border.xml create mode 100644 vector/src/main/res/layout/view_qr_code_login_instructions.xml diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 8520bfbed4..a2642caab3 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -3323,9 +3323,18 @@ Tap top right to see the option to feedback. Try it out - + + 1 + 2 + 3 + 4 + Scan QR code Use the camera on this device to scan the QR code shown on your other device: + Open Element on your other device + Go to Settings -> Security & Privacy + Select \'Link a device\' + Select \'Show QR code on this device\' diff --git a/library/ui-styles/src/main/res/values/stylable_qr_code_instructions_view.xml b/library/ui-styles/src/main/res/values/stylable_qr_code_instructions_view.xml new file mode 100644 index 0000000000..c9a4bb9d05 --- /dev/null +++ b/library/ui-styles/src/main/res/values/stylable_qr_code_instructions_view.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsView.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsView.kt new file mode 100644 index 0000000000..ddb92b272e --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginInstructionsView.kt @@ -0,0 +1,61 @@ +/* + * 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 + +import android.content.Context +import android.content.res.TypedArray +import android.util.AttributeSet +import android.view.LayoutInflater +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.res.use +import im.vector.app.R +import im.vector.app.core.extensions.setTextOrHide +import im.vector.app.databinding.ViewQrCodeLoginInstructionsBinding + +class QrCodeLoginInstructionsView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + private val binding = ViewQrCodeLoginInstructionsBinding.inflate( + LayoutInflater.from(context), + this + ) + + init { + context.obtainStyledAttributes( + attrs, + R.styleable.QrCodeLoginInstructionsView, + 0, + 0 + ).use { + setInstructions(it) + } + } + + private fun setInstructions(typedArray: TypedArray) { + val instruction1 = typedArray.getString(R.styleable.QrCodeLoginInstructionsView_qrCodeLoginInstruction1) + val instruction2 = typedArray.getString(R.styleable.QrCodeLoginInstructionsView_qrCodeLoginInstruction2) + val instruction3 = typedArray.getString(R.styleable.QrCodeLoginInstructionsView_qrCodeLoginInstruction3) + val instruction4 = typedArray.getString(R.styleable.QrCodeLoginInstructionsView_qrCodeLoginInstruction4) + binding.instruction1TextView.setTextOrHide(instruction1) + binding.instruction2TextView.setTextOrHide(instruction2) + binding.instruction3TextView.setTextOrHide(instruction3) + binding.instruction4TextView.setTextOrHide(instruction4) + } +} diff --git a/vector/src/main/res/drawable/circle_qr_code_login_instruction_with_border.xml b/vector/src/main/res/drawable/circle_qr_code_login_instruction_with_border.xml new file mode 100644 index 0000000000..cb99e4467c --- /dev/null +++ b/vector/src/main/res/drawable/circle_qr_code_login_instruction_with_border.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml b/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml index 3f085b0aee..9f87b1b4d4 100644 --- a/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml +++ b/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml @@ -17,4 +17,18 @@ app:qrCodeLoginHeaderImageResource="@drawable/ic_camera" app:qrCodeLoginHeaderTitle="@string/qr_code_login_header_scan_qr_code_title" /> + + diff --git a/vector/src/main/res/layout/view_qr_code_login_instructions.xml b/vector/src/main/res/layout/view_qr_code_login_instructions.xml new file mode 100644 index 0000000000..4b23c0d73d --- /dev/null +++ b/vector/src/main/res/layout/view_qr_code_login_instructions.xml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9859dab3cc7127ad54a69cc6b39768e70257867e Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 6 Oct 2022 00:51:00 +0300 Subject: [PATCH 04/37] Complete qr code login instructions screen. --- .../src/main/res/values/strings.xml | 3 ++ .../fragment_qr_code_login_instructions.xml | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index a2642caab3..5099b70c1d 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -3336,5 +3336,8 @@ Go to Settings -> Security & Privacy Select \'Link a device\' Select \'Show QR code on this device\' + Show QR code in this device + Need an alternative method? + Scan QR code diff --git a/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml b/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml index 9f87b1b4d4..9a7a97a12b 100644 --- a/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml +++ b/vector/src/main/res/layout/fragment_qr_code_login_instructions.xml @@ -31,4 +31,53 @@ app:qrCodeLoginInstruction3="@string/qr_code_login_new_device_instruction_3" app:qrCodeLoginInstruction4="@string/qr_code_login_new_device_instruction_4" /> +