playback: immprove search error cases
This commit is contained in:
parent
a712a773b0
commit
130d30c70d
1 changed files with 19 additions and 12 deletions
|
@ -219,7 +219,7 @@ constructor(
|
||||||
return commandFactory.all(ShuffleMode.ON)
|
return commandFactory.all(ShuffleMode.ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
val bestCommand = when (extras.getString(MediaStore.EXTRA_MEDIA_FOCUS)) {
|
when (extras.getString(MediaStore.EXTRA_MEDIA_FOCUS)) {
|
||||||
MediaStore.Audio.Media.ENTRY_CONTENT_TYPE -> {
|
MediaStore.Audio.Media.ENTRY_CONTENT_TYPE -> {
|
||||||
val songQuery = extras.getString(MediaStore.EXTRA_MEDIA_TITLE)
|
val songQuery = extras.getString(MediaStore.EXTRA_MEDIA_TITLE)
|
||||||
val albumQuery = extras.getString(MediaStore.EXTRA_MEDIA_ALBUM)
|
val albumQuery = extras.getString(MediaStore.EXTRA_MEDIA_ALBUM)
|
||||||
|
@ -228,7 +228,9 @@ constructor(
|
||||||
fuzzy(it.name, songQuery) + fuzzy(it.album.name, albumQuery) +
|
fuzzy(it.name, songQuery) + fuzzy(it.album.name, albumQuery) +
|
||||||
it.artists.maxOf { artist -> fuzzy(artist.name, artistQuery) }
|
it.artists.maxOf { artist -> fuzzy(artist.name, artistQuery) }
|
||||||
}
|
}
|
||||||
best?.let { commandFactory.song(it, ShuffleMode.IMPLICIT) }
|
if (best != null) {
|
||||||
|
return expandSongIntoCommand(best, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE -> {
|
MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE -> {
|
||||||
|
@ -237,37 +239,42 @@ constructor(
|
||||||
val best = deviceLibrary.albums.maxByOrNull {
|
val best = deviceLibrary.albums.maxByOrNull {
|
||||||
fuzzy(it.name, albumQuery) + it.artists.maxOf { artist -> fuzzy(artist.name, artistQuery) }
|
fuzzy(it.name, albumQuery) + it.artists.maxOf { artist -> fuzzy(artist.name, artistQuery) }
|
||||||
}
|
}
|
||||||
best?.let { commandFactory.album(it, ShuffleMode.OFF) }
|
if (best != null) {
|
||||||
|
return commandFactory.album(best, ShuffleMode.OFF)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE -> {
|
MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE -> {
|
||||||
val artistQuery = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST)
|
val artistQuery = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST)
|
||||||
val best = deviceLibrary.artists.maxByOrNull { fuzzy(it.name, artistQuery) }
|
val best = deviceLibrary.artists.maxByOrNull { fuzzy(it.name, artistQuery) }
|
||||||
best?.let { commandFactory.artist(it, ShuffleMode.OFF) }
|
if (best != null) {
|
||||||
|
return commandFactory.artist(best, ShuffleMode.OFF)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaStore.Audio.Genres.ENTRY_CONTENT_TYPE -> {
|
MediaStore.Audio.Genres.ENTRY_CONTENT_TYPE -> {
|
||||||
val genreQuery = extras.getString(MediaStore.EXTRA_MEDIA_GENRE)
|
val genreQuery = extras.getString(MediaStore.EXTRA_MEDIA_GENRE)
|
||||||
val best = deviceLibrary.genres.maxByOrNull { fuzzy(it.name, genreQuery) }
|
val best = deviceLibrary.genres.maxByOrNull { fuzzy(it.name, genreQuery) }
|
||||||
best?.let { commandFactory.genre(it, ShuffleMode.OFF) }
|
if (best != null) {
|
||||||
|
return commandFactory.genre(best, ShuffleMode.OFF)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE -> {
|
MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE -> {
|
||||||
val playlistQuery = extras.getString(MediaStore.EXTRA_MEDIA_PLAYLIST)
|
val playlistQuery = extras.getString(MediaStore.EXTRA_MEDIA_PLAYLIST)
|
||||||
val best = userLibrary.playlists.maxByOrNull { fuzzy(it.name, playlistQuery) }
|
val best = userLibrary.playlists.maxByOrNull { fuzzy(it.name, playlistQuery) }
|
||||||
best?.let { commandFactory.playlist(it, ShuffleMode.OFF) }
|
if (best != null) {
|
||||||
|
return commandFactory.playlist(best, ShuffleMode.OFF)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> null
|
else -> {}
|
||||||
}
|
|
||||||
|
|
||||||
if (bestCommand != null) {
|
|
||||||
return bestCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val bestMusic = (deviceLibrary.songs + deviceLibrary.albums + deviceLibrary.artists + deviceLibrary.genres + userLibrary.playlists)
|
val bestMusic = (deviceLibrary.songs + deviceLibrary.albums + deviceLibrary.artists + deviceLibrary.genres + userLibrary.playlists)
|
||||||
.maxByOrNull { fuzzy(it.name, query) }
|
.maxByOrNull { fuzzy(it.name, query) }
|
||||||
return bestMusic?.let { expandMusicIntoCommand(it, null) }
|
// TODO: Error out when we can't correctly resolve the query
|
||||||
|
return bestMusic?.let { expandMusicIntoCommand(it, null) } ?: commandFactory.all(ShuffleMode.ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fuzzy(name: Name, query: String?): Double =
|
private fun fuzzy(name: Name, query: String?): Double =
|
||||||
|
|
Loading…
Reference in a new issue