Login screens: fix issue on terms

This commit is contained in:
Benoit Marty 2019-11-19 19:16:34 +01:00
parent a8f24e5c39
commit 20f969d563
7 changed files with 65 additions and 20 deletions

View File

@ -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<LocalizedFlowDataLoginTermsChecked>()
@ -83,7 +84,10 @@ 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(),
@ -92,6 +96,7 @@ class LoginTermsFragment @Inject constructor(private val policyController: Polic
// WebViewMode.DEFAULT)
//startActivity(intent)
}
}
@OnClick(R.id.loginTermsSubmit)
internal fun submit() {

View File

@ -25,12 +25,15 @@ class PolicyController @Inject constructor() : TypedEpoxyController<List<Localiz
var listener: PolicyControllerListener? = null
var homeServer: String? = null
override fun buildModels(data: List<LocalizedFlowDataLoginTermsChecked>) {
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 ->

View File

@ -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<PolicyModel.Holder>() {
abstract class PolicyItem : EpoxyModelWithHolder<PolicyItem.Holder>() {
@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<PolicyModel.Holder>() {
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<PolicyModel.Holder>() {
class Holder : VectorEpoxyHolder() {
val checkbox by bind<CheckBox>(R.id.adapter_item_policy_checkbox)
val title by bind<TextView>(R.id.adapter_item_policy_title)
val subtitle by bind<TextView>(R.id.adapter_item_policy_subtitle)
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/riotx_accent" android:state_checked="true" />
<item android:color="#61708B" />
</selector>

View File

@ -14,14 +14,23 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/loginTermsTitle"
style="@style/TextAppearance.Vector.Login.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="27dp"
android:text="@string/login_terms_title"
app:layout_constraintTop_toBottomOf="@+id/logoImageView" />
<TextView
android:id="@+id/loginTermsNotice"
style="@style/TextAppearance.Vector.Login.Text.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="27dp"
android:layout_marginTop="12dp"
android:text="@string/auth_accept_policies"
app:layout_constraintTop_toBottomOf="@+id/logoImageView" />
app:layout_constraintTop_toBottomOf="@+id/loginTermsTitle" />
<com.airbnb.epoxy.EpoxyRecyclerView
android:id="@+id/loginTermsPolicyList"

View File

@ -4,40 +4,55 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp">
android:foreground="?attr/selectableItemBackground"
android:minHeight="72dp">
<CheckBox
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/adapter_item_policy_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/login_button_tint"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/adapter_item_policy_title"
style="@style/TextAppearance.Vector.Login.Text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:drawablePadding="8dp"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/adapter_item_policy_subtitle"
app:layout_constraintEnd_toStartOf="@+id/adapter_item_policy_arrow"
app:layout_constraintStart_toEndOf="@+id/adapter_item_policy_checkbox"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="Policy title" />
<TextView
android:id="@+id/adapter_item_policy_subtitle"
style="@style/TextAppearance.Vector.Login.Text.Small"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:drawablePadding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/adapter_item_policy_arrow"
app:layout_constraintStart_toEndOf="@+id/adapter_item_policy_checkbox"
app:layout_constraintTop_toBottomOf="@+id/adapter_item_policy_title"
tools:text="matrix.org" />
<!-- Do not use drawableEnd on the TextView because of RTL support -->
<ImageView
android:id="@+id/adapter_item_policy_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAccessibility="no"
android:paddingStart="8dp"
android:paddingEnd="0dp"
android:rotationY="@integer/rtl_mirror_flip"
android:src="@drawable/ic_material_chevron_right_black"
android:tint="?riotx_android_secondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@ -100,5 +100,6 @@
<string name="login_a11y_choose_modular">Select modular</string>
<string name="login_a11y_choose_other">Select a custom homeserver</string>
<string name="login_a11y_captcha_container">Please perform the captcha challenge</string>
<string name="login_terms_title">Accept terms to continue</string>
</resources>