mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Merge pull request #5249 from vector-im/feature/mna/2782-collapse-acl-events
#2782: Collapse server ACLs update events
This commit is contained in:
commit
3b0856bf8e
5 changed files with 40 additions and 23 deletions
1
changelog.d/2782.misc
Normal file
1
changelog.d/2782.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Collapse successive ACLs events in room timeline
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.app.features.home.room.detail.timeline.factory
|
||||
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.core.extensions.prevOrNull
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
|
@ -26,10 +27,10 @@ import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventVisi
|
|||
import im.vector.app.features.home.room.detail.timeline.helper.canBeMerged
|
||||
import im.vector.app.features.home.room.detail.timeline.helper.isRoomConfiguration
|
||||
import im.vector.app.features.home.room.detail.timeline.item.BasedMergedItem
|
||||
import im.vector.app.features.home.room.detail.timeline.item.MergedMembershipEventsItem
|
||||
import im.vector.app.features.home.room.detail.timeline.item.MergedMembershipEventsItem_
|
||||
import im.vector.app.features.home.room.detail.timeline.item.MergedRoomCreationItem
|
||||
import im.vector.app.features.home.room.detail.timeline.item.MergedRoomCreationItem_
|
||||
import im.vector.app.features.home.room.detail.timeline.item.MergedSimilarEventsItem
|
||||
import im.vector.app.features.home.room.detail.timeline.item.MergedSimilarEventsItem_
|
||||
import im.vector.app.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
|
@ -82,7 +83,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
|
|||
event: TimelineEvent,
|
||||
eventIdToHighlight: String?,
|
||||
requestModelBuild: () -> Unit,
|
||||
callback: TimelineEventController.Callback?): MergedMembershipEventsItem_? {
|
||||
callback: TimelineEventController.Callback?): MergedSimilarEventsItem_? {
|
||||
val mergedEvents = timelineEventVisibilityHelper.prevSameTypeEvents(
|
||||
items,
|
||||
currentPosition,
|
||||
|
@ -122,23 +123,31 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
|
|||
collapsedEventIds.removeAll(mergedEventIds)
|
||||
}
|
||||
val mergeId = mergedEventIds.joinToString(separator = "_") { it.toString() }
|
||||
val attributes = MergedMembershipEventsItem.Attributes(
|
||||
isCollapsed = isCollapsed,
|
||||
mergeData = mergedData,
|
||||
avatarRenderer = avatarRenderer,
|
||||
onCollapsedStateChanged = {
|
||||
mergeItemCollapseStates[event.localId] = it
|
||||
requestModelBuild()
|
||||
}
|
||||
)
|
||||
MergedMembershipEventsItem_()
|
||||
.id(mergeId)
|
||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||
.highlighted(isCollapsed && highlighted)
|
||||
.attributes(attributes)
|
||||
.also {
|
||||
it.setOnVisibilityStateChanged(MergedTimelineEventVisibilityStateChangedListener(callback, mergedEvents))
|
||||
}
|
||||
val summaryTitleResId = when (event.root.getClearType()) {
|
||||
EventType.STATE_ROOM_MEMBER -> R.plurals.membership_changes
|
||||
EventType.STATE_ROOM_SERVER_ACL -> R.plurals.notice_room_server_acl_changes
|
||||
else -> null
|
||||
}
|
||||
summaryTitleResId?.let { summaryTitle ->
|
||||
val attributes = MergedSimilarEventsItem.Attributes(
|
||||
summaryTitleResId = summaryTitle,
|
||||
isCollapsed = isCollapsed,
|
||||
mergeData = mergedData,
|
||||
avatarRenderer = avatarRenderer,
|
||||
onCollapsedStateChanged = {
|
||||
mergeItemCollapseStates[event.localId] = it
|
||||
requestModelBuild()
|
||||
}
|
||||
)
|
||||
MergedSimilarEventsItem_()
|
||||
.id(mergeId)
|
||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||
.highlighted(isCollapsed && highlighted)
|
||||
.attributes(attributes)
|
||||
.also {
|
||||
it.setOnVisibilityStateChanged(MergedTimelineEventVisibilityStateChangedListener(callback, mergedEvents))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ object TimelineDisplayableEvents {
|
|||
}
|
||||
|
||||
fun TimelineEvent.canBeMerged(): Boolean {
|
||||
return root.getClearType() == EventType.STATE_ROOM_MEMBER
|
||||
return root.getClearType() == EventType.STATE_ROOM_MEMBER ||
|
||||
root.getClearType() == EventType.STATE_ROOM_SERVER_ACL
|
||||
}
|
||||
|
||||
fun TimelineEvent.isRoomConfiguration(roomCreatorUserId: String?): Boolean {
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.PluralsRes
|
||||
import androidx.core.view.children
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
|
@ -27,7 +28,7 @@ import im.vector.app.R
|
|||
import im.vector.app.features.home.AvatarRenderer
|
||||
|
||||
@EpoxyModelClass(layout = R.layout.item_timeline_event_base_noinfo)
|
||||
abstract class MergedMembershipEventsItem : BasedMergedItem<MergedMembershipEventsItem.Holder>() {
|
||||
abstract class MergedSimilarEventsItem : BasedMergedItem<MergedSimilarEventsItem.Holder>() {
|
||||
|
||||
override fun getViewStubId() = STUB_ID
|
||||
|
||||
|
@ -37,7 +38,7 @@ abstract class MergedMembershipEventsItem : BasedMergedItem<MergedMembershipEven
|
|||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
if (attributes.isCollapsed) {
|
||||
val summary = holder.expandView.resources.getQuantityString(R.plurals.membership_changes, attributes.mergeData.size, attributes.mergeData.size)
|
||||
val summary = holder.expandView.resources.getQuantityString(attributes.summaryTitleResId, attributes.mergeData.size, attributes.mergeData.size)
|
||||
holder.summaryView.text = summary
|
||||
holder.summaryView.visibility = View.VISIBLE
|
||||
holder.avatarListView.visibility = View.VISIBLE
|
||||
|
@ -66,6 +67,7 @@ abstract class MergedMembershipEventsItem : BasedMergedItem<MergedMembershipEven
|
|||
}
|
||||
|
||||
data class Attributes(
|
||||
@PluralsRes val summaryTitleResId: Int,
|
||||
override val isCollapsed: Boolean,
|
||||
override val mergeData: List<Data>,
|
||||
override val avatarRenderer: AvatarRenderer,
|
|
@ -81,6 +81,10 @@
|
|||
|
||||
<string name="notice_room_server_acl_updated_title">%s changed the server ACLs for this room.</string>
|
||||
<string name="notice_room_server_acl_updated_title_by_you">You changed the server ACLs for this room.</string>
|
||||
<plurals name="notice_room_server_acl_changes">
|
||||
<item quantity="one">%d server ACLs change</item>
|
||||
<item quantity="other">%d server ACLs changes</item>
|
||||
</plurals>
|
||||
<string name="notice_room_server_acl_updated_banned">• Servers matching %s are now banned.</string>
|
||||
<string name="notice_room_server_acl_updated_was_banned">• Servers matching %s were removed from the ban list.</string>
|
||||
<string name="notice_room_server_acl_updated_allowed">• Servers matching %s are now allowed.</string>
|
||||
|
|
Loading…
Reference in a new issue