use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class SongListAdapter method getView.
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
DownloadFile downloadFile = getItem(position);
MusicDirectory.Entry entry = downloadFile.getSong();
SongView view;
if (convertView != null && convertView instanceof SongView) {
SongView currentView = (SongView) convertView;
if (currentView.getEntry().equals(entry)) {
currentView.update();
return currentView;
} else {
EntryAdapter.SongViewHolder viewHolder = (EntryAdapter.SongViewHolder) convertView.getTag();
view = currentView;
view.setViewHolder(viewHolder);
}
} else {
view = new SongView(this.context);
view.setLayout(entry);
}
view.setSong(entry, false, true);
return view;
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class SongView method update.
@Override
protected void update() {
updateBackground();
if (downloadService == null) {
return;
}
downloadFile = downloadService.forSong(this.song);
File partialFile = downloadFile.getPartialFile();
if (downloadFile.isWorkDone()) {
ImageType newLeftImageType = downloadFile.isSaved() ? ImageType.unpin : ImageType.downloaded;
if (this.leftImageType != newLeftImageType) {
this.leftImage = downloadFile.isSaved() ? unpinImage : downloadedImage;
this.leftImageType = newLeftImageType;
}
} else {
this.leftImageType = ImageType.none;
this.leftImage = null;
}
if (downloadFile.isDownloading() && !downloadFile.isDownloadCancelled() && partialFile.exists()) {
if (this.viewHolder.status != null) {
this.viewHolder.status.setText(Util.formatLocalizedBytes(partialFile.length(), this.context));
}
this.rightImageType = ImageType.downloading;
this.rightImage = downloadingImage;
} else {
this.rightImageType = ImageType.none;
this.rightImage = null;
if (this.viewHolder.status != null) {
CharSequence statusText = this.viewHolder.status.getText();
if (statusText != "" || statusText != null) {
this.viewHolder.status.setText(null);
}
}
}
if (this.previousLeftImageType != leftImageType || this.previousRightImageType != rightImageType) {
this.previousLeftImageType = leftImageType;
this.previousRightImageType = rightImageType;
if (this.viewHolder.status != null) {
this.viewHolder.status.setCompoundDrawablesWithIntrinsicBounds(leftImage, null, rightImage, null);
if (rightImage == downloadingImage) {
AnimationDrawable frameAnimation = (AnimationDrawable) rightImage;
frameAnimation.setVisible(true, true);
}
}
}
if (!song.getStarred()) {
if (viewHolder.star != null) {
if (viewHolder.star.getDrawable() != starHollowDrawable) {
viewHolder.star.setImageDrawable(starHollowDrawable);
}
}
} else {
if (viewHolder.star != null) {
if (viewHolder.star.getDrawable() != starDrawable) {
viewHolder.star.setImageDrawable(starDrawable);
}
}
}
boolean playing = downloadService.getCurrentPlaying() == downloadFile;
if (playing) {
if (!this.playing) {
this.playing = true;
viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(playingImage, null, null, null);
}
} else {
if (this.playing) {
this.playing = false;
viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
}
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class SelectAlbumActivity method enableButtons.
private void enableButtons() {
if (getDownloadService() == null) {
return;
}
List<MusicDirectory.Entry> selection = getSelectedSongs(albumListView);
boolean enabled = !selection.isEmpty();
boolean unpinEnabled = false;
boolean deleteEnabled = false;
int pinnedCount = 0;
for (MusicDirectory.Entry song : selection) {
DownloadFile downloadFile = getDownloadService().forSong(song);
if (downloadFile.isWorkDone()) {
deleteEnabled = true;
}
if (downloadFile.isSaved()) {
pinnedCount++;
unpinEnabled = true;
}
}
playNowButton.setVisibility(enabled ? View.VISIBLE : View.GONE);
playNextButton.setVisibility(enabled ? View.VISIBLE : View.GONE);
playLastButton.setVisibility(enabled ? View.VISIBLE : View.GONE);
pinButton.setVisibility((enabled && !Util.isOffline(this) && selection.size() > pinnedCount) ? View.VISIBLE : View.GONE);
unpinButton.setVisibility(enabled && unpinEnabled ? View.VISIBLE : View.GONE);
downloadButton.setVisibility(enabled && !deleteEnabled && !Util.isOffline(this) ? View.VISIBLE : View.GONE);
deleteButton.setVisibility(enabled && deleteEnabled ? View.VISIBLE : View.GONE);
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class BookmarkActivity method enableButtons.
private void enableButtons() {
if (getDownloadService() == null) {
return;
}
List<MusicDirectory.Entry> selection = getSelectedSongs(albumListView);
boolean enabled = !selection.isEmpty();
boolean unpinEnabled = false;
boolean deleteEnabled = false;
int pinnedCount = 0;
for (MusicDirectory.Entry song : selection) {
DownloadFile downloadFile = getDownloadService().forSong(song);
if (downloadFile.isWorkDone()) {
deleteEnabled = true;
}
if (downloadFile.isSaved()) {
pinnedCount++;
unpinEnabled = true;
}
}
playNowButton.setVisibility(enabled && deleteEnabled ? View.VISIBLE : View.GONE);
pinButton.setVisibility((enabled && !Util.isOffline(this) && selection.size() > pinnedCount) ? View.VISIBLE : View.GONE);
unpinButton.setVisibility(enabled && unpinEnabled ? View.VISIBLE : View.GONE);
downloadButton.setVisibility(enabled && !deleteEnabled && !Util.isOffline(this) ? View.VISIBLE : View.GONE);
deleteButton.setVisibility(enabled && deleteEnabled ? View.VISIBLE : View.GONE);
}
Aggregations