Limit the number of pushed shortcuts

This commit is contained in:
Benoit Marty 2021-11-05 12:48:27 +01:00
parent 83897dda4e
commit d5e7a8542b

View file

@ -41,6 +41,7 @@ class ShortcutsHandler @Inject constructor(
private val pinCodeStore: PinCodeStore
) : PinCodeStoreListener {
private val isRequestPinShortcutSupported = ShortcutManagerCompat.isRequestPinShortcutSupported(context)
private val maxShortcutCountPerActivity = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context)
// Value will be set correctly if necessary
private var hasPinCode = true
@ -93,9 +94,11 @@ class ShortcutsHandler @Inject constructor(
// No shortcut in this case (privacy)
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
} else {
val shortcuts = rooms.mapIndexed { index, room ->
shortcutCreator.create(room, index)
}
val shortcuts = rooms
.take(maxShortcutCountPerActivity)
.mapIndexed { index, room ->
shortcutCreator.create(room, index)
}
shortcuts.forEach { shortcut ->
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)