From 20f969d563f66ac43fef5645fa945adc20f71d78 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 19 Nov 2019 19:16:34 +0100 Subject: [PATCH] Login screens: fix issue on terms --- .../login/terms/LoginTermsFragment.kt | 19 +++++++----- .../features/login/terms/PolicyController.kt | 7 +++-- .../terms/{PolicyModel.kt => PolicyItem.kt} | 7 ++++- .../src/main/res/color/login_button_tint.xml | 7 +++++ .../main/res/layout/fragment_login_terms.xml | 13 ++++++-- vector/src/main/res/layout/item_policy.xml | 31 ++++++++++++++----- vector/src/main/res/values/strings_riotX.xml | 1 + 7 files changed, 65 insertions(+), 20 deletions(-) rename vector/src/main/java/im/vector/riotx/features/login/terms/{PolicyModel.kt => PolicyItem.kt} (89%) create mode 100644 vector/src/main/res/color/login_button_tint.xml diff --git a/vector/src/main/java/im/vector/riotx/features/login/terms/LoginTermsFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/terms/LoginTermsFragment.kt index 3e202b5245..4b98563503 100755 --- a/vector/src/main/java/im/vector/riotx/features/login/terms/LoginTermsFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/terms/LoginTermsFragment.kt @@ -51,6 +51,7 @@ class LoginTermsFragment @Inject constructor(private val policyController: Polic super.onViewCreated(view, savedInstanceState) loginTermsPolicyList.setController(policyController) + policyController.homeServer = loginViewModel.getHomeServerUrlSimple() policyController.listener = this val list = ArrayList() @@ -83,14 +84,18 @@ class LoginTermsFragment @Inject constructor(private val policyController: Polic } override fun openPolicy(localizedFlowDataLoginTerms: LocalizedFlowDataLoginTerms) { - openUrlInExternalBrowser(requireContext(), localizedFlowDataLoginTerms.localizedUrl!!) + localizedFlowDataLoginTerms.localizedUrl + ?.takeIf { it.isNotBlank() } + ?.let { + openUrlInExternalBrowser(requireContext(), it) - // This code crashed, because user is not authenticated yet - //val intent = VectorWebViewActivity.getIntent(requireContext(), - // localizedFlowDataLoginTerms.localizedUrl!!, - // localizedFlowDataLoginTerms.localizedName!!, - // WebViewMode.DEFAULT) - //startActivity(intent) + // This code crashed, because user is not authenticated yet + //val intent = VectorWebViewActivity.getIntent(requireContext(), + // localizedFlowDataLoginTerms.localizedUrl!!, + // localizedFlowDataLoginTerms.localizedName!!, + // WebViewMode.DEFAULT) + //startActivity(intent) + } } @OnClick(R.id.loginTermsSubmit) diff --git a/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyController.kt b/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyController.kt index 6e86d40e3d..c301463c2a 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyController.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyController.kt @@ -25,12 +25,15 @@ class PolicyController @Inject constructor() : TypedEpoxyController) { data.forEach { entry -> - policy { + policyItem { id(entry.localizedFlowDataLoginTerms.policyName) checked(entry.checked) - title(entry.localizedFlowDataLoginTerms.localizedName!!) + title(entry.localizedFlowDataLoginTerms.localizedName) + subtitle(homeServer) clickListener(View.OnClickListener { listener?.openPolicy(entry.localizedFlowDataLoginTerms) }) checkChangeListener { _, isChecked -> diff --git a/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyModel.kt b/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyItem.kt similarity index 89% rename from vector/src/main/java/im/vector/riotx/features/login/terms/PolicyModel.kt rename to vector/src/main/java/im/vector/riotx/features/login/terms/PolicyItem.kt index 85b7c80dd0..9931d33068 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/terms/PolicyItem.kt @@ -27,13 +27,16 @@ import im.vector.riotx.R import im.vector.riotx.core.epoxy.VectorEpoxyHolder @EpoxyModelClass(layout = R.layout.item_policy) -abstract class PolicyModel : EpoxyModelWithHolder() { +abstract class PolicyItem : EpoxyModelWithHolder() { @EpoxyAttribute var checked: Boolean = false @EpoxyAttribute var title: String? = null + @EpoxyAttribute + var subtitle: String? = null + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var checkChangeListener: CompoundButton.OnCheckedChangeListener? = null @@ -45,6 +48,7 @@ abstract class PolicyModel : EpoxyModelWithHolder() { it.checkbox.isChecked = checked it.checkbox.setOnCheckedChangeListener(checkChangeListener) it.title.text = title + it.subtitle.text = subtitle it.view.setOnClickListener(clickListener) } } @@ -58,5 +62,6 @@ abstract class PolicyModel : EpoxyModelWithHolder() { class Holder : VectorEpoxyHolder() { val checkbox by bind(R.id.adapter_item_policy_checkbox) val title by bind(R.id.adapter_item_policy_title) + val subtitle by bind(R.id.adapter_item_policy_subtitle) } } diff --git a/vector/src/main/res/color/login_button_tint.xml b/vector/src/main/res/color/login_button_tint.xml new file mode 100644 index 0000000000..719335766c --- /dev/null +++ b/vector/src/main/res/color/login_button_tint.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/layout/fragment_login_terms.xml b/vector/src/main/res/layout/fragment_login_terms.xml index c595587a5d..e44139e18b 100644 --- a/vector/src/main/res/layout/fragment_login_terms.xml +++ b/vector/src/main/res/layout/fragment_login_terms.xml @@ -14,14 +14,23 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + app:layout_constraintTop_toBottomOf="@+id/loginTermsTitle" /> + android:foreground="?attr/selectableItemBackground" + android:minHeight="72dp"> - + + diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index bf8f22e59a..8a013a255b 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -100,5 +100,6 @@ Select modular Select a custom homeserver Please perform the captcha challenge + Accept terms to continue