dynamically setting the terms item padding

This commit is contained in:
Adam Brown 2022-04-08 16:19:57 +01:00
parent 06147967a4
commit f45de34db4
6 changed files with 29 additions and 14 deletions

View file

@ -24,6 +24,7 @@ class PolicyController @Inject constructor() : TypedEpoxyController<List<Localiz
var listener: PolicyControllerListener? = null
var horizontalPadding: Int? = null
var homeServer: String? = null
override fun buildModels(data: List<LocalizedFlowDataLoginTermsChecked>) {
@ -32,6 +33,7 @@ class PolicyController @Inject constructor() : TypedEpoxyController<List<Localiz
policyItem {
id(entry.localizedFlowDataLoginTerms.policyName)
checked(entry.checked)
horizontalPadding(host.horizontalPadding)
title(entry.localizedFlowDataLoginTerms.localizedName)
subtitle(host.homeServer)
clickListener { host.listener?.openPolicy(entry.localizedFlowDataLoginTerms) }

View file

@ -38,6 +38,9 @@ abstract class PolicyItem : EpoxyModelWithHolder<PolicyItem.Holder>() {
@EpoxyAttribute
var subtitle: String? = null
@EpoxyAttribute
var horizontalPadding: Int? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var checkChangeListener: CompoundButton.OnCheckedChangeListener? = null
@ -47,6 +50,12 @@ abstract class PolicyItem : EpoxyModelWithHolder<PolicyItem.Holder>() {
override fun bind(holder: Holder) {
super.bind(holder)
holder.let {
it.view.setPadding(
horizontalPadding ?: it.view.paddingLeft,
it.view.paddingTop,
horizontalPadding ?: it.view.paddingRight,
it.view.paddingBottom
)
it.checkbox.isChecked = checked
it.checkbox.setOnCheckedChangeListener(checkChangeListener)
it.title.text = title

View file

@ -20,7 +20,10 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.doOnLayout
import com.airbnb.mvrx.args
import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.toReducedUrl
@ -35,6 +38,7 @@ import im.vector.app.features.onboarding.RegisterAction
import im.vector.app.features.onboarding.ftueauth.AbstractFtueAuthFragment
import org.matrix.android.sdk.internal.auth.registration.LocalizedFlowDataLoginTerms
import javax.inject.Inject
import kotlin.math.roundToInt
/**
* LoginTermsFragment displays the list of policies the user has to accept
@ -54,24 +58,24 @@ class FtueAuthTermsFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupViews()
views.loginTermsPolicyList.configureWith(policyController, hasFixedSize = false)
policyController.listener = this
val list = ArrayList<LocalizedFlowDataLoginTermsChecked>()
params.localizedFlowDataLoginTerms
.forEach {
list.add(LocalizedFlowDataLoginTermsChecked(it))
}
loginTermsViewState = LoginTermsViewState(list)
}
private fun setupViews() {
views.displayNameSubmit.setOnClickListener { submit() }
views.loginTermsPolicyList.setHasFixedSize(false)
views.loginTermsPolicyList.configureWith(policyController, hasFixedSize = false, dividerDrawable = R.drawable.divider_horizontal)
views.displayNameGutterStart.doOnLayout {
val gutterSize = views.contentRoot.width * (views.displayNameGutterStart.layoutParams as ConstraintLayout.LayoutParams).guidePercent
policyController.horizontalPadding = gutterSize.roundToInt()
}
policyController.listener = this
}
override fun onDestroyView() {

View file

@ -48,6 +48,8 @@
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="16dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
app:layout_constraintBottom_toTopOf="@id/loginTermsSubmit"
app:layout_constraintTop_toBottomOf="@id/loginTermsNotice"
tools:listitem="@layout/item_policy" />

View file

@ -52,6 +52,8 @@
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="16dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
app:layout_constraintBottom_toTopOf="@id/loginTermsSubmit"
app:layout_constraintTop_toBottomOf="@id/loginTermsNotice"
tools:listitem="@layout/item_policy" />

View file

@ -6,8 +6,6 @@
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackground"
android:minHeight="72dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
tools:viewBindingIgnore="true">
<CheckBox
@ -20,10 +18,9 @@
<TextView
android:id="@+id/adapter_item_policy_title"
style="@style/Widget.Vector.TextView.Body"
style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:textColor="?vctr_content_primary"
app:layout_constraintBottom_toTopOf="@id/adapter_item_policy_subtitle"
app:layout_constraintEnd_toStartOf="@id/adapter_item_policy_arrow"
@ -50,16 +47,15 @@
<ImageView
android:id="@+id/adapter_item_policy_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="22dp"
android:importantForAccessibility="no"
android:paddingStart="8dp"
android:paddingEnd="0dp"
android:adjustViewBounds="true"
android:rotationY="@integer/rtl_mirror_flip"
android:src="@drawable/ic_arrow_right"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?vctr_content_secondary"
app:tint="?vctr_content_tertiary"
tools:ignore="MissingPrefix" />
</androidx.constraintlayout.widget.ConstraintLayout>