Skip to content

Commit

Permalink
Improve shortcut sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dkter committed Jul 13, 2021
1 parent c9ec8d4 commit 18f915c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ package org.matrix.android.sdk.api.session.room
enum class RoomSortOrder {
NAME,
ACTIVITY,
PRIORITY_AND_ACTIVITY,
NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields

internal fun RealmQuery<RoomSummaryEntity>.process(sortOrder: RoomSortOrder): RealmQuery<RoomSummaryEntity> {
when (sortOrder) {
RoomSortOrder.NAME -> {
RoomSortOrder.NAME -> {
sort(RoomSummaryEntityFields.DISPLAY_NAME, Sort.ASCENDING)
}
RoomSortOrder.ACTIVITY -> {
RoomSortOrder.ACTIVITY -> {
sort(RoomSummaryEntityFields.LAST_ACTIVITY_TIME, Sort.DESCENDING)
}
RoomSortOrder.NONE -> {
RoomSortOrder.PRIORITY_AND_ACTIVITY -> {
sort(
arrayOf(
RoomSummaryEntityFields.IS_FAVOURITE,
RoomSummaryEntityFields.IS_LOW_PRIORITY,
RoomSummaryEntityFields.LAST_ACTIVITY_TIME),
arrayOf(Sort.DESCENDING, Sort.ASCENDING, Sort.DESCENDING))
}
RoomSortOrder.NONE -> {
}
}
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.core.content.pm.ShortcutManagerCompat
import im.vector.app.core.di.ActiveSessionHolder
import io.reactivex.disposables.Disposable
import io.reactivex.disposables.Disposables
import org.matrix.android.sdk.api.session.room.RoomSortOrder
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.rx.asObservable
Expand All @@ -45,7 +46,8 @@ class ShortcutsHandler @Inject constructor(
?.getPagedRoomSummariesLive(
roomSummaryQueryParams {
memberships = listOf(Membership.JOIN)
}
},
sortOrder = RoomSortOrder.PRIORITY_AND_ACTIVITY
)
?.asObservable()
?.subscribe { rooms ->
Expand All @@ -57,13 +59,7 @@ class ShortcutsHandler @Inject constructor(
ShortcutManagerCompat.removeLongLivedShortcuts(context, deadShortcutIds)

val shortcuts = rooms
.sortedBy { room ->
// pushDynamicShortcut adds each shortcut to the top of the shortcut ranking,
// so higher priority rooms should be at the end of this list to get pushed on last.
if (room.isFavorite) 2
else if (room.isLowPriority) 0
else 1
}
.asReversed()
.map { shortcutCreator.create(it) }

shortcuts.forEach { shortcut ->
Expand Down

0 comments on commit 18f915c

Please sign in to comment.