Search in sources :

Example 1 with ArtistAdapter

use of org.moire.ultrasonic.view.ArtistAdapter 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);
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) ArtistAdapter(org.moire.ultrasonic.view.ArtistAdapter) MergeAdapter(org.moire.ultrasonic.util.MergeAdapter) EntryAdapter(org.moire.ultrasonic.view.EntryAdapter) ArrayList(java.util.ArrayList)

Example 2 with ArtistAdapter

use of org.moire.ultrasonic.view.ArtistAdapter in project ultrasonic by ultrasonic.

the class SelectArtistActivity method load.

private void load() {
    BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this, true) {

        @Override
        protected Indexes doInBackground() throws Throwable {
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this);
            boolean isOffline = Util.isOffline(SelectArtistActivity.this);
            boolean useId3Tags = Util.getShouldUseId3Tags(SelectArtistActivity.this);
            if (!isOffline && !useId3Tags) {
                musicFolders = musicService.getMusicFolders(refresh, SelectArtistActivity.this, this);
            }
            String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
            return !isOffline && useId3Tags ? musicService.getArtists(refresh, SelectArtistActivity.this, this) : musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this);
        }

        @Override
        protected void done(Indexes result) {
            if (result != null) {
                List<Artist> artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
                artists.addAll(result.getShortcuts());
                artists.addAll(result.getArtists());
                artistListView.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists));
            }
            // Display selected music folder
            if (musicFolders != null) {
                String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
                if (musicFolderId == null) {
                    if (folderName != null) {
                        folderName.setText(R.string.select_artist_all_folders);
                    }
                } else {
                    for (MusicFolder musicFolder : musicFolders) {
                        if (musicFolder.getId().equals(musicFolderId)) {
                            if (folderName != null) {
                                folderName.setText(musicFolder.getName());
                            }
                            break;
                        }
                    }
                }
            }
        }
    };
    task.execute();
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) ArtistAdapter(org.moire.ultrasonic.view.ArtistAdapter) ArrayList(java.util.ArrayList) Indexes(org.moire.ultrasonic.domain.Indexes) MusicFolder(org.moire.ultrasonic.domain.MusicFolder)

Aggregations

ArrayList (java.util.ArrayList)2 Artist (org.moire.ultrasonic.domain.Artist)2 ArtistAdapter (org.moire.ultrasonic.view.ArtistAdapter)2 Indexes (org.moire.ultrasonic.domain.Indexes)1 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)1 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)1 MusicFolder (org.moire.ultrasonic.domain.MusicFolder)1 MusicService (org.moire.ultrasonic.service.MusicService)1 MergeAdapter (org.moire.ultrasonic.util.MergeAdapter)1 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)1 EntryAdapter (org.moire.ultrasonic.view.EntryAdapter)1