Search in sources :

Example 1 with SongListAdapter

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

the class DownloadActivity method onDownloadListChanged.

private void onDownloadListChanged() {
    final DownloadService downloadService = getDownloadService();
    if (downloadService == null) {
        return;
    }
    final List<DownloadFile> list = downloadService.getSongs();
    emptyTextView.setText(R.string.download_empty);
    final SongListAdapter adapter = new SongListAdapter(this, list);
    playlistView.setAdapter(adapter);
    playlistView.setDragSortListener(new DragSortListView.DragSortListener() {

        @Override
        public void drop(int from, int to) {
            if (from != to) {
                DownloadFile item = adapter.getItem(from);
                adapter.remove(item);
                adapter.notifyDataSetChanged();
                adapter.insert(item, to);
                adapter.notifyDataSetChanged();
            }
        }

        @Override
        public void drag(int from, int to) {
        }

        @Override
        public void remove(int which) {
            DownloadFile item = adapter.getItem(which);
            DownloadService downloadService = getDownloadService();
            if (item == null || downloadService == null) {
                return;
            }
            DownloadFile currentPlaying = downloadService.getCurrentPlaying();
            if (currentPlaying == item) {
                getDownloadService().next();
            }
            adapter.remove(item);
            adapter.notifyDataSetChanged();
            String songRemoved = String.format(getResources().getString(R.string.download_song_removed), item.getSong().getTitle());
            Util.toast(DownloadActivity.this, songRemoved);
            onDownloadListChanged();
            onCurrentChanged();
        }
    });
    emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
    currentRevision = downloadService.getDownloadListUpdateRevision();
    switch(downloadService.getRepeatMode()) {
        case OFF:
            repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_off));
            break;
        case ALL:
            repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_all));
            break;
        case SINGLE:
            repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_single));
            break;
        default:
            break;
    }
}
Also used : DownloadFile(org.moire.ultrasonic.service.DownloadFile) SongListAdapter(org.moire.ultrasonic.view.SongListAdapter) DragSortListView(com.mobeta.android.dslv.DragSortListView) DownloadService(org.moire.ultrasonic.service.DownloadService) Point(android.graphics.Point)

Aggregations

Point (android.graphics.Point)1 DragSortListView (com.mobeta.android.dslv.DragSortListView)1 DownloadFile (org.moire.ultrasonic.service.DownloadFile)1 DownloadService (org.moire.ultrasonic.service.DownloadService)1 SongListAdapter (org.moire.ultrasonic.view.SongListAdapter)1