Skip to content

Commit

Permalink
Insert room shortcuts in order
Browse files Browse the repository at this point in the history
This prevents shortcuts from momentarily being shown out of order while
the shortcut list is in the process of being updated.
  • Loading branch information
dkter committed Aug 25, 2021
1 parent 842ccb1 commit 2004d35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ShortcutCreator @Inject constructor(
}

@WorkerThread
fun create(roomSummary: RoomSummary): ShortcutInfoCompat {
fun create(roomSummary: RoomSummary, rank: Int = 1): ShortcutInfoCompat {
val intent = RoomDetailActivity.shortcutIntent(context, roomSummary.roomId)
val bitmap = try {
avatarRenderer.shortcutDrawable(GlideApp.with(context), roomSummary.toMatrixItem(), iconSize)
Expand All @@ -70,6 +70,7 @@ class ShortcutCreator @Inject constructor(
.setIcon(bitmap?.toProfileImageIcon())
.setIntent(intent)
.setLongLived(true)
.setRank(rank)

// Make it show up in the direct share menu
.setCategories(setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class ShortcutsHandler @Inject constructor(
.filter { !roomIds.contains(it) }
ShortcutManagerCompat.removeLongLivedShortcuts(context, deadShortcutIds)

val shortcuts = rooms
.asReversed()
.map { shortcutCreator.create(it) }
val shortcuts = rooms.mapIndexed { index, room ->
shortcutCreator.create(room, index)
}

shortcuts.forEach { shortcut ->
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
Expand Down

0 comments on commit 2004d35

Please sign in to comment.