use of org.moire.ultrasonic.domain.Artist in project ultrasonic by ultrasonic.
the class SearchActivity method populateList.
private void populateList() {
mergeAdapter = new MergeAdapter();
mergeAdapter.addView(searchButton, true);
if (searchResult != null) {
List<Artist> artists = searchResult.getArtists();
if (!artists.isEmpty()) {
mergeAdapter.addView(artistsHeading);
List<Artist> displayedArtists = new ArrayList<Artist>(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size())));
artistAdapter = new ArtistAdapter(this, displayedArtists);
mergeAdapter.addAdapter(artistAdapter);
if (artists.size() > DEFAULT_ARTISTS) {
moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true);
}
}
List<MusicDirectory.Entry> albums = searchResult.getAlbums();
if (!albums.isEmpty()) {
mergeAdapter.addView(albumsHeading);
List<MusicDirectory.Entry> displayedAlbums = new ArrayList<MusicDirectory.Entry>(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size())));
albumAdapter = new EntryAdapter(this, getImageLoader(), displayedAlbums, false);
mergeAdapter.addAdapter(albumAdapter);
if (albums.size() > DEFAULT_ALBUMS) {
moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true);
}
}
List<MusicDirectory.Entry> songs = searchResult.getSongs();
if (!songs.isEmpty()) {
mergeAdapter.addView(songsHeading);
List<MusicDirectory.Entry> displayedSongs = new ArrayList<MusicDirectory.Entry>(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size())));
songAdapter = new EntryAdapter(this, getImageLoader(), displayedSongs, false);
mergeAdapter.addAdapter(songAdapter);
if (songs.size() > DEFAULT_SONGS) {
moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true);
}
}
boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty();
searchButton.setText(empty ? R.string.search_no_match : R.string.search_search);
}
list.setAdapter(mergeAdapter);
}
use of org.moire.ultrasonic.domain.Artist in project ultrasonic by ultrasonic.
the class SelectArtistActivity method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view == folderButton) {
selectFolder();
} else {
Artist artist = (Artist) parent.getItemAtPosition(position);
if (artist != null) {
Intent intent = new Intent(this, SelectAlbumActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
intent.putExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID, artist.getId());
intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, true);
startActivityForResultWithoutTransition(this, intent);
}
}
}
use of org.moire.ultrasonic.domain.Artist in project ultrasonic by ultrasonic.
the class SelectArtistActivity method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
if (artistListView.getItemAtPosition(info.position) instanceof Artist) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.select_artist_context, menu);
} else if (info.position == 1) {
String musicFolderId = Util.getSelectedMusicFolderId(this);
MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
if (musicFolderId == null) {
menuItem.setChecked(true);
}
if (musicFolders != null) {
for (int i = 0; i < musicFolders.size(); i++) {
MusicFolder musicFolder = musicFolders.get(i);
menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName());
if (musicFolder.getId().equals(musicFolderId)) {
menuItem.setChecked(true);
}
}
}
menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true);
}
MenuItem downloadMenuItem = menu.findItem(R.id.artist_menu_download);
if (downloadMenuItem != null) {
downloadMenuItem.setVisible(!Util.isOffline(this));
}
}
use of org.moire.ultrasonic.domain.Artist in project ultrasonic by ultrasonic.
the class OfflineMusicService method getIndexes.
@Override
public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
List<Artist> artists = new ArrayList<Artist>();
File root = FileUtil.getMusicDirectory(context);
for (File file : FileUtil.listFiles(root)) {
if (file.isDirectory()) {
Artist artist = new Artist();
artist.setId(file.getPath());
artist.setIndex(file.getName().substring(0, 1));
artist.setName(file.getName());
artists.add(artist);
}
}
String ignoredArticlesString = "The El La Los Las Le Les";
final String[] ignoredArticles = COMPILE.split(ignoredArticlesString);
Collections.sort(artists, new Comparator<Artist>() {
@Override
public int compare(Artist lhsArtist, Artist rhsArtist) {
String lhs = lhsArtist.getName().toLowerCase();
String rhs = rhsArtist.getName().toLowerCase();
char lhs1 = lhs.charAt(0);
char rhs1 = rhs.charAt(0);
if (Character.isDigit(lhs1) && !Character.isDigit(rhs1)) {
return 1;
}
if (Character.isDigit(rhs1) && !Character.isDigit(lhs1)) {
return -1;
}
for (String article : ignoredArticles) {
int index = lhs.indexOf(String.format("%s ", article.toLowerCase()));
if (index == 0) {
lhs = lhs.substring(article.length() + 1);
}
index = rhs.indexOf(String.format("%s ", article.toLowerCase()));
if (index == 0) {
rhs = rhs.substring(article.length() + 1);
}
}
return lhs.compareTo(rhs);
}
});
return new Indexes(0L, ignoredArticlesString, Collections.<Artist>emptyList(), artists);
}
use of org.moire.ultrasonic.domain.Artist 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);
}
Aggregations