Search in sources :

Example 1 with Share

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

the class ShareActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem menuItem) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
    if (info == null) {
        return false;
    }
    Share share = (Share) sharesListView.getItemAtPosition(info.position);
    if (share == null) {
        return false;
    }
    switch(menuItem.getItemId()) {
        case R.id.share_menu_pin:
            downloadShare(share.getId(), share.getName(), true, true, false, false, true, false, false);
            break;
        case R.id.share_menu_unpin:
            downloadShare(share.getId(), share.getName(), false, false, false, false, true, false, true);
            break;
        case R.id.share_menu_download:
            downloadShare(share.getId(), share.getName(), false, false, false, false, true, false, false);
            break;
        case R.id.share_menu_play_now:
            downloadShare(share.getId(), share.getName(), false, false, true, false, false, false, false);
            break;
        case R.id.share_menu_play_shuffled:
            downloadShare(share.getId(), share.getName(), false, false, true, true, false, false, false);
            break;
        case R.id.share_menu_delete:
            deleteShare(share);
            break;
        case R.id.share_info:
            displayShareInfo(share);
            break;
        case R.id.share_update_info:
            updateShareInfo(share);
            break;
        default:
            return super.onContextItemSelected(menuItem);
    }
    return true;
}
Also used : AdapterView(android.widget.AdapterView) Share(org.moire.ultrasonic.domain.Share)

Example 2 with Share

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

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

the class ShareActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Share share = (Share) parent.getItemAtPosition(position);
    if (share == null) {
        return;
    }
    Intent intent = new Intent(ShareActivity.this, SelectAlbumActivity.class);
    intent.putExtra(Constants.INTENT_EXTRA_NAME_SHARE_ID, share.getId());
    intent.putExtra(Constants.INTENT_EXTRA_NAME_SHARE_NAME, share.getName());
    startActivityForResultWithoutTransition(ShareActivity.this, intent);
}
Also used : Intent(android.content.Intent) Share(org.moire.ultrasonic.domain.Share)

Example 4 with Share

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

Example 5 with Share

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

the class ShareAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Share entry = getItem(position);
    ShareView view;
    if (convertView != null && convertView instanceof ShareView) {
        ShareView currentView = (ShareView) convertView;
        ViewHolder viewHolder = (ViewHolder) convertView.getTag();
        view = currentView;
        view.setViewHolder(viewHolder);
    } else {
        view = new ShareView(activity);
        view.setLayout();
    }
    view.setShare(entry);
    return view;
}
Also used : Share(org.moire.ultrasonic.domain.Share)

Aggregations

Share (org.moire.ultrasonic.domain.Share)7 MusicService (org.moire.ultrasonic.service.MusicService)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Intent (android.content.Intent)2 LinkedList (java.util.LinkedList)2 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)2 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)2 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)2 AdapterView (android.widget.AdapterView)1 Collection (java.util.Collection)1 DownloadService (org.moire.ultrasonic.service.DownloadService)1 EntryByDiscAndTrackComparator (org.moire.ultrasonic.util.EntryByDiscAndTrackComparator)1 ModalBackgroundTask (org.moire.ultrasonic.util.ModalBackgroundTask)1 ShareAdapter (org.moire.ultrasonic.view.ShareAdapter)1