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
shortcutAction { | |
trackShortcutUsed(it, constellation) | |
} |
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
@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 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 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 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 playlist: Playlist = ... | |
val song: Song = ... | |
// This is a bug, but the compiler allows it! | |
playlistRepository.addSongToPlaylist(songId = playlist.id, playlistId = song.id) |
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
data class SongId(id: Long) | |
data class PlaylistId(id: Long) |
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
interface PlaylistRepository: Repository { | |
fun addSongToPlaylist(songId: SongId, playlistId: PlaylistId) | |
} |
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
// Compiler doesn’t like this. Red squigglies everywhere. | |
playlistRepository.addSongToPlaylist(songId = PlaylistId(420L), playlistId = SongId(9001L)) |
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
data class SongId(id: Long) | |
val Song.typedId: SongId = SongId(this.id) | |
data class PlaylistId(id: Long) | |
val Playlist.typedId: PlaylistId = PlaylistId(this.id) |
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
val song: Song = ... | |
val playlist: Playlist = ... | |
playlistRepository.addSongToPlaylist(song.typedId, playlist.typedId) |