use of org.moire.ultrasonic.domain.SearchResult in project ultrasonic by ultrasonic.
the class OfflineMusicService method search.
@Override
public SearchResult search(SearchCriteria criteria, Context context, ProgressListener progressListener) throws Exception {
List<Artist> artists = new ArrayList<Artist>();
List<MusicDirectory.Entry> albums = new ArrayList<MusicDirectory.Entry>();
List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
File root = FileUtil.getMusicDirectory(context);
int closeness;
for (File artistFile : FileUtil.listFiles(root)) {
String artistName = artistFile.getName();
if (artistFile.isDirectory()) {
if ((closeness = matchCriteria(criteria, artistName)) > 0) {
Artist artist = new Artist();
artist.setId(artistFile.getPath());
artist.setIndex(artistFile.getName().substring(0, 1));
artist.setName(artistName);
artist.setCloseness(closeness);
artists.add(artist);
}
recursiveAlbumSearch(artistName, artistFile, criteria, context, albums, songs);
}
}
Collections.sort(artists, new Comparator<Artist>() {
@Override
public int compare(Artist lhs, Artist rhs) {
if (lhs.getCloseness() == rhs.getCloseness()) {
return 0;
} else
return lhs.getCloseness() > rhs.getCloseness() ? -1 : 1;
}
});
Collections.sort(albums, new Comparator<MusicDirectory.Entry>() {
@Override
public int compare(MusicDirectory.Entry lhs, MusicDirectory.Entry rhs) {
if (lhs.getCloseness() == rhs.getCloseness()) {
return 0;
} else
return lhs.getCloseness() > rhs.getCloseness() ? -1 : 1;
}
});
Collections.sort(songs, new Comparator<MusicDirectory.Entry>() {
@Override
public int compare(MusicDirectory.Entry lhs, MusicDirectory.Entry rhs) {
if (lhs.getCloseness() == rhs.getCloseness()) {
return 0;
} else
return lhs.getCloseness() > rhs.getCloseness() ? -1 : 1;
}
});
return new SearchResult(artists, albums, songs);
}
use of org.moire.ultrasonic.domain.SearchResult in project ultrasonic by ultrasonic.
the class SearchActivity method search.
private void search(final String query, final boolean autoplay) {
final int maxArtists = Util.getMaxArtists(this);
final int maxAlbums = Util.getMaxAlbums(this);
final int maxSongs = Util.getMaxSongs(this);
BackgroundTask<SearchResult> task = new TabActivityBackgroundTask<SearchResult>(this, true) {
@Override
protected SearchResult doInBackground() throws Throwable {
SearchCriteria criteria = new SearchCriteria(query, maxArtists, maxAlbums, maxSongs);
MusicService service = MusicServiceFactory.getMusicService(SearchActivity.this);
licenseValid = service.isLicenseValid(SearchActivity.this, this);
return service.search(criteria, SearchActivity.this, this);
}
@Override
protected void done(SearchResult result) {
searchResult = result;
populateList();
if (autoplay) {
autoplay();
}
}
};
task.execute();
}
Aggregations