Support Android 11 Conversation features
Instead of only favorite rooms having shortcuts, all rooms now have shortcuts and they are ranked according to favorite/normal/low-priority status.
This commit is contained in:
parent
f843712d7e
commit
69d0ed3fb8
|
@ -17,6 +17,7 @@
|
|||
package im.vector.app.features.home
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import androidx.annotation.WorkerThread
|
||||
|
@ -67,9 +68,12 @@ class ShortcutCreator @Inject constructor(
|
|||
.setShortLabel(roomSummary.displayName)
|
||||
.setIcon(bitmap?.toProfileImageIcon())
|
||||
.setIntent(intent)
|
||||
.setLongLived(true)
|
||||
|
||||
// Make it show up in the direct share menu
|
||||
.setCategories(setOf(directShareCategory))
|
||||
.setCategories(setOf(
|
||||
directShareCategory,
|
||||
ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION))
|
||||
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ 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.query.RoomTagQueryFilter
|
||||
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
|
||||
|
@ -46,17 +45,23 @@ class ShortcutsHandler @Inject constructor(
|
|||
?.getPagedRoomSummariesLive(
|
||||
roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.JOIN)
|
||||
roomTagQueryFilter = RoomTagQueryFilter(isFavorite = true, null, null)
|
||||
}
|
||||
)
|
||||
?.asObservable()
|
||||
?.subscribe { rooms ->
|
||||
val shortcuts = rooms
|
||||
.take(n = 4) // Android only allows us to create 4 shortcuts
|
||||
.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
|
||||
}
|
||||
.map { shortcutCreator.create(it) }
|
||||
|
||||
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
|
||||
ShortcutManagerCompat.addDynamicShortcuts(context, shortcuts)
|
||||
shortcuts.forEach { shortcut ->
|
||||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
||||
}
|
||||
}
|
||||
?: Disposables.empty()
|
||||
}
|
||||
|
|
|
@ -550,6 +550,9 @@ class NotificationUtils @Inject constructor(private val context: Context,
|
|||
// that can be displayed in not disturb mode if white listed (the later will need compat28.x)
|
||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||
|
||||
// ID of the corresponding shortcut, for conversation features under API 30+
|
||||
.setShortcutId(roomInfo.roomId)
|
||||
|
||||
// Title for API < 16 devices.
|
||||
.setContentTitle(roomInfo.roomDisplayName)
|
||||
// Content for API < 16 devices.
|
||||
|
|
Loading…
Reference in New Issue