diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-11-23 21:52:29 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-11-23 21:52:29 -0800 |
commit | e9fc1f04ed660a050896a43425a12fac5908f822 (patch) | |
tree | 25913a632350e41ae9d3f317868f80c35c3317ab /app/src/main/java | |
parent | d2003fd40e3d87e3ea9af1d30774a04e520e997f (diff) | |
download | dsub-e9fc1f04ed660a050896a43425a12fac5908f822.tar.gz dsub-e9fc1f04ed660a050896a43425a12fac5908f822.tar.bz2 dsub-e9fc1f04ed660a050896a43425a12fac5908f822.zip |
Work on getting search results to auto play better if case is different or off by a single letter
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java index 7072408a..ce36eea6 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java @@ -42,6 +42,7 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O private static final int MAX_ARTISTS = 10; private static final int MAX_ALBUMS = 10; private static final int MAX_SONGS = 25; + private static final int MIN_CLOSENESS = 1; protected RecyclerView recyclerView; protected SearchAdapter adapter; @@ -265,13 +266,27 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O } private void autoplay(String query) { - Artist artist = searchResult.getArtists().isEmpty() ? null : searchResult.getArtists().get(0); - MusicDirectory.Entry album = searchResult.getAlbums().isEmpty() ? null : searchResult.getAlbums().get(0); - MusicDirectory.Entry song = searchResult.getSongs().isEmpty() ? null : searchResult.getSongs().get(0); - - if(artist != null && query.equals(artist.getName())) { + query = query.toLowerCase(); + + Artist artist = null; + if(!searchResult.getArtists().isEmpty()) { + artist = searchResult.getArtists().get(0); + artist.setCloseness(Util.getStringDistance(artist.getName().toLowerCase(), query)); + } + MusicDirectory.Entry album = null; + if(!searchResult.getAlbums().isEmpty()) { + album = searchResult.getAlbums().get(0); + album.setCloseness(Util.getStringDistance(album.getTitle().toLowerCase(), query)); + } + MusicDirectory.Entry song = null; + if(!searchResult.getSongs().isEmpty()) { + song = searchResult.getSongs().get(0); + song.setCloseness(Util.getStringDistance(song.getTitle().toLowerCase(), query)); + } + + if(artist != null && artist.getCloseness() <= MIN_CLOSENESS) { onArtistSelected(artist, true); - } else if(album != null && query.equals(album.getTitle())) { + } else if(album != null && album.getCloseness() <= MIN_CLOSENESS) { onAlbumSelected(album, true); } else if(song != null) { onSongSelected(song, false, false, true, false); |