mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Adds accordion-style space sheet
This commit is contained in:
parent
cc49e96d36
commit
16efec9d1e
@ -22,6 +22,7 @@ import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.features.grouplist.newHomeSpaceSummaryItem
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
import im.vector.app.features.home.room.list.UnreadCounterBadgeView
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
|
||||
@ -50,7 +51,8 @@ class NewSpaceSummaryController @Inject constructor(
|
||||
nonNullViewState.spaces,
|
||||
nonNullViewState.selectedSpace,
|
||||
nonNullViewState.rootSpacesOrdered,
|
||||
nonNullViewState.homeAggregateCount
|
||||
nonNullViewState.homeAggregateCount,
|
||||
nonNullViewState.expandedStates,
|
||||
)
|
||||
}
|
||||
|
||||
@ -58,19 +60,49 @@ class NewSpaceSummaryController @Inject constructor(
|
||||
spaceSummaries: List<RoomSummary>?,
|
||||
selectedSpace: RoomSummary?,
|
||||
rootSpaces: List<RoomSummary>?,
|
||||
homeCount: RoomAggregateNotificationCount
|
||||
homeCount: RoomAggregateNotificationCount,
|
||||
expandedStates: Map<String, Boolean>,
|
||||
) {
|
||||
println(homeCount)
|
||||
val host = this
|
||||
newSpaceListHeaderItem {
|
||||
id("space_list_header")
|
||||
}
|
||||
|
||||
if (selectedSpace != null) {
|
||||
addSubSpaces(selectedSpace, spaceSummaries, homeCount)
|
||||
} else {
|
||||
addHomeItem(true, homeCount)
|
||||
addRootSpaces(rootSpaces)
|
||||
}
|
||||
addHomeItem(false, homeCount)
|
||||
|
||||
rootSpaces
|
||||
?.filter { it.membership != Membership.INVITE }
|
||||
?.forEach { spaceSummary ->
|
||||
|
||||
val subSpaces = spaceSummary.spaceChildren?.filter { childInfo ->
|
||||
spaceSummaries?.any { it.roomId == childInfo.childRoomId }.orFalse()
|
||||
}
|
||||
val hasChildren = (subSpaces?.size ?: 0) > 0
|
||||
val isSelected = spaceSummary.roomId == selectedSpace?.roomId
|
||||
val expanded = expandedStates[spaceSummary.roomId] == true
|
||||
|
||||
newSpaceSummaryItem {
|
||||
avatarRenderer(host.avatarRenderer)
|
||||
id(spaceSummary.roomId)
|
||||
matrixItem(spaceSummary.toMatrixItem())
|
||||
onSpaceSelectedListener { host.callback?.onSpaceSelected(spaceSummary) }
|
||||
countState(UnreadCounterBadgeView.State(spaceSummary.notificationCount, spaceSummary.highlightCount > 0))
|
||||
|
||||
expanded(expanded)
|
||||
hasChildren(hasChildren)
|
||||
toggleExpand { host.callback?.onToggleExpand(spaceSummary) }
|
||||
selected(isSelected)
|
||||
onMore { host.callback?.onSpaceSettings(spaceSummary) }
|
||||
}
|
||||
|
||||
if (hasChildren && expanded) {
|
||||
// it's expanded
|
||||
subSpaces?.forEach { child ->
|
||||
buildSubSpace(spaceSummary.roomId, spaceSummaries, expandedStates, selectedSpace, child, 1, 3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newSpaceAddItem {
|
||||
id("create")
|
||||
@ -78,6 +110,51 @@ class NewSpaceSummaryController @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildSubSpace(
|
||||
idPrefix: String,
|
||||
summaries: List<RoomSummary>?,
|
||||
expandedStates: Map<String, Boolean>,
|
||||
selectedSpace: RoomSummary?,
|
||||
info: SpaceChildInfo, currentDepth: Int, maxDepth: Int
|
||||
) {
|
||||
val host = this
|
||||
if (currentDepth >= maxDepth) return
|
||||
val childSummary = summaries?.firstOrNull { it.roomId == info.childRoomId } ?: return
|
||||
// does it have children?
|
||||
val subSpaces = childSummary.spaceChildren?.filter { childInfo ->
|
||||
summaries.any { it.roomId == childInfo.childRoomId }
|
||||
}?.sortedWith(subSpaceComparator)
|
||||
val expanded = expandedStates[childSummary.roomId] == true
|
||||
val isSelected = childSummary.roomId == selectedSpace?.roomId
|
||||
|
||||
val id = "$idPrefix:${childSummary.roomId}"
|
||||
|
||||
newSubSpaceSummaryItem {
|
||||
avatarRenderer(host.avatarRenderer)
|
||||
id(id)
|
||||
hasChildren(!subSpaces.isNullOrEmpty())
|
||||
selected(isSelected)
|
||||
expanded(expanded)
|
||||
onMore { host.callback?.onSpaceSettings(childSummary) }
|
||||
matrixItem(childSummary.toMatrixItem())
|
||||
listener { host.callback?.onSpaceSelected(childSummary) }
|
||||
toggleExpand { host.callback?.onToggleExpand(childSummary) }
|
||||
indent(currentDepth)
|
||||
countState(
|
||||
UnreadCounterBadgeView.State(
|
||||
childSummary.notificationCount,
|
||||
childSummary.highlightCount > 0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (expanded) {
|
||||
subSpaces?.forEach {
|
||||
buildSubSpace(id, summaries, expandedStates, selectedSpace, it, currentDepth + 1, maxDepth)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addHomeItem(selected: Boolean, homeCount: RoomAggregateNotificationCount) {
|
||||
val host = this
|
||||
newHomeSpaceSummaryItem {
|
||||
@ -108,7 +185,7 @@ class NewSpaceSummaryController @Inject constructor(
|
||||
id(subSpaceSummary.roomId)
|
||||
matrixItem(subSpaceSummary.toMatrixItem())
|
||||
selected(false)
|
||||
listener { host.callback?.onSpaceSelected(subSpaceSummary) }
|
||||
onSpaceSelectedListener { host.callback?.onSpaceSelected(subSpaceSummary) }
|
||||
countState(
|
||||
UnreadCounterBadgeView.State(
|
||||
subSpaceSummary.notificationCount,
|
||||
@ -124,25 +201,11 @@ class NewSpaceSummaryController @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRootSpaces(rootSpaces: List<RoomSummary>?) {
|
||||
val host = this
|
||||
rootSpaces
|
||||
?.filter { it.membership != Membership.INVITE }
|
||||
?.forEach { roomSummary ->
|
||||
newSpaceSummaryItem {
|
||||
avatarRenderer(host.avatarRenderer)
|
||||
id(roomSummary.roomId)
|
||||
matrixItem(roomSummary.toMatrixItem())
|
||||
listener { host.callback?.onSpaceSelected(roomSummary) }
|
||||
countState(UnreadCounterBadgeView.State(roomSummary.notificationCount, roomSummary.highlightCount > 0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
fun onSpaceSelected(spaceSummary: RoomSummary?)
|
||||
fun onSpaceInviteSelected(spaceSummary: RoomSummary)
|
||||
fun onSpaceSettings(spaceSummary: RoomSummary)
|
||||
fun onToggleExpand(spaceSummary: RoomSummary)
|
||||
fun onAddSpaceSelected()
|
||||
fun sendFeedBack()
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package im.vector.app.features.spaces
|
||||
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.app.R
|
||||
@ -36,14 +37,24 @@ abstract class NewSpaceSummaryItem : VectorEpoxyModel<NewSpaceSummaryItem.Holder
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var avatarRenderer: AvatarRenderer
|
||||
@EpoxyAttribute lateinit var matrixItem: MatrixItem
|
||||
@EpoxyAttribute var selected: Boolean = false
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onSpaceSelectedListener: ClickListener? = null
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: ClickListener? = null
|
||||
@EpoxyAttribute var countState: UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false)
|
||||
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: ClickListener? = null
|
||||
@EpoxyAttribute var expanded: Boolean = false
|
||||
@EpoxyAttribute var hasChildren: Boolean = false
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
holder.rootView.onClick(listener)
|
||||
holder.root.onClick(onSpaceSelectedListener)
|
||||
holder.root.setOnLongClickListener { onMore?.invoke(holder.root).let { true } }
|
||||
holder.name.text = matrixItem.displayName
|
||||
holder.rootView.isChecked = selected
|
||||
holder.root.isChecked = selected
|
||||
|
||||
holder.chevron.setOnClickListener(toggleExpand)
|
||||
holder.chevron.isVisible = hasChildren
|
||||
holder.chevron.setImageResource(if (expanded) R.drawable.ic_expand_more else R.drawable.ic_arrow_right)
|
||||
|
||||
avatarRenderer.render(matrixItem, holder.avatar)
|
||||
holder.unreadCounter.render(countState)
|
||||
@ -55,9 +66,10 @@ abstract class NewSpaceSummaryItem : VectorEpoxyModel<NewSpaceSummaryItem.Holder
|
||||
}
|
||||
|
||||
class Holder : VectorEpoxyHolder() {
|
||||
val rootView by bind<CheckableConstraintLayout>(R.id.root)
|
||||
val root by bind<CheckableConstraintLayout>(R.id.root)
|
||||
val avatar by bind<ImageView>(R.id.avatar)
|
||||
val name by bind<TextView>(R.id.name)
|
||||
val unreadCounter by bind<UnreadCounterBadgeView>(R.id.unread_counter)
|
||||
val chevron by bind<ImageView>(R.id.chevron)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.spaces
|
||||
|
||||
import android.widget.ImageView
|
||||
import android.widget.Space
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.ClickListener
|
||||
import im.vector.app.core.epoxy.VectorEpoxyHolder
|
||||
import im.vector.app.core.epoxy.VectorEpoxyModel
|
||||
import im.vector.app.core.epoxy.onClick
|
||||
import im.vector.app.core.platform.CheckableConstraintLayout
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
import im.vector.app.features.home.room.list.UnreadCounterBadgeView
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
|
||||
@EpoxyModelClass
|
||||
abstract class NewSubSpaceSummaryItem : VectorEpoxyModel<NewSubSpaceSummaryItem.Holder>(R.layout.item_new_sub_space) {
|
||||
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var avatarRenderer: AvatarRenderer
|
||||
@EpoxyAttribute lateinit var matrixItem: MatrixItem
|
||||
@EpoxyAttribute var selected: Boolean = false
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: ClickListener? = null
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: ClickListener? = null
|
||||
@EpoxyAttribute var expanded: Boolean = false
|
||||
@EpoxyAttribute var hasChildren: Boolean = false
|
||||
@EpoxyAttribute var indent: Int = 0
|
||||
@EpoxyAttribute var countState: UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false)
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
holder.root.onClick(listener)
|
||||
holder.name.text = matrixItem.displayName
|
||||
holder.root.isChecked = selected
|
||||
holder.root.setOnLongClickListener { onMore?.invoke(holder.root).let { true } }
|
||||
|
||||
holder.chevron.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
holder.view.context,
|
||||
if (expanded) R.drawable.ic_expand_more else R.drawable.ic_arrow_right
|
||||
)
|
||||
)
|
||||
holder.chevron.onClick(toggleExpand)
|
||||
holder.chevron.isVisible = hasChildren
|
||||
|
||||
holder.indent.isVisible = indent > 0
|
||||
holder.indent.updateLayoutParams {
|
||||
width = indent * 30
|
||||
}
|
||||
|
||||
avatarRenderer.render(matrixItem, holder.avatar)
|
||||
holder.notificationBadge.render(countState)
|
||||
}
|
||||
|
||||
override fun unbind(holder: Holder) {
|
||||
avatarRenderer.clear(holder.avatar)
|
||||
super.unbind(holder)
|
||||
}
|
||||
|
||||
class Holder : VectorEpoxyHolder() {
|
||||
val avatar by bind<ImageView>(R.id.avatar)
|
||||
val name by bind<TextView>(R.id.name)
|
||||
val root by bind<CheckableConstraintLayout>(R.id.root)
|
||||
val chevron by bind<ImageView>(R.id.chevron)
|
||||
val indent by bind<Space>(R.id.indent)
|
||||
val notificationBadge by bind<UnreadCounterBadgeView>(R.id.notification_badge)
|
||||
}
|
||||
}
|
@ -34,9 +34,9 @@
|
||||
android:maxLines="1"
|
||||
android:textColor="?vctr_content_primary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toEndOf="@id/avatar"
|
||||
app:layout_constraintEnd_toStartOf="@id/unread_counter"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/unread_counter"
|
||||
app:layout_constraintStart_toEndOf="@id/avatar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Element Corp" />
|
||||
|
||||
@ -53,25 +53,28 @@
|
||||
android:paddingEnd="4dp"
|
||||
android:textColor="?colorOnError"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/chevron"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
tools:background="@drawable/bg_unread_highlight"
|
||||
tools:text="147"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/chevron"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginEnd="21dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/ic_arrow_right"
|
||||
android:visibility="visible"
|
||||
android:scaleType="centerInside"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:tint="?vctr_content_secondary"
|
||||
tools:ignore="MissingPrefix" />
|
||||
tools:ignore="MissingPrefix"
|
||||
tools:src="@drawable/ic_arrow_right"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</im.vector.app.core.platform.CheckableConstraintLayout>
|
||||
|
93
vector/src/main/res/layout/item_new_sub_space.xml
Normal file
93
vector/src/main/res/layout/item_new_sub_space.xml
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<im.vector.app.core.platform.CheckableConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/bg_space_item"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
tools:viewBindingIgnore="true">
|
||||
|
||||
<Space
|
||||
android:id="@+id/indent"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="26dp"
|
||||
android:layout_height="26dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="@dimen/layout_horizontal_margin"
|
||||
android:duplicateParentState="true"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/indent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:src="@sample/space_avatars" />
|
||||
|
||||
<im.vector.app.features.home.room.list.UnreadCounterBadgeView
|
||||
android:id="@+id/notification_badge"
|
||||
style="@style/Widget.Vector.TextView.Micro"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:gravity="center"
|
||||
android:minWidth="16dp"
|
||||
android:minHeight="16dp"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingEnd="4dp"
|
||||
android:textColor="?colorOnError"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintCircle="@id/avatar"
|
||||
app:layout_constraintCircleAngle="45"
|
||||
app:layout_constraintCircleRadius="14dp"
|
||||
tools:background="@drawable/bg_unread_highlight"
|
||||
tools:text="147"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
style="@style/Widget.Vector.TextView.Subtitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/layout_horizontal_margin"
|
||||
android:layout_marginEnd="@dimen/layout_horizontal_margin"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?vctr_content_primary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/chevron"
|
||||
app:layout_constraintStart_toEndOf="@id/avatar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/chevron"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="centerInside"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tint="?vctr_content_secondary"
|
||||
tools:ignore="MissingPrefix"
|
||||
tools:src="@drawable/ic_arrow_right"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</im.vector.app.core.platform.CheckableConstraintLayout>
|
Loading…
Reference in New Issue
Block a user