Search in sources :

Example 1 with MusicService

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

the class SelectAlbumActivity method getMusicDirectory.

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

        @Override
        protected MusicDirectory load(MusicService service) throws Exception {
            MusicDirectory root = new MusicDirectory();
            if (allSongsId.equals(id)) {
                boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
                MusicDirectory musicDirectory = service.getMusicDirectory(parentId, name, refresh, SelectAlbumActivity.this, this);
                List<MusicDirectory.Entry> songs = new LinkedList<MusicDirectory.Entry>();
                getSongsRecursively(musicDirectory, songs);
                for (MusicDirectory.Entry song : songs) {
                    if (!song.isDirectory()) {
                        root.addChild(song);
                    }
                }
            } else {
                boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
                MusicDirectory musicDirectory = service.getMusicDirectory(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.addChild(allSongs);
                    List<MusicDirectory.Entry> children = musicDirectory.getChildren();
                    if (children != null) {
                        root.addAll(children);
                    }
                } else {
                    root = musicDirectory;
                }
            }
            return root;
        }

        private void getSongsRecursively(MusicDirectory parent, List<MusicDirectory.Entry> songs) throws Exception {
            for (MusicDirectory.Entry song : parent.getChildren(false, true)) {
                if (!song.isVideo() && !song.isDirectory()) {
                    songs.add(song);
                }
            }
            MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this);
            for (MusicDirectory.Entry dir : parent.getChildren(true, false)) {
                MusicDirectory root;
                if (!allSongsId.equals(dir.getId())) {
                    root = musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, SelectAlbumActivity.this, this);
                    getSongsRecursively(root, songs);
                }
            }
        }
    }.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 2 with MusicService

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

the class SelectGenreActivity method load.

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

        @Override
        protected List<Genre> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(SelectGenreActivity.this);
            List<Genre> genres = new ArrayList<Genre>();
            try {
                genres = musicService.getGenres(SelectGenreActivity.this, this);
            } catch (Exception x) {
                Log.e(TAG, "Failed to load genres", x);
            }
            return genres;
        }

        @Override
        protected void done(List<Genre> result) {
            emptyView.setVisibility(result == null || result.isEmpty() ? View.VISIBLE : View.GONE);
            if (result != null) {
                genreListView.setAdapter(new GenreAdapter(SelectGenreActivity.this, result));
            }
        }
    };
    task.execute();
}
Also used : TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Genre(org.moire.ultrasonic.domain.Genre) GenreAdapter(org.moire.ultrasonic.view.GenreAdapter)

Example 3 with MusicService

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

the class SelectPlaylistActivity method load.

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

        @Override
        protected List<Playlist> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            List<Playlist> playlists = musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
            if (!Util.isOffline(SelectPlaylistActivity.this))
                new CacheCleaner(SelectPlaylistActivity.this, getDownloadService()).cleanPlaylists(playlists);
            return playlists;
        }

        @Override
        protected void done(List<Playlist> result) {
            playlistsListView.setAdapter(playlistAdapter = new PlaylistAdapter(SelectPlaylistActivity.this, result));
            emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
        }
    };
    task.execute();
}
Also used : Playlist(org.moire.ultrasonic.domain.Playlist) TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) PlaylistAdapter(org.moire.ultrasonic.view.PlaylistAdapter) List(java.util.List) CacheCleaner(org.moire.ultrasonic.util.CacheCleaner)

Example 4 with MusicService

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

the class ShareActivity method load.

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

        @Override
        protected List<Share> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(ShareActivity.this);
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            return musicService.getShares(refresh, ShareActivity.this, this);
        }

        @Override
        protected void done(List<Share> result) {
            sharesListView.setAdapter(shareAdapter = new ShareAdapter(ShareActivity.this, result));
            emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
        }
    };
    task.execute();
}
Also used : TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) List(java.util.List) ShareAdapter(org.moire.ultrasonic.view.ShareAdapter) Share(org.moire.ultrasonic.domain.Share)

Example 5 with MusicService

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

the class SubsonicTabActivity method downloadRecursively.

protected void downloadRecursively(final String id, final String name, final boolean isShare, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background, final boolean playNext, final boolean unpin, final boolean isArtist) {
    ModalBackgroundTask<List<Entry>> task = new ModalBackgroundTask<List<Entry>>(this, false) {

        private static final int MAX_SONGS = 500;

        @Override
        protected List<Entry> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
            List<Entry> songs = new LinkedList<Entry>();
            MusicDirectory root;
            if (!Util.isOffline(SubsonicTabActivity.this) && isArtist && Util.getShouldUseId3Tags(SubsonicTabActivity.this)) {
                getSongsForArtist(id, songs);
            } else {
                if (isDirectory) {
                    root = !Util.isOffline(SubsonicTabActivity.this) && Util.getShouldUseId3Tags(SubsonicTabActivity.this) ? musicService.getAlbum(id, name, false, SubsonicTabActivity.this, this) : musicService.getMusicDirectory(id, name, false, SubsonicTabActivity.this, this);
                } else if (isShare) {
                    root = new MusicDirectory();
                    List<Share> shares = musicService.getShares(true, SubsonicTabActivity.this, this);
                    for (Share share : shares) {
                        if (share.getId().equals(id)) {
                            for (Entry entry : share.getEntries()) {
                                root.addChild(entry);
                            }
                            break;
                        }
                    }
                } else {
                    root = musicService.getPlaylist(id, name, SubsonicTabActivity.this, this);
                }
                getSongsRecursively(root, songs);
            }
            return songs;
        }

        private void getSongsRecursively(MusicDirectory parent, List<Entry> songs) throws Exception {
            if (songs.size() > MAX_SONGS) {
                return;
            }
            for (Entry song : parent.getChildren(false, true)) {
                if (!song.isVideo()) {
                    songs.add(song);
                }
            }
            MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
            for (Entry dir : parent.getChildren(true, false)) {
                MusicDirectory root;
                root = !Util.isOffline(SubsonicTabActivity.this) && Util.getShouldUseId3Tags(SubsonicTabActivity.this) ? musicService.getAlbum(dir.getId(), dir.getTitle(), false, SubsonicTabActivity.this, this) : musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, SubsonicTabActivity.this, this);
                getSongsRecursively(root, songs);
            }
        }

        private void getSongsForArtist(String id, Collection<Entry> songs) throws Exception {
            if (songs.size() > MAX_SONGS) {
                return;
            }
            MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
            MusicDirectory artist = musicService.getArtist(id, "", false, SubsonicTabActivity.this, this);
            for (Entry album : artist.getChildren()) {
                MusicDirectory albumDirectory = musicService.getAlbum(album.getId(), "", false, SubsonicTabActivity.this, this);
                for (Entry song : albumDirectory.getChildren()) {
                    if (!song.isVideo()) {
                        songs.add(song);
                    }
                }
            }
        }

        @Override
        protected void done(List<Entry> songs) {
            if (Util.getShouldSortByDisc(SubsonicTabActivity.this)) {
                Collections.sort(songs, new EntryByDiscAndTrackComparator());
            }
            DownloadService downloadService = getDownloadService();
            if (!songs.isEmpty() && downloadService != null) {
                if (!append && !playNext && !unpin && !background) {
                    downloadService.clear();
                }
                warnIfNetworkOrStorageUnavailable();
                if (!background) {
                    if (unpin) {
                        downloadService.unpin(songs);
                    } else {
                        downloadService.download(songs, save, autoplay, playNext, shuffle, false);
                        if (!append && Util.getShouldTransitionOnPlaybackPreference(SubsonicTabActivity.this)) {
                            startActivityForResultWithoutTransition(SubsonicTabActivity.this, DownloadActivity.class);
                        }
                    }
                } else {
                    if (unpin) {
                        downloadService.unpin(songs);
                    } else {
                        downloadService.downloadBackground(songs, save);
                    }
                }
            }
        }
    };
    task.execute();
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService) EntryByDiscAndTrackComparator(org.moire.ultrasonic.util.EntryByDiscAndTrackComparator) ModalBackgroundTask(org.moire.ultrasonic.util.ModalBackgroundTask) LinkedList(java.util.LinkedList) DownloadService(org.moire.ultrasonic.service.DownloadService) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) 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