Last active
December 18, 2016 23:55
-
-
Save AOrobator/ad2243ac7c4d21a2f012fe84f008eee6 to your computer and use it in GitHub Desktop.
Implementing App Shortcuts - Updating your shortcuts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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