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) |
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
// 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
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
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
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
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
@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 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 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) | |
} | |
} |