mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-15 18:59:12 +03:00
Category unread counter: count chats with non-notification events
When collapsing categories and disabling notifications for chats, it might still be interesting how many unread chats there are. Change-Id: If62cda94844cc7741d5052e9954d8fe1447de93a
This commit is contained in:
parent
c7ae49df1b
commit
8d6b141d8b
11 changed files with 45 additions and 10 deletions
|
@ -36,6 +36,7 @@ abstract class BreadcrumbsItem : VectorEpoxyModel<BreadcrumbsItem.Holder>() {
|
|||
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
|
||||
@EpoxyAttribute lateinit var matrixItem: MatrixItem
|
||||
@EpoxyAttribute var unreadNotificationCount: Int = 0
|
||||
@EpoxyAttribute var unreadMessages: Int = 0 // SC addition
|
||||
@EpoxyAttribute var showHighlighted: Boolean = false
|
||||
@EpoxyAttribute var hasUnreadMessage: Boolean = false
|
||||
@EpoxyAttribute var hasDraft: Boolean = false
|
||||
|
@ -46,7 +47,7 @@ abstract class BreadcrumbsItem : VectorEpoxyModel<BreadcrumbsItem.Holder>() {
|
|||
holder.rootView.setOnClickListener(itemClickListener)
|
||||
holder.unreadIndentIndicator.isVisible = hasUnreadMessage
|
||||
avatarRenderer.render(matrixItem, holder.avatarImageView)
|
||||
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
|
||||
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted, unreadMessages))
|
||||
holder.draftIndentIndicator.isVisible = hasDraft
|
||||
holder.typingIndicator.isVisible = hasTypingUsers
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ abstract class RoomCategoryItem : VectorEpoxyModel<RoomCategoryItem.Holder>() {
|
|||
@EpoxyAttribute lateinit var title: CharSequence
|
||||
@EpoxyAttribute var expanded: Boolean = false
|
||||
@EpoxyAttribute var unreadNotificationCount: Int = 0
|
||||
@EpoxyAttribute var unreadMessages: Int = 0
|
||||
@EpoxyAttribute var showHighlighted: Boolean = false
|
||||
@EpoxyAttribute var listener: (() -> Unit)? = null
|
||||
|
||||
|
@ -43,7 +44,7 @@ abstract class RoomCategoryItem : VectorEpoxyModel<RoomCategoryItem.Holder>() {
|
|||
val expandedArrowDrawable = ContextCompat.getDrawable(holder.rootView.context, expandedArrowDrawableRes)?.also {
|
||||
DrawableCompat.setTint(it, tintColor)
|
||||
}
|
||||
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
|
||||
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted, unreadMessages))
|
||||
holder.titleView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
|
||||
holder.titleView.text = title
|
||||
holder.rootView.setOnClickListener { listener?.invoke() }
|
||||
|
|
|
@ -23,17 +23,20 @@ import im.vector.app.core.epoxy.helpFooterItem
|
|||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.resources.UserPreferencesProvider
|
||||
import im.vector.app.features.home.RoomListDisplayMode
|
||||
import im.vector.app.features.home.room.ScSdkPreferences
|
||||
import im.vector.app.features.home.room.filtered.FilteredRoomFooterItem
|
||||
import im.vector.app.features.home.room.filtered.filteredRoomFooterItem
|
||||
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class RoomSummaryController @Inject constructor(private val stringProvider: StringProvider,
|
||||
private val roomSummaryItemFactory: RoomSummaryItemFactory,
|
||||
private val roomListNameFilter: RoomListNameFilter,
|
||||
private val userPreferencesProvider: UserPreferencesProvider
|
||||
private val userPreferencesProvider: UserPreferencesProvider,
|
||||
private val scSdkPreferences: ScSdkPreferences
|
||||
) : EpoxyController() {
|
||||
|
||||
var listener: Listener? = null
|
||||
|
@ -133,12 +136,20 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
|
|||
} else {
|
||||
summaries.map { it.notificationCount }.sumBy { i -> i }
|
||||
}
|
||||
// SC addition
|
||||
val unreadMessages = if (summaries.isEmpty()) {
|
||||
0
|
||||
} else {
|
||||
// TODO actual sum of events instead of sum of chats?
|
||||
summaries.map { it.scHasUnreadMessages(scSdkPreferences) }.sumBy { b -> if (b) 1 else 0 }
|
||||
}
|
||||
val showHighlighted = summaries.any { it.highlightCount > 0 }
|
||||
roomCategoryItem {
|
||||
id(titleRes)
|
||||
title(stringProvider.getString(titleRes))
|
||||
expanded(isExpanded)
|
||||
unreadNotificationCount(unreadCount)
|
||||
unreadMessages(unreadMessages)
|
||||
showHighlighted(showHighlighted)
|
||||
listener {
|
||||
mutateExpandedState()
|
||||
|
|
|
@ -68,7 +68,8 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
|
|||
holder.titleView.text = matrixItem.getBestName()
|
||||
holder.lastEventTimeView.text = lastEventTime
|
||||
holder.lastEventView.text = lastFormattedEvent
|
||||
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
|
||||
// SC-TODO: once we count unimportant unread messages, pass that as counter - for now, unreadIndentIndicator is enough, so pass 0 to the badge instead
|
||||
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted, 0))
|
||||
holder.unreadIndentIndicator.isVisible = hasUnreadMessage
|
||||
holder.draftView.isVisible = hasDraft
|
||||
avatarRenderer.render(matrixItem, holder.avatarImageView)
|
||||
|
|
|
@ -30,22 +30,28 @@ class UnreadCounterBadgeView : AppCompatTextView {
|
|||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
||||
|
||||
fun render(state: State) {
|
||||
if (state.count == 0) {
|
||||
if (state.count == 0 && state.unread == 0) {
|
||||
visibility = View.INVISIBLE
|
||||
} else {
|
||||
visibility = View.VISIBLE
|
||||
val bgRes = if (state.highlighted) {
|
||||
R.drawable.bg_unread_highlight
|
||||
val bgRes = if (state.count > 0) {
|
||||
if (state.highlighted) {
|
||||
R.drawable.bg_unread_highlight
|
||||
} else {
|
||||
R.drawable.bg_unread_notification
|
||||
}
|
||||
} else {
|
||||
R.drawable.bg_unread_notification
|
||||
R.drawable.bg_unread_unimportant
|
||||
}
|
||||
setBackgroundResource(bgRes)
|
||||
text = RoomSummaryFormatter.formatUnreadMessagesCounter(state.count)
|
||||
text = RoomSummaryFormatter.formatUnreadMessagesCounter(if (state.count > 0) state.count else state.unread)
|
||||
}
|
||||
}
|
||||
|
||||
data class State(
|
||||
val count: Int,
|
||||
val highlighted: Boolean
|
||||
val highlighted: Boolean,
|
||||
// SC addition
|
||||
val unread: Int
|
||||
)
|
||||
}
|
||||
|
|
9
vector/src/main/res/drawable/bg_unread_unimportant.xml
Normal file
9
vector/src/main/res/drawable/bg_unread_unimportant.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners android:radius="40dp" />
|
||||
|
||||
<solid android:color="?riotx_unread_unimportant_room_badge" />
|
||||
</shape>
|
|
@ -10,6 +10,8 @@
|
|||
<attr name="riotx_positive_accent_alpha12" format="color" />
|
||||
<attr name="riotx_toolbar_bg" format="color" />
|
||||
|
||||
<attr name="riotx_unread_unimportant_room_badge" format="color" />
|
||||
|
||||
</declare-styleable>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -188,6 +188,7 @@
|
|||
<item name="riotx_positive_accent">@color/riotx_positive_accent</item>
|
||||
<item name="riotx_positive_accent_alpha12">@color/riotx_positive_accent_alpha12</item>
|
||||
<item name="riotx_toolbar_bg">?riotx_background</item>
|
||||
<item name="riotx_unread_unimportant_room_badge">@color/riotx_unread_room_badge_dark</item>
|
||||
|
||||
<item name="android:statusBarColor">@color/riotx_header_panel_background_dark</item>
|
||||
<item name="android:navigationBarColor">@color/riotx_header_panel_background_dark</item>
|
||||
|
|
|
@ -188,6 +188,7 @@
|
|||
<item name="riotx_positive_accent">@color/riotx_positive_accent</item>
|
||||
<item name="riotx_positive_accent_alpha12">@color/riotx_positive_accent_alpha12</item>
|
||||
<item name="riotx_toolbar_bg">?riotx_background</item>
|
||||
<item name="riotx_unread_unimportant_room_badge">@color/riotx_unread_room_badge_light</item>
|
||||
|
||||
<!-- Use dark color, to have enough contrast with icons color. windowLightStatusBar is only available in API 23+ -->
|
||||
<item name="android:statusBarColor">@color/riotx_header_panel_background_dark</item>
|
||||
|
|
|
@ -170,6 +170,7 @@
|
|||
<item name="riotx_positive_accent">@color/accent_sc</item>
|
||||
<item name="riotx_positive_accent_alpha12">@color/accent_sc_alpha12</item>
|
||||
<item name="riotx_toolbar_bg">?riotx_background</item>
|
||||
<item name="riotx_unread_unimportant_room_badge">@color/background_floating_sc</item>
|
||||
|
||||
<item name="android:statusBarColor">@color/background_black_sc</item>
|
||||
<item name="android:navigationBarColor">@color/background_black_sc</item>
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
<item name="riotx_positive_accent">@color/accent_sc</item>
|
||||
<item name="riotx_positive_accent_alpha12">@color/accent_sc_alpha12</item>
|
||||
<item name="riotx_toolbar_bg">?riotx_background</item>
|
||||
<item name="riotx_unread_unimportant_room_badge">?riotx_header_panel_text_secondary</item>
|
||||
|
||||
<item name="bottomSheetDialogTheme">@style/Vector.BottomSheet.SC.Light</item>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue