Subspace more hierarchy depth + fix bad notification count

This commit is contained in:
Valere 2021-05-11 10:07:34 +02:00
parent 1ec08bec07
commit 24a32f2b7e
5 changed files with 292 additions and 24 deletions

View File

@ -18,6 +18,7 @@
package im.vector.app.features.grouplist package im.vector.app.features.grouplist
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -35,8 +36,9 @@ import im.vector.app.features.themes.ThemeUtils
abstract class HomeSpaceSummaryItem : VectorEpoxyModel<HomeSpaceSummaryItem.Holder>() { abstract class HomeSpaceSummaryItem : VectorEpoxyModel<HomeSpaceSummaryItem.Holder>() {
@EpoxyAttribute var selected: Boolean = false @EpoxyAttribute var selected: Boolean = false
@EpoxyAttribute var listener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: (() -> Unit)? = null
@EpoxyAttribute var countState : UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false) @EpoxyAttribute var countState : UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false)
@EpoxyAttribute var showSeparator: Boolean = false
override fun getViewType(): Int { override fun getViewType(): Int {
// mm.. it's reusing the same layout for basic space item // mm.. it's reusing the same layout for basic space item
@ -56,6 +58,7 @@ abstract class HomeSpaceSummaryItem : VectorEpoxyModel<HomeSpaceSummaryItem.Hold
holder.leaveView.isVisible = false holder.leaveView.isVisible = false
holder.counterBadgeView.render(countState) holder.counterBadgeView.render(countState)
holder.bottomSeparator.isVisible = showSeparator
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {
@ -64,5 +67,6 @@ abstract class HomeSpaceSummaryItem : VectorEpoxyModel<HomeSpaceSummaryItem.Hold
val rootView by bind<CheckableConstraintLayout>(R.id.itemGroupLayout) val rootView by bind<CheckableConstraintLayout>(R.id.itemGroupLayout)
val leaveView by bind<ImageView>(R.id.groupTmpLeave) val leaveView by bind<ImageView>(R.id.groupTmpLeave)
val counterBadgeView by bind<UnreadCounterBadgeView>(R.id.groupCounterBadge) val counterBadgeView by bind<UnreadCounterBadgeView>(R.id.groupCounterBadge)
val bottomSeparator by bind<View>(R.id.groupBottomSeparator)
} }
} }

View File

@ -31,8 +31,8 @@ import im.vector.app.space
import org.matrix.android.sdk.api.session.group.model.GroupSummary import org.matrix.android.sdk.api.session.group.model.GroupSummary
import org.matrix.android.sdk.api.session.room.model.Membership 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.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
import org.matrix.android.sdk.api.util.MatrixItem
import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject import javax.inject.Inject
@ -163,24 +163,7 @@ class SpaceSummaryController @Inject constructor(
if (hasChildren && expanded) { if (hasChildren && expanded) {
// it's expanded // it's expanded
subSpaces?.forEach { child -> subSpaces?.forEach { child ->
summaries?.firstOrNull { it.roomId == child.childRoomId }?.let { childSum -> buildSubSpace(summaries, expandedStates, selected, child, 1, 3)
val isChildSelected = selected is RoomGroupingMethod.BySpace && childSum.roomId == selected.space()?.roomId
spaceSummaryItem {
avatarRenderer(avatarRenderer)
id(child.childRoomId)
hasChildren(false)
selected(isChildSelected)
matrixItem(MatrixItem.RoomItem(child.childRoomId, child.name, child.avatarUrl))
listener { callback?.onSpaceSelected(childSum) }
indent(1)
countState(
UnreadCounterBadgeView.State(
groupSummary.notificationCount,
groupSummary.highlightCount > 0
)
)
}
}
} }
} }
} }
@ -191,6 +174,45 @@ class SpaceSummaryController @Inject constructor(
} }
} }
private fun buildSubSpace(summaries: List<RoomSummary>?,
expandedStates: Map<String, Boolean>,
selected: RoomGroupingMethod,
childSum: SpaceChildInfo, currentDepth: Int, maxDepth: Int) {
if (currentDepth >= maxDepth) return
val childSum = summaries?.firstOrNull { it.roomId == childSum.childRoomId } ?: return
// does it have children?
val subSpaces = childSum.spaceChildren?.filter { childInfo ->
summaries.indexOfFirst { it.roomId == childInfo.childRoomId } != -1
}
val expanded = expandedStates[childSum.roomId] == true
val isSelected = selected is RoomGroupingMethod.BySpace && childSum.roomId == selected.space()?.roomId
subSpaceSummaryItem {
avatarRenderer(avatarRenderer)
id(childSum.roomId)
hasChildren(!subSpaces.isNullOrEmpty())
selected(isSelected)
expanded(expanded)
onMore { callback?.onSpaceSettings(childSum) }
matrixItem(childSum.toMatrixItem())
listener { callback?.onSpaceSelected(childSum) }
toggleExpand { callback?.onToggleExpand(childSum) }
indent(currentDepth)
countState(
UnreadCounterBadgeView.State(
childSum.notificationCount,
childSum.highlightCount > 0
)
)
}
if (expanded) {
subSpaces?.forEach {
buildSubSpace(summaries, expandedStates, selected, it, currentDepth + 1, maxDepth)
}
}
}
interface Callback { interface Callback {
fun onSpaceSelected(spaceSummary: RoomSummary?) fun onSpaceSelected(spaceSummary: RoomSummary?)
fun onSpaceInviteSelected(spaceSummary: RoomSummary) fun onSpaceInviteSelected(spaceSummary: RoomSummary)

View File

@ -16,6 +16,7 @@
package im.vector.app.features.spaces package im.vector.app.features.spaces
import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.Space import android.widget.Space
import android.widget.TextView import android.widget.TextView
@ -37,17 +38,18 @@ import org.matrix.android.sdk.api.util.MatrixItem
@EpoxyModelClass(layout = R.layout.item_space) @EpoxyModelClass(layout = R.layout.item_space)
abstract class SpaceSummaryItem : VectorEpoxyModel<SpaceSummaryItem.Holder>() { abstract class SpaceSummaryItem : VectorEpoxyModel<SpaceSummaryItem.Holder>() {
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var matrixItem: MatrixItem @EpoxyAttribute lateinit var matrixItem: MatrixItem
@EpoxyAttribute var selected: Boolean = false @EpoxyAttribute var selected: Boolean = false
@EpoxyAttribute var listener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: (() -> Unit)? = null
@EpoxyAttribute var onMore: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: (() -> Unit)? = null
@EpoxyAttribute var toggleExpand: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: (() -> Unit)? = null
@EpoxyAttribute var expanded: Boolean = false @EpoxyAttribute var expanded: Boolean = false
@EpoxyAttribute var hasChildren: Boolean = false @EpoxyAttribute var hasChildren: Boolean = false
@EpoxyAttribute var indent: Int = 0 @EpoxyAttribute var indent: Int = 0
@EpoxyAttribute var countState : UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false) @EpoxyAttribute var countState : UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false)
@EpoxyAttribute var description: String? = null @EpoxyAttribute var description: String? = null
@EpoxyAttribute var showSeparator: Boolean = false
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
@ -83,6 +85,7 @@ abstract class SpaceSummaryItem : VectorEpoxyModel<SpaceSummaryItem.Holder>() {
} }
holder.indentSpace.isVisible = indent > 0 holder.indentSpace.isVisible = indent > 0
holder.separator.isVisible = showSeparator
avatarRenderer.renderSpace(matrixItem, holder.avatarImageView) avatarRenderer.renderSpace(matrixItem, holder.avatarImageView)
holder.counterBadgeView.render(countState) holder.counterBadgeView.render(countState)
@ -102,5 +105,6 @@ abstract class SpaceSummaryItem : VectorEpoxyModel<SpaceSummaryItem.Holder>() {
val collapseIndicator by bind<ImageView>(R.id.groupChildrenCollapse) val collapseIndicator by bind<ImageView>(R.id.groupChildrenCollapse)
val indentSpace by bind<Space>(R.id.indent) val indentSpace by bind<Space>(R.id.indent)
val counterBadgeView by bind<UnreadCounterBadgeView>(R.id.groupCounterBadge) val counterBadgeView by bind<UnreadCounterBadgeView>(R.id.groupCounterBadge)
val separator by bind<View>(R.id.groupBottomSeparator)
} }
} }

View File

@ -0,0 +1,106 @@
/*
* 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.isGone
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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.platform.CheckableConstraintLayout
import im.vector.app.core.utils.DebouncedClickListener
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(layout = R.layout.item_sub_space)
abstract class SubSpaceSummaryItem : VectorEpoxyModel<SubSpaceSummaryItem.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: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: (() -> Unit)? = 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.rootView.setOnClickListener { listener?.invoke() }
holder.groupNameView.text = matrixItem.displayName
holder.rootView.isChecked = selected
if (onMore != null) {
holder.moreView.isVisible = true
holder.moreView.setOnClickListener(
DebouncedClickListener({ _ ->
onMore?.invoke()
})
)
} else {
holder.moreView.isVisible = false
}
if (hasChildren) {
holder.collapseIndicator.isVisible = true
holder.collapseIndicator.setImageDrawable(
ContextCompat.getDrawable(holder.view.context,
if (expanded) R.drawable.ic_expand_less else R.drawable.ic_expand_more
)
)
holder.collapseIndicator.setOnClickListener(
DebouncedClickListener({ _ ->
toggleExpand?.invoke()
})
)
} else {
holder.collapseIndicator.isGone = true
}
holder.indentSpace.isVisible = indent > 0
holder.indentSpace.updateLayoutParams {
width = indent * 30
}
avatarRenderer.renderSpace(matrixItem, holder.avatarImageView)
holder.counterBadgeView.render(countState)
}
override fun unbind(holder: Holder) {
avatarRenderer.clear(holder.avatarImageView)
super.unbind(holder)
}
class Holder : VectorEpoxyHolder() {
val avatarImageView by bind<ImageView>(R.id.groupAvatarImageView)
val groupNameView by bind<TextView>(R.id.groupNameView)
val rootView by bind<CheckableConstraintLayout>(R.id.itemGroupLayout)
val moreView by bind<ImageView>(R.id.groupTmpLeave)
val collapseIndicator by bind<ImageView>(R.id.groupChildrenCollapse)
val indentSpace by bind<Space>(R.id.indent)
val counterBadgeView by bind<UnreadCounterBadgeView>(R.id.groupCounterBadge)
}
}

View File

@ -0,0 +1,132 @@
<?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/itemGroupLayout"
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">
<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/groupAvatarImageView"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_gravity="center"
android:layout_marginStart="@dimen/layout_horizontal_margin"
android:contentDescription="@string/avatar"
android:duplicateParentState="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/indent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/avatars" />
<im.vector.app.features.home.room.list.UnreadCounterBadgeView
android:id="@+id/groupCounterBadge"
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="@android:color/white"
android:textSize="10sp"
android:visibility="gone"
app:layout_constraintCircle="@+id/groupAvatarImageView"
app:layout_constraintCircleAngle="45"
app:layout_constraintCircleRadius="14dp"
tools:background="@drawable/bg_unread_highlight"
tools:text="147"
tools:visibility="visible" />
<TextView
android:id="@+id/groupNameView"
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="?riotx_text_primary"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/groupChildrenCollapse"
app:layout_constraintStart_toEndOf="@+id/groupAvatarImageView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="@tools:sample/lorem/random" />
<ImageView
android:id="@+id/groupChildrenCollapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:importantForAccessibility="no"
android:src="@drawable/ic_expand_less_white"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/groupTmpLeave"
app:layout_constraintTop_toTopOf="parent"
app:tint="?riotx_text_primary"
tools:ignore="MissingPrefix"
tools:src="@drawable/ic_expand_more_white"
tools:visibility="visible" />
<ImageView
android:id="@+id/groupTmpLeave"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="4dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:importantForAccessibility="no"
android:padding="4dp"
android:src="@drawable/ic_more_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/groupAvatarChevron"
app:layout_constraintTop_toTopOf="parent"
app:tint="?riotx_text_secondary" />
<ImageView
android:id="@+id/groupAvatarChevron"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="21dp"
android:importantForAccessibility="no"
android:src="@drawable/ic_arrow_right"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/groupBottomSeparator"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?riotx_text_primary"
tools:ignore="MissingPrefix" />
<!-- <View-->
<!-- android:id="@+id/groupBottomSeparator"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="1dp"-->
<!-- android:background="?riotx_header_panel_border_mobile"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent" />-->
</im.vector.app.core.platform.CheckableConstraintLayout>