Search in sources :

Example 16 with MusicDirectory

use of org.moire.ultrasonic.domain.MusicDirectory in project ultrasonic by ultrasonic.

the class RESTMusicService method getRandomSongs.

@Override
public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception {
    updateProgressListener(progressListener, R.string.parser_reading);
    Response<GetRandomSongsResponse> response = subsonicAPIClient.getApi().getRandomSongs(size, null, null, null, null).execute();
    checkResponseSuccessful(response);
    MusicDirectory result = new MusicDirectory();
    result.addAll(APIMusicDirectoryConverter.toDomainEntityList(response.body().getSongsList()));
    return result;
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) GetRandomSongsResponse(org.moire.ultrasonic.api.subsonic.response.GetRandomSongsResponse)

Example 17 with MusicDirectory

use of org.moire.ultrasonic.domain.MusicDirectory 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 18 with MusicDirectory

use of org.moire.ultrasonic.domain.MusicDirectory 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 19 with MusicDirectory

use of org.moire.ultrasonic.domain.MusicDirectory 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 20 with MusicDirectory

use of org.moire.ultrasonic.domain.MusicDirectory 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)

Aggregations

MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)23 MusicService (org.moire.ultrasonic.service.MusicService)8 LinkedList (java.util.LinkedList)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Intent (android.content.Intent)2 View (android.view.View)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 PullToRefreshListView (com.handmark.pulltorefresh.library.PullToRefreshListView)2 Collection (java.util.Collection)2 Share (org.moire.ultrasonic.domain.Share)2 AlbumView (org.moire.ultrasonic.view.AlbumView)2 SongView (org.moire.ultrasonic.view.SongView)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1