diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/read/ReadService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/read/ReadService.kt index 55e844681f..c501553f52 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/read/ReadService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/read/ReadService.kt @@ -49,7 +49,7 @@ interface ReadService { /** * Mark a room as unread, or remove an existing unread marker. */ - fun setMarkedUnread(markedUnread: Boolean, callback: MatrixCallback) + suspend fun setMarkedUnread(markedUnread: Boolean) /** * Check if an event is already read, ie. your read receipt is set on a more recent event. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomAggregateNotificationCount.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomAggregateNotificationCount.kt index 066178b1ec..b11cbe6e46 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomAggregateNotificationCount.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomAggregateNotificationCount.kt @@ -18,8 +18,11 @@ package org.matrix.android.sdk.api.session.room.summary data class RoomAggregateNotificationCount( val notificationCount: Int, - val highlightCount: Int + val highlightCount: Int, + val unreadCount: Int, + val markedUnreadCount: Int ) { - val totalCount = notificationCount + highlightCount + val totalCount = notificationCount + highlightCount + markedUnreadCount val isHighlight = highlightCount > 0 + val markedUnread = markedUnreadCount > 0 } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt index 8cabaf2dc2..eea356be5f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt @@ -59,7 +59,7 @@ internal class DefaultReadService @AssistedInject constructor( ) setReadMarkersTask.execute(taskParams) // Automatically unset unread marker - setMarkedUnreadFlag(false, callback) + setMarkedUnreadFlag(false) } override suspend fun setReadReceipt(eventId: String) { @@ -72,23 +72,19 @@ internal class DefaultReadService @AssistedInject constructor( setReadMarkersTask.execute(params) } - override fun setMarkedUnread(markedUnread: Boolean, callback: MatrixCallback) { + override suspend fun setMarkedUnread(markedUnread: Boolean) { if (markedUnread) { - setMarkedUnreadFlag(true, callback) + setMarkedUnreadFlag(true) } else { // We want to both remove unread marker and update read receipt position, // i.e., we want what markAsRead does - markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, callback) + markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) } } - private fun setMarkedUnreadFlag(markedUnread: Boolean, callback: MatrixCallback) { + private suspend fun setMarkedUnreadFlag(markedUnread: Boolean) { val params = SetMarkedUnreadTask.Params(roomId, markedUnread = markedUnread) - setMarkedUnreadTask - .configureWith(params) { - this.callback = callback - } - .executeBy(taskExecutor) + setMarkedUnreadTask.execute(params) } override fun isEventRead(eventId: String): Boolean { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetMarkedUnreadTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetMarkedUnreadTask.kt index e5b0d8a7aa..075c2b50a3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetMarkedUnreadTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetMarkedUnreadTask.kt @@ -54,9 +54,8 @@ internal class DefaultSetMarkedUnreadTask @Inject constructor( if (isMarkedUnread(monarchy.realmConfiguration, params.roomId) != params.markedUnread) { updateDatabase(params.roomId, params.markedUnread) - executeRequest(globalErrorReceiver) { - isRetryable = true - apiCall = accountDataApi.setRoomAccountData(userId, params.roomId, EventType.MARKED_UNREAD, params.markedUnreadContent) + executeRequest(globalErrorReceiver, canRetry = true) { + accountDataApi.setRoomAccountData(userId, params.roomId, EventType.MARKED_UNREAD, params.markedUnreadContent) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index dd3fbe04b2..f3a8509281 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotification import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.toOptional import org.matrix.android.sdk.internal.database.mapper.RoomSummaryMapper +import org.matrix.android.sdk.internal.database.model.RoomEntityFields import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields import org.matrix.android.sdk.internal.database.query.findByAlias @@ -152,9 +153,14 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat val roomSummariesQuery = roomSummariesQuery(realm, queryParams) val notifCount = roomSummariesQuery.sum(RoomSummaryEntityFields.NOTIFICATION_COUNT).toInt() val highlightCount = roomSummariesQuery.sum(RoomSummaryEntityFields.HIGHLIGHT_COUNT).toInt() + // TODO-SC-merge: respect setting for selecting right field here (HAS_UNREAD_CONTENT_MESSAGES, HAS_UNREAD_MESSAGES, HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES) + val unreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES, true).count().toInt() + val markedUnreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.MARKED_UNREAD, true).count().toInt() notificationCount = RoomAggregateNotificationCount( notifCount, - highlightCount + highlightCount, + unreadCount, + markedUnreadCount ) } return notificationCount!! diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt index edd52be65f..041cec85e1 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt @@ -128,6 +128,7 @@ abstract class BaseEventItem : VectorEpoxyModel @CallSuper open fun setBubbleLayout(holder: H, bubbleStyle: String, bubbleStyleSetting: String, reverseBubble: Boolean) { + /* TODO-SC-merge: read receipt layout alignment val defaultDirection = holder.readReceiptsView.resources.configuration.layoutDirection; val defaultRtl = defaultDirection == View.LAYOUT_DIRECTION_RTL val reverseDirection = if (defaultRtl) View.LAYOUT_DIRECTION_LTR else View.LAYOUT_DIRECTION_RTL @@ -156,6 +157,7 @@ abstract class BaseEventItem : VectorEpoxyModel // Also set rtl to have members fill from the natural side setFlatRtl(holder.readReceiptsView, if (dualBubbles) reverseDirection else defaultDirection, defaultDirection) + */ } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index a22812cc98..090c1a1fdc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -99,12 +99,6 @@ class RoomListFragment @Inject constructor( private val adapterInfosList = mutableListOf() private var concatAdapter : ConcatAdapter? = null - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - context?.let { roomListViewModel.initWithContext(it, roomListParams.displayMode) } - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) views.stateView.contentView = views.roomListView @@ -166,9 +160,11 @@ class RoomListFragment @Inject constructor( override fun onPause() { super.onPause() + /* TODO-SC-merge: remember expand state for priority headers withState(roomListViewModel) { state -> context?.let { state.persistWithContext(it, roomListParams.displayMode) } } + */ } override fun showFailure(throwable: Throwable) { @@ -281,7 +277,9 @@ class RoomListFragment @Inject constructor( section.notificationCount.observe(viewLifecycleOwner) { counts -> sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( notificationCount = counts.totalCount, - isHighlighted = counts.isHighlight + isHighlighted = counts.isHighlight, + unread = counts.unreadCount, + markedUnread = counts.markedUnread )) } section.isExpanded.observe(viewLifecycleOwner) { _ -> diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index 22a585dfb3..21c03a9c67 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -98,6 +98,7 @@ class RoomListViewModel @Inject constructor( it.roomTagQueryFilter = RoomTagQueryFilter(true, null, null) } + // TODO-SC why no low priority? addSection(sections, R.string.bottom_action_people_x) { it.memberships = listOf(Membership.JOIN) it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM @@ -155,19 +156,31 @@ class RoomListViewModel @Inject constructor( it.memberships = listOf(Membership.JOIN) it.roomCategoryFilter = RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS } + } else if (initialState.displayMode == RoomListDisplayMode.ALL) { + addSection(sections, R.string.invitations_header, true) { + it.memberships = listOf(Membership.INVITE) + } + addSection(sections, R.string.bottom_action_favourites) { + it.memberships = listOf(Membership.JOIN) + it.roomTagQueryFilter = RoomTagQueryFilter(true, null, null) + } + addSection(sections, R.string.normal_priority_header) { + it.memberships = listOf(Membership.JOIN) + it.roomTagQueryFilter = RoomTagQueryFilter(false, false, false) + } + addSection(sections, R.string.low_priority_header) { + it.memberships = listOf(Membership.JOIN) + it.roomTagQueryFilter = RoomTagQueryFilter(null, true, null) + } + addSection(sections, R.string.system_alerts_header) { + it.memberships = listOf(Membership.JOIN) + it.roomTagQueryFilter = RoomTagQueryFilter(null, null, true) + } } sections } - fun initWithContext(context: Context, displayMode: RoomListDisplayMode) { - vectorPreferences = VectorPreferences(context) - setState { - // RoomListViewState.initWithContext - this.initWithContext(context, displayMode) - } - } - override fun handle(action: RoomListAction) { when (action) { is RoomListAction.SelectRoom -> handleSelectRoom(action) @@ -362,15 +375,16 @@ class RoomListViewModel @Inject constructor( } private fun handleSetMarkedUnread(action: RoomListAction.SetMarkedUnread) { - session.getRoom(action.roomId)?.setMarkedUnread(action.markedUnread, object : MatrixCallback { - override fun onSuccess(data: Unit) { - _viewEvents.post(RoomListViewEvents.Done) + val room = session.getRoom(action.roomId) + if (room != null) { + viewModelScope.launch { + try { + room.setMarkedUnread(action.markedUnread) + } catch (failure: Exception) { + _viewEvents.post(RoomListViewEvents.Failure(failure)) + } } - - override fun onFailure(failure: Throwable) { - _viewEvents.post(RoomListViewEvents.Failure(failure)) - } - }) + } } private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomsSection.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomsSection.kt index 71b7169814..90bbe71b6c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomsSection.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomsSection.kt @@ -26,6 +26,6 @@ data class RoomsSection( val sectionName: String, val livePages: LiveData>, val isExpanded: MutableLiveData = MutableLiveData(true), - val notificationCount: MutableLiveData = MutableLiveData(RoomAggregateNotificationCount(0, 0)), + val notificationCount: MutableLiveData = MutableLiveData(RoomAggregateNotificationCount(0, 0, 0, 0)), val notifyOfLocalEcho: Boolean = false ) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt index f9c5766821..3158bf5e96 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt @@ -35,7 +35,10 @@ class SectionHeaderAdapter constructor( val isExpanded: Boolean = true, val notificationCount: Int = 0, val isHighlighted: Boolean = false, - val isHidden: Boolean = true + val isHidden: Boolean = true, + // SC additions + val unread: Int = 0, + val markedUnread: Boolean = true ) lateinit var roomsSectionData: RoomsSectionData @@ -84,7 +87,7 @@ class SectionHeaderAdapter constructor( val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also { DrawableCompat.setTint(it, tintColor) } - binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted)) + binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted, roomsSectionData.unread, roomsSectionData.markedUnread)) binding.roomCategoryTitleView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null) } diff --git a/vector/src/main/java/im/vector/app/features/themes/ActivityOtherThemes.kt b/vector/src/main/java/im/vector/app/features/themes/ActivityOtherThemes.kt index 4b0dc5e9d4..6c0c165f96 100644 --- a/vector/src/main/java/im/vector/app/features/themes/ActivityOtherThemes.kt +++ b/vector/src/main/java/im/vector/app/features/themes/ActivityOtherThemes.kt @@ -45,7 +45,13 @@ sealed class ActivityOtherThemes(@StyleRes val light: Int, object Launcher : ActivityOtherThemes( R.style.AppTheme_Launcher, - R.style.AppTheme_Launcher + R.style.AppTheme_Launcher, + R.style.AppTheme_Launcher, + R.style.AppTheme_Launcher_SC, + R.style.AppTheme_Launcher_SC, + R.style.AppTheme_Launcher_SC, + R.style.AppTheme_Launcher_SC, + R.style.AppTheme_Launcher_SC, ) object AttachmentsPreview : ActivityOtherThemes(