This file contains hidden or 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
| interface PlaylistRepository: Repository { | |
| fun addSongToPlaylist(songId: Long, playlistId: Long) | |
| } |
This file contains hidden or 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
| public class MainActivity extends Activity { | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); | |
| if (shortcutManager.getDynamicShortcuts().size() == 0) { | |
| // Application restored. Need to re-publish dynamic shortcuts. | |
| if (shortcutManager.getPinnedShortcuts().size() > 0) { | |
| // Pinned shortcuts have been restored. Use | |
| // updateShortcuts(List) to make sure they | |
| // contain up-to-date information. |
This file contains hidden or 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
| @TargetApi(N_MR1) | |
| fun trackShortcutUsed(shortcutManager: ShortcutManager, constellation: Constellation) { | |
| shortcutManager.reportShortcutUsed(constellation.name) | |
| val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(APP_CONTEXT) | |
| val seenCount = sharedPrefs.getInt(constellation.name, 0) | |
| sharedPrefs | |
| .edit() | |
| .putInt(constellation.name, seenCount + 1) | |
| .apply() | |
| updateShortcuts(shortcutManager) |
This file contains hidden or 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
| shortcutAction { | |
| trackShortcutUsed(it, constellation) | |
| } |
This file contains hidden or 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
| @TargetApi(N_MR1) | |
| override fun onOptionsItemSelected(item: MenuItem): Boolean { | |
| when (item.itemId) { | |
| R.id.enable_shortcut -> shortcutAction { | |
| it.enableShortcuts(listOf(constellation.name)) | |
| alertUser(R.string.shortcut_enabled) | |
| } | |
| R.id.disable_shortcut -> shortcutAction { | |
| it.disableShortcuts(listOf(constellation.name)) | |
| alertUser(R.string.shortcut_disabled) |
This file contains hidden or 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) }) |
This file contains hidden or 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
| inline fun shortcutAction(action: (ShortcutManager) -> Unit): Unit { | |
| if (SDK_INT >= N_MR1) { | |
| val shortcutManager = APP_CONTEXT.getSystemService(ShortcutManager::class.java) | |
| action(shortcutManager) | |
| } | |
| } |
This file contains hidden or 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
| val shortcutManager = context.getSystemService(ShortcutManager::class.java) |
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> | |
| <shortcut | |
| android:enabled="true" | |
| android:icon="@drawable/random_constellation" | |
| android:shortcutDisabledMessage="@string/shortcut_disabled_message" | |
| android:shortcutId="random_constellation" | |
| android:shortcutLongLabel="@string/shortcut_long_label" | |
| android:shortcutShortLabel="@string/shortcut_short_label"> | |
| <!-- Each one of these intents needs an android:action, even if you don't |
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| package="com.orobator.konstellations"> | |
| <application | |
| android:name=".KonstellationsApplication" | |
| android:allowBackup="true" | |
| android:icon="@drawable/app_icon" | |
| android:label="@string/app_name" | |
| android:supportsRtl="true" |