use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class DownloadActivity method scrollToCurrent.
// Scroll to current playing/downloading.
private void scrollToCurrent() {
if (getDownloadService() == null) {
return;
}
ListAdapter adapter = playlistView.getAdapter();
if (adapter != null) {
int count = adapter.getCount();
for (int i = 0; i < count; i++) {
if (currentPlaying == playlistView.getItemAtPosition(i)) {
playlistView.smoothScrollToPositionFromTop(i, 40);
return;
}
}
final DownloadFile currentDownloading = getDownloadService().getCurrentDownloading();
for (int i = 0; i < count; i++) {
if (currentDownloading == playlistView.getItemAtPosition(i)) {
playlistView.smoothScrollToPositionFromTop(i, 40);
return;
}
}
}
}
use of org.moire.ultrasonic.service.DownloadFile 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;
}
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class DownloadActivity method onCreateContextMenu.
@Override
public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
if (view == playlistView) {
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
final DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.nowplaying_context, menu);
Entry song = null;
if (downloadFile != null) {
song = downloadFile.getSong();
}
if (song != null && song.getParent() == null) {
MenuItem menuItem = menu.findItem(R.id.menu_show_album);
if (menuItem != null) {
menuItem.setVisible(false);
}
}
if (Util.isOffline(this) || !Util.getShouldUseId3Tags(this)) {
MenuItem menuItem = menu.findItem(R.id.menu_show_artist);
if (menuItem != null) {
menuItem.setVisible(false);
}
}
if (Util.isOffline(this)) {
MenuItem menuItem = menu.findItem(R.id.menu_lyrics);
if (menuItem != null) {
menuItem.setVisible(false);
}
}
}
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class DownloadActivity method onPrepareOptionsMenu.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
super.onPrepareOptionsMenu(menu);
final MenuItem screenOption = menu.findItem(R.id.menu_item_screen_on_off);
final MenuItem jukeboxOption = menu.findItem(R.id.menu_item_jukebox);
final MenuItem equalizerMenuItem = menu.findItem(R.id.menu_item_equalizer);
final MenuItem visualizerMenuItem = menu.findItem(R.id.menu_item_visualizer);
final MenuItem shareMenuItem = menu.findItem(R.id.menu_item_share);
starMenuItem = menu.findItem(R.id.menu_item_star);
MenuItem bookmarkMenuItem = menu.findItem(R.id.menu_item_bookmark_set);
MenuItem bookmarkRemoveMenuItem = menu.findItem(R.id.menu_item_bookmark_delete);
if (Util.isOffline(this)) {
if (shareMenuItem != null) {
shareMenuItem.setVisible(false);
}
if (starMenuItem != null) {
starMenuItem.setVisible(false);
}
if (bookmarkMenuItem != null) {
bookmarkMenuItem.setVisible(false);
}
if (bookmarkRemoveMenuItem != null) {
bookmarkRemoveMenuItem.setVisible(false);
}
}
if (equalizerMenuItem != null) {
equalizerMenuItem.setEnabled(equalizerAvailable);
equalizerMenuItem.setVisible(equalizerAvailable);
}
if (visualizerMenuItem != null) {
visualizerMenuItem.setEnabled(visualizerAvailable);
visualizerMenuItem.setVisible(visualizerAvailable);
}
final DownloadService downloadService = getDownloadService();
if (downloadService != null) {
DownloadFile downloadFile = downloadService.getCurrentPlaying();
if (downloadFile != null) {
currentSong = downloadFile.getSong();
}
if (currentSong != null) {
final Drawable starDrawable = currentSong.getStarred() ? Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_full) : Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow);
if (starMenuItem != null) {
starMenuItem.setIcon(starDrawable);
}
} else {
final Drawable starDrawable = Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow);
if (starMenuItem != null) {
starMenuItem.setIcon(starDrawable);
}
}
if (downloadService.getKeepScreenOn()) {
if (screenOption != null) {
screenOption.setTitle(R.string.download_menu_screen_off);
}
} else {
if (screenOption != null) {
screenOption.setTitle(R.string.download_menu_screen_on);
}
}
if (jukeboxOption != null) {
jukeboxOption.setEnabled(jukeboxAvailable);
jukeboxOption.setVisible(jukeboxAvailable);
if (downloadService.isJukeboxEnabled()) {
jukeboxOption.setTitle(R.string.download_menu_jukebox_off);
} else {
jukeboxOption.setTitle(R.string.download_menu_jukebox_on);
}
}
}
return true;
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class DownloadActivity method onContextItemSelected.
@Override
public boolean onContextItemSelected(final MenuItem menuItem) {
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
DownloadFile downloadFile = null;
if (info != null) {
downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
}
return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem);
}
Aggregations