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;
}
}
Aggregations