Skip to content

Instantly share code, notes, and snippets.

@AOrobator
Last active December 18, 2016 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AOrobator/ad2243ac7c4d21a2f012fe84f008eee6 to your computer and use it in GitHub Desktop.
Save AOrobator/ad2243ac7c4d21a2f012fe84f008eee6 to your computer and use it in GitHub Desktop.
Implementing App Shortcuts - Updating your shortcuts
/**
* Sets the new Shortcut List by providing the three most visited
* constellations
* */
@TargetApi(N_MR1)
fun updateShortcuts(shortcutManager: ShortcutManager) {
shortcutManager.dynamicShortcuts =
Constellation
.values()
.sortedWith(compareBy { -getConstellationVisitedCount(it) })
.map {
ShortcutInfo.Builder(APP_CONTEXT, it.name)
.setShortLabel(it.shortName)
.setLongLabel(it.longName)
.setIcon(Icon.createWithResource(APP_CONTEXT, R.drawable.shortcut_icon))
.setIntents(
arrayOf(
// This intent is used for the back-stack
MainActivity.getIntent(APP_CONTEXT),
// This intent is what gets initially launched
ConstellationDetailActivity.getIntent(APP_CONTEXT, it)
)
)
.build()
}.subList(0, 3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment