Improve shortcut sorting

This commit is contained in:
David Teresi 2021-07-12 21:21:31 -04:00
parent 4af58dde74
commit 842ccb12b2
3 changed files with 16 additions and 11 deletions

View file

@ -19,5 +19,6 @@ package org.matrix.android.sdk.api.session.room
enum class RoomSortOrder {
NAME,
ACTIVITY,
PRIORITY_AND_ACTIVITY,
NONE
}

View file

@ -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

View file

@ -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
@ -45,7 +46,8 @@ class ShortcutsHandler @Inject constructor(
?.getPagedRoomSummariesLive(
roomSummaryQueryParams {
memberships = listOf(Membership.JOIN)
}
},
sortOrder = RoomSortOrder.PRIORITY_AND_ACTIVITY
)
?.asObservable()
?.subscribe { rooms ->
@ -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 ->