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:
David Teresi 2021-07-05 14:12:49 -04:00
parent f843712d7e
commit 69d0ed3fb8
3 changed files with 18 additions and 6 deletions

View File

@ -17,6 +17,7 @@
package im.vector.app.features.home package im.vector.app.features.home
import android.content.Context import android.content.Context
import android.content.pm.ShortcutInfo
import android.graphics.Bitmap import android.graphics.Bitmap
import android.os.Build import android.os.Build
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
@ -67,9 +68,12 @@ class ShortcutCreator @Inject constructor(
.setShortLabel(roomSummary.displayName) .setShortLabel(roomSummary.displayName)
.setIcon(bitmap?.toProfileImageIcon()) .setIcon(bitmap?.toProfileImageIcon())
.setIntent(intent) .setIntent(intent)
.setLongLived(true)
// Make it show up in the direct share menu // Make it show up in the direct share menu
.setCategories(setOf(directShareCategory)) .setCategories(setOf(
directShareCategory,
ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION))
.build() .build()
} }

View File

@ -24,7 +24,6 @@ import androidx.core.content.pm.ShortcutManagerCompat
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.disposables.Disposables 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.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.rx.asObservable import org.matrix.android.sdk.rx.asObservable
@ -46,17 +45,23 @@ class ShortcutsHandler @Inject constructor(
?.getPagedRoomSummariesLive( ?.getPagedRoomSummariesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
roomTagQueryFilter = RoomTagQueryFilter(isFavorite = true, null, null)
} }
) )
?.asObservable() ?.asObservable()
?.subscribe { rooms -> ?.subscribe { rooms ->
val shortcuts = 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) } .map { shortcutCreator.create(it) }
ShortcutManagerCompat.removeAllDynamicShortcuts(context) shortcuts.forEach { shortcut ->
ShortcutManagerCompat.addDynamicShortcuts(context, shortcuts) ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
}
} }
?: Disposables.empty() ?: Disposables.empty()
} }

View File

@ -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) // that can be displayed in not disturb mode if white listed (the later will need compat28.x)
.setCategory(NotificationCompat.CATEGORY_MESSAGE) .setCategory(NotificationCompat.CATEGORY_MESSAGE)
// ID of the corresponding shortcut, for conversation features under API 30+
.setShortcutId(roomInfo.roomId)
// Title for API < 16 devices. // Title for API < 16 devices.
.setContentTitle(roomInfo.roomDisplayName) .setContentTitle(roomInfo.roomDisplayName)
// Content for API < 16 devices. // Content for API < 16 devices.