mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 03:49:04 +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
|
||||
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<ExpandableTextItem.Holder>(
|
|||
holder.content.copyOnLongClick()
|
||||
holder.content.movementMethod = movementMethod
|
||||
|
||||
holder.content.doOnPreDraw {
|
||||
if (holder.content.lineCount > maxLines) {
|
||||
expandedLines = holder.content.lineCount
|
||||
holder.content.maxLines = maxLines
|
||||
|
||||
if (expanded == null) {
|
||||
holder.view.setOnClickListener {
|
||||
if (isExpanded) {
|
||||
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
|
||||
|
||||
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<ExpandableTextItem.Holder>(
|
|||
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<ExpandableTextItem.Holder>(
|
|||
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() {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ data class DiscoverySettingsState(
|
|||
val phoneNumbersList: Async<List<PidInfo>> = 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(
|
||||
|
|
|
@ -114,6 +114,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
|
|||
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)
|
||||
|
@ -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()) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue