From 5a4f320bf984bece0d786dcb30855b876706139f Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 6 Oct 2021 17:16:57 +0100 Subject: [PATCH] binding the expanded state as part of the view, allows us to manually control the expansion --- .../app/core/epoxy/ExpandableTextItem.kt | 33 +++++++++++++++---- .../discovery/DiscoverySettingsAction.kt | 1 + .../discovery/DiscoverySettingsController.kt | 8 ++++- .../discovery/DiscoverySettingsFragment.kt | 4 +++ .../discovery/DiscoverySettingsState.kt | 3 +- .../discovery/DiscoverySettingsViewModel.kt | 29 ++++++++++------ 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/epoxy/ExpandableTextItem.kt b/vector/src/main/java/im/vector/app/core/epoxy/ExpandableTextItem.kt index a148c63865..ee942ed885 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/ExpandableTextItem.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/ExpandableTextItem.kt @@ -43,7 +43,13 @@ abstract class ExpandableTextItem : VectorEpoxyModel( @EpoxyAttribute var enableScrollBar = true - private var isExpanded = false + @EpoxyAttribute + var expanded: Boolean? = null + + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) + var onExpandClicked: () -> Unit? = {} + + private var internalIsExpanded = false private var expandedLines = 0 override fun bind(holder: Holder) { @@ -53,18 +59,31 @@ abstract class ExpandableTextItem : VectorEpoxyModel( holder.content.copyOnLongClick() holder.content.movementMethod = movementMethod + if (expanded == null) { + holder.view.setOnClickListener { + if (internalIsExpanded) { + collapse(holder) + } else { + expand(holder) + } + } + } else { + holder.view.setOnClickListener { onExpandClicked() } + } + holder.content.doOnPreDraw { if (holder.content.lineCount > maxLines) { expandedLines = holder.content.lineCount holder.content.maxLines = maxLines - holder.view.setOnClickListener { - if (isExpanded) { - collapse(holder) - } else { + expanded?.let { expanded -> + if (expanded) { expand(holder) + } else { + collapse(holder) } } + holder.arrow.isVisible = true } else { holder.arrow.isVisible = false @@ -81,7 +100,7 @@ abstract class ExpandableTextItem : VectorEpoxyModel( holder.content.ellipsize = null holder.arrow.setImageResource(R.drawable.ic_expand_less) holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_collapse) - isExpanded = true + internalIsExpanded = true } private fun collapse(holder: Holder) { @@ -93,7 +112,7 @@ abstract class ExpandableTextItem : VectorEpoxyModel( holder.content.ellipsize = TextUtils.TruncateAt.END holder.arrow.setImageResource(R.drawable.ic_expand_more) holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_expand) - isExpanded = false + internalIsExpanded = false } class Holder : VectorEpoxyHolder() { diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsAction.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsAction.kt index 426f1321e7..3d6038da3f 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsAction.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsAction.kt @@ -31,4 +31,5 @@ sealed class DiscoverySettingsAction : VectorViewModelAction { data class FinalizeBind3pid(val threePid: ThreePid) : DiscoverySettingsAction() data class SubmitMsisdnToken(val threePid: ThreePid.Msisdn, val code: String) : DiscoverySettingsAction() data class CancelBinding(val threePid: ThreePid) : DiscoverySettingsAction() + object PolicyUrlsExpandedStateToggled : DiscoverySettingsAction() } diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsController.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsController.kt index 502b9c5337..1d8989adc1 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsController.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsController.kt @@ -15,6 +15,7 @@ */ package im.vector.app.features.discovery +import android.text.method.LinkMovementMethod import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.Async import com.airbnb.mvrx.Fail @@ -134,7 +135,11 @@ class DiscoverySettingsController @Inject constructor( append(title) appendNl(policyUrls) }) - movementMethod(EvenBetterLinkMovementMethod()) + movementMethod(LinkMovementMethod()) + expanded(data.isIdentityPolicyUrlsExpanded) + onExpandClicked { + host.listener?.onPolicyUrlsExpandedStateToggled() + } } } @@ -419,5 +424,6 @@ class DiscoverySettingsController @Inject constructor( fun onTapDisconnectIdentityServer() fun onTapUpdateUserConsent(newValue: Boolean) fun onTapRetryToRetrieveBindings() + fun onPolicyUrlsExpandedStateToggled() } } diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt index 66ce2d0976..b079157421 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt @@ -192,6 +192,10 @@ class DiscoverySettingsFragment @Inject constructor( viewModel.handle(DiscoverySettingsAction.RetrieveBinding) } + override fun onPolicyUrlsExpandedStateToggled() { + viewModel.handle(DiscoverySettingsAction.PolicyUrlsExpandedStateToggled) + } + private fun navigateToChangeIdentityServerFragment() { (vectorBaseActivity as? VectorSettingsActivity)?.navigateTo(SetIdentityServerFragment::class.java) } diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsState.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsState.kt index 360ff4b2b1..4dbb5c495f 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsState.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsState.kt @@ -27,7 +27,8 @@ data class DiscoverySettingsState( val phoneNumbersList: Async> = Uninitialized, // Can be true if terms are updated val termsNotSigned: Boolean = false, - val userConsent: Boolean = false + val userConsent: Boolean = false, + val isIdentityPolicyUrlsExpanded: Boolean = false ) : MvRxState data class IdentityServerWithTerms( diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt index 9025537c7e..fc3eb7b990 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt @@ -111,16 +111,17 @@ class DiscoverySettingsViewModel @AssistedInject constructor( override fun handle(action: DiscoverySettingsAction) { when (action) { - DiscoverySettingsAction.Refresh -> fetchContent() - DiscoverySettingsAction.RetrieveBinding -> retrieveBinding() - DiscoverySettingsAction.DisconnectIdentityServer -> disconnectIdentityServer() - is DiscoverySettingsAction.ChangeIdentityServer -> changeIdentityServer(action) - is DiscoverySettingsAction.UpdateUserConsent -> handleUpdateUserConsent(action) - is DiscoverySettingsAction.RevokeThreePid -> revokeThreePid(action) - is DiscoverySettingsAction.ShareThreePid -> shareThreePid(action) - is DiscoverySettingsAction.FinalizeBind3pid -> finalizeBind3pid(action, true) - is DiscoverySettingsAction.SubmitMsisdnToken -> submitMsisdnToken(action) - is DiscoverySettingsAction.CancelBinding -> cancelBinding(action) + DiscoverySettingsAction.Refresh -> fetchContent() + DiscoverySettingsAction.RetrieveBinding -> retrieveBinding() + DiscoverySettingsAction.DisconnectIdentityServer -> disconnectIdentityServer() + DiscoverySettingsAction.PolicyUrlsExpandedStateToggled -> toggleExpandedPolicyUrlsState() + is DiscoverySettingsAction.ChangeIdentityServer -> changeIdentityServer(action) + is DiscoverySettingsAction.UpdateUserConsent -> handleUpdateUserConsent(action) + is DiscoverySettingsAction.RevokeThreePid -> revokeThreePid(action) + is DiscoverySettingsAction.ShareThreePid -> shareThreePid(action) + is DiscoverySettingsAction.FinalizeBind3pid -> finalizeBind3pid(action, true) + is DiscoverySettingsAction.SubmitMsisdnToken -> submitMsisdnToken(action) + is DiscoverySettingsAction.CancelBinding -> cancelBinding(action) }.exhaustive } @@ -147,6 +148,14 @@ class DiscoverySettingsViewModel @AssistedInject constructor( } } + private fun toggleExpandedPolicyUrlsState() { + withState { + setState { + copy(isIdentityPolicyUrlsExpanded = !it.isIdentityPolicyUrlsExpanded) + } + } + } + private fun changeIdentityServer(action: DiscoverySettingsAction.ChangeIdentityServer) { setState { copy(identityServer = Loading()) }