mirror of
https://github.com/element-hq/element-android
synced 2024-12-19 07:45:17 +03:00
binding the expanded state as part of the view, allows us to manually control the expansion
This commit is contained in:
parent
7ce811c227
commit
5a4f320bf9
6 changed files with 59 additions and 19 deletions
|
@ -43,7 +43,13 @@ abstract class ExpandableTextItem : VectorEpoxyModel<ExpandableTextItem.Holder>(
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var enableScrollBar = true
|
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
|
private var expandedLines = 0
|
||||||
|
|
||||||
override fun bind(holder: Holder) {
|
override fun bind(holder: Holder) {
|
||||||
|
@ -53,18 +59,31 @@ abstract class ExpandableTextItem : VectorEpoxyModel<ExpandableTextItem.Holder>(
|
||||||
holder.content.copyOnLongClick()
|
holder.content.copyOnLongClick()
|
||||||
holder.content.movementMethod = movementMethod
|
holder.content.movementMethod = movementMethod
|
||||||
|
|
||||||
holder.content.doOnPreDraw {
|
if (expanded == null) {
|
||||||
if (holder.content.lineCount > maxLines) {
|
|
||||||
expandedLines = holder.content.lineCount
|
|
||||||
holder.content.maxLines = maxLines
|
|
||||||
|
|
||||||
holder.view.setOnClickListener {
|
holder.view.setOnClickListener {
|
||||||
if (isExpanded) {
|
if (internalIsExpanded) {
|
||||||
collapse(holder)
|
collapse(holder)
|
||||||
} else {
|
} else {
|
||||||
expand(holder)
|
expand(holder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
holder.view.setOnClickListener { onExpandClicked() }
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.content.doOnPreDraw {
|
||||||
|
if (holder.content.lineCount > maxLines) {
|
||||||
|
expandedLines = holder.content.lineCount
|
||||||
|
holder.content.maxLines = maxLines
|
||||||
|
|
||||||
|
expanded?.let { expanded ->
|
||||||
|
if (expanded) {
|
||||||
|
expand(holder)
|
||||||
|
} else {
|
||||||
|
collapse(holder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
holder.arrow.isVisible = true
|
holder.arrow.isVisible = true
|
||||||
} else {
|
} else {
|
||||||
holder.arrow.isVisible = false
|
holder.arrow.isVisible = false
|
||||||
|
@ -81,7 +100,7 @@ abstract class ExpandableTextItem : VectorEpoxyModel<ExpandableTextItem.Holder>(
|
||||||
holder.content.ellipsize = null
|
holder.content.ellipsize = null
|
||||||
holder.arrow.setImageResource(R.drawable.ic_expand_less)
|
holder.arrow.setImageResource(R.drawable.ic_expand_less)
|
||||||
holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_collapse)
|
holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_collapse)
|
||||||
isExpanded = true
|
internalIsExpanded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collapse(holder: Holder) {
|
private fun collapse(holder: Holder) {
|
||||||
|
@ -93,7 +112,7 @@ abstract class ExpandableTextItem : VectorEpoxyModel<ExpandableTextItem.Holder>(
|
||||||
holder.content.ellipsize = TextUtils.TruncateAt.END
|
holder.content.ellipsize = TextUtils.TruncateAt.END
|
||||||
holder.arrow.setImageResource(R.drawable.ic_expand_more)
|
holder.arrow.setImageResource(R.drawable.ic_expand_more)
|
||||||
holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_expand)
|
holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_expand)
|
||||||
isExpanded = false
|
internalIsExpanded = false
|
||||||
}
|
}
|
||||||
|
|
||||||
class Holder : VectorEpoxyHolder() {
|
class Holder : VectorEpoxyHolder() {
|
||||||
|
|
|
@ -31,4 +31,5 @@ sealed class DiscoverySettingsAction : VectorViewModelAction {
|
||||||
data class FinalizeBind3pid(val threePid: ThreePid) : DiscoverySettingsAction()
|
data class FinalizeBind3pid(val threePid: ThreePid) : DiscoverySettingsAction()
|
||||||
data class SubmitMsisdnToken(val threePid: ThreePid.Msisdn, val code: String) : DiscoverySettingsAction()
|
data class SubmitMsisdnToken(val threePid: ThreePid.Msisdn, val code: String) : DiscoverySettingsAction()
|
||||||
data class CancelBinding(val threePid: ThreePid) : DiscoverySettingsAction()
|
data class CancelBinding(val threePid: ThreePid) : DiscoverySettingsAction()
|
||||||
|
object PolicyUrlsExpandedStateToggled : DiscoverySettingsAction()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.discovery
|
package im.vector.app.features.discovery
|
||||||
|
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
|
@ -134,7 +135,11 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
append(title)
|
append(title)
|
||||||
appendNl(policyUrls)
|
appendNl(policyUrls)
|
||||||
})
|
})
|
||||||
movementMethod(EvenBetterLinkMovementMethod())
|
movementMethod(LinkMovementMethod())
|
||||||
|
expanded(data.isIdentityPolicyUrlsExpanded)
|
||||||
|
onExpandClicked {
|
||||||
|
host.listener?.onPolicyUrlsExpandedStateToggled()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,5 +424,6 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
fun onTapDisconnectIdentityServer()
|
fun onTapDisconnectIdentityServer()
|
||||||
fun onTapUpdateUserConsent(newValue: Boolean)
|
fun onTapUpdateUserConsent(newValue: Boolean)
|
||||||
fun onTapRetryToRetrieveBindings()
|
fun onTapRetryToRetrieveBindings()
|
||||||
|
fun onPolicyUrlsExpandedStateToggled()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,10 @@ class DiscoverySettingsFragment @Inject constructor(
|
||||||
viewModel.handle(DiscoverySettingsAction.RetrieveBinding)
|
viewModel.handle(DiscoverySettingsAction.RetrieveBinding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPolicyUrlsExpandedStateToggled() {
|
||||||
|
viewModel.handle(DiscoverySettingsAction.PolicyUrlsExpandedStateToggled)
|
||||||
|
}
|
||||||
|
|
||||||
private fun navigateToChangeIdentityServerFragment() {
|
private fun navigateToChangeIdentityServerFragment() {
|
||||||
(vectorBaseActivity as? VectorSettingsActivity)?.navigateTo(SetIdentityServerFragment::class.java)
|
(vectorBaseActivity as? VectorSettingsActivity)?.navigateTo(SetIdentityServerFragment::class.java)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ data class DiscoverySettingsState(
|
||||||
val phoneNumbersList: Async<List<PidInfo>> = Uninitialized,
|
val phoneNumbersList: Async<List<PidInfo>> = Uninitialized,
|
||||||
// Can be true if terms are updated
|
// Can be true if terms are updated
|
||||||
val termsNotSigned: Boolean = false,
|
val termsNotSigned: Boolean = false,
|
||||||
val userConsent: Boolean = false
|
val userConsent: Boolean = false,
|
||||||
|
val isIdentityPolicyUrlsExpanded: Boolean = false
|
||||||
) : MvRxState
|
) : MvRxState
|
||||||
|
|
||||||
data class IdentityServerWithTerms(
|
data class IdentityServerWithTerms(
|
||||||
|
|
|
@ -114,6 +114,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
|
||||||
DiscoverySettingsAction.Refresh -> fetchContent()
|
DiscoverySettingsAction.Refresh -> fetchContent()
|
||||||
DiscoverySettingsAction.RetrieveBinding -> retrieveBinding()
|
DiscoverySettingsAction.RetrieveBinding -> retrieveBinding()
|
||||||
DiscoverySettingsAction.DisconnectIdentityServer -> disconnectIdentityServer()
|
DiscoverySettingsAction.DisconnectIdentityServer -> disconnectIdentityServer()
|
||||||
|
DiscoverySettingsAction.PolicyUrlsExpandedStateToggled -> toggleExpandedPolicyUrlsState()
|
||||||
is DiscoverySettingsAction.ChangeIdentityServer -> changeIdentityServer(action)
|
is DiscoverySettingsAction.ChangeIdentityServer -> changeIdentityServer(action)
|
||||||
is DiscoverySettingsAction.UpdateUserConsent -> handleUpdateUserConsent(action)
|
is DiscoverySettingsAction.UpdateUserConsent -> handleUpdateUserConsent(action)
|
||||||
is DiscoverySettingsAction.RevokeThreePid -> revokeThreePid(action)
|
is DiscoverySettingsAction.RevokeThreePid -> revokeThreePid(action)
|
||||||
|
@ -147,6 +148,14 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun toggleExpandedPolicyUrlsState() {
|
||||||
|
withState {
|
||||||
|
setState {
|
||||||
|
copy(isIdentityPolicyUrlsExpanded = !it.isIdentityPolicyUrlsExpanded)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun changeIdentityServer(action: DiscoverySettingsAction.ChangeIdentityServer) {
|
private fun changeIdentityServer(action: DiscoverySettingsAction.ChangeIdentityServer) {
|
||||||
setState { copy(identityServer = Loading()) }
|
setState { copy(identityServer = Loading()) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue