Search in sources :

Example 11 with MusicService

use of org.moire.ultrasonic.service.MusicService in project ultrasonic by ultrasonic.

the class SelectAlbumActivity method getAlbumList.

private void getAlbumList(final String albumListType, final int albumListTitle, final int size, final int offset) {
    showHeader = false;
    setActionBarSubtitle(albumListTitle);
    new LoadTask() {

        @Override
        protected MusicDirectory load(MusicService service) throws Exception {
            return Util.getShouldUseId3Tags(SelectAlbumActivity.this) ? service.getAlbumList2(albumListType, size, offset, SelectAlbumActivity.this, this) : service.getAlbumList(albumListType, size, offset, SelectAlbumActivity.this, this);
        }

        @Override
        protected void done(Pair<MusicDirectory, Boolean> result) {
            if (!result.getFirst().getChildren().isEmpty()) {
                pinButton.setVisibility(View.GONE);
                unpinButton.setVisibility(View.GONE);
                downloadButton.setVisibility(View.GONE);
                deleteButton.setVisibility(View.GONE);
                // Hide more button when results are less than album list size
                if (result.getFirst().getChildren().size() < getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0)) {
                    moreButton.setVisibility(View.GONE);
                } else {
                    moreButton.setVisibility(View.VISIBLE);
                    moreButton.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class);
                            int albumListTitle = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, 0);
                            String type = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
                            int size = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
                            int offset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + size;
                            intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, albumListTitle);
                            intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
                            intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, size);
                            intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset);
                            startActivityForResultWithoutTransition(SelectAlbumActivity.this, intent);
                        }
                    });
                }
            } else {
                moreButton.setVisibility(View.GONE);
            }
            super.done(result);
        }
    }.execute();
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) AlbumView(org.moire.ultrasonic.view.AlbumView) PullToRefreshListView(com.handmark.pulltorefresh.library.PullToRefreshListView) TextView(android.widget.TextView) SongView(org.moire.ultrasonic.view.SongView) ListView(android.widget.ListView)

Example 12 with MusicService

use of org.moire.ultrasonic.service.MusicService in project ultrasonic by ultrasonic.

the class SelectAlbumActivity method getSongsForGenre.

private void getSongsForGenre(final String genre, final int count, final int offset) {
    setActionBarSubtitle(genre);
    new LoadTask() {

        @Override
        protected MusicDirectory load(MusicService service) throws Exception {
            return service.getSongsByGenre(genre, count, offset, SelectAlbumActivity.this, this);
        }

        @Override
        protected void done(Pair<MusicDirectory, Boolean> result) {
            // Hide more button when results are less than album list size
            if (result.getFirst().getChildren().size() < getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0)) {
                moreButton.setVisibility(View.GONE);
            } else {
                moreButton.setVisibility(View.VISIBLE);
            }
            moreButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class);
                    String genre = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_GENRE_NAME);
                    int size = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
                    int offset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + size;
                    intent.putExtra(Constants.INTENT_EXTRA_NAME_GENRE_NAME, genre);
                    intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, size);
                    intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset);
                    startActivityForResultWithoutTransition(SelectAlbumActivity.this, intent);
                }
            });
            super.done(result);
        }
    }.execute();
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) AlbumView(org.moire.ultrasonic.view.AlbumView) PullToRefreshListView(com.handmark.pulltorefresh.library.PullToRefreshListView) TextView(android.widget.TextView) SongView(org.moire.ultrasonic.view.SongView) ListView(android.widget.ListView)

Example 13 with MusicService

use of org.moire.ultrasonic.service.MusicService in project ultrasonic by ultrasonic.

the class SelectAlbumActivity method getArtist.

private void getArtist(final String id, final String name) {
    setActionBarSubtitle(name);
    new LoadTask() {

        @Override
        protected MusicDirectory load(MusicService service) throws Exception {
            MusicDirectory root = new MusicDirectory();
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            MusicDirectory musicDirectory = service.getArtist(id, name, refresh, SelectAlbumActivity.this, this);
            if (Util.getShouldShowAllSongsByArtist(SelectAlbumActivity.this) && musicDirectory.findChild(allSongsId) == null && musicDirectory.getChildren(true, false).size() == musicDirectory.getChildren(true, true).size()) {
                MusicDirectory.Entry allSongs = new MusicDirectory.Entry();
                allSongs.setDirectory(true);
                allSongs.setArtist(name);
                allSongs.setParent(id);
                allSongs.setId(allSongsId);
                allSongs.setTitle(String.format(getResources().getString(R.string.select_album_all_songs), name));
                root.addFirst(allSongs);
                List<MusicDirectory.Entry> children = musicDirectory.getChildren();
                if (children != null) {
                    root.addAll(children);
                }
            } else {
                root = musicDirectory;
            }
            return root;
        }
    }.execute();
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 14 with MusicService

use of org.moire.ultrasonic.service.MusicService in project ultrasonic by ultrasonic.

the class SelectAlbumActivity method getAlbum.

private void getAlbum(final String id, final String name, final String parentId) {
    setActionBarSubtitle(name);
    new LoadTask() {

        @Override
        protected MusicDirectory load(MusicService service) throws Exception {
            MusicDirectory musicDirectory;
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            if (allSongsId.equals(id)) {
                MusicDirectory root = new MusicDirectory();
                Collection<MusicDirectory.Entry> songs = new LinkedList<MusicDirectory.Entry>();
                getSongsForArtist(parentId, songs);
                for (MusicDirectory.Entry song : songs) {
                    if (!song.isDirectory()) {
                        root.addChild(song);
                    }
                }
                musicDirectory = root;
            } else {
                musicDirectory = service.getAlbum(id, name, refresh, SelectAlbumActivity.this, this);
            }
            return musicDirectory;
        }

        private void getSongsForArtist(String id, Collection<MusicDirectory.Entry> songs) throws Exception {
            MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this);
            MusicDirectory artist = musicService.getArtist(id, "", false, SelectAlbumActivity.this, this);
            for (MusicDirectory.Entry album : artist.getChildren()) {
                if (!allSongsId.equals(album.getId())) {
                    MusicDirectory albumDirectory = musicService.getAlbum(album.getId(), "", false, SelectAlbumActivity.this, this);
                    for (MusicDirectory.Entry song : albumDirectory.getChildren()) {
                        if (!song.isVideo()) {
                            songs.add(song);
                        }
                    }
                }
            }
        }
    }.execute();
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService) Collection(java.util.Collection)

Example 15 with MusicService

use of org.moire.ultrasonic.service.MusicService in project ultrasonic by ultrasonic.

the class SelectAlbumActivity method getShare.

private void getShare(final String shareId, final CharSequence shareName) {
    setActionBarSubtitle(shareName);
    new LoadTask() {

        @Override
        protected MusicDirectory load(MusicService service) throws Exception {
            List<Share> shares = service.getShares(true, SelectAlbumActivity.this, this);
            MusicDirectory md = new MusicDirectory();
            for (Share share : shares) {
                if (share.getId().equals(shareId)) {
                    for (MusicDirectory.Entry entry : share.getEntries()) {
                        md.addChild(entry);
                    }
                    break;
                }
            }
            return md;
        }
    }.execute();
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Share(org.moire.ultrasonic.domain.Share)

Aggregations

MusicService (org.moire.ultrasonic.service.MusicService)24 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)8 TextView (android.widget.TextView)5 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 SpannableString (android.text.SpannableString)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 ListView (android.widget.ListView)4 PullToRefreshListView (com.handmark.pulltorefresh.library.PullToRefreshListView)4 LinkedList (java.util.LinkedList)4 ApiNotSupportedException (org.moire.ultrasonic.api.subsonic.ApiNotSupportedException)4 Share (org.moire.ultrasonic.domain.Share)4 OfflineException (org.moire.ultrasonic.service.OfflineException)4 LoadingTask (org.moire.ultrasonic.util.LoadingTask)4 Editable (android.text.Editable)3 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)3