Search in sources :

Example 11 with DownloadFile

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;
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) DownloadFile(org.moire.ultrasonic.service.DownloadFile)

Example 12 with DownloadFile

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);
        }
    }
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) DownloadFile(org.moire.ultrasonic.service.DownloadFile) File(java.io.File)

Example 13 with DownloadFile

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);
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) DownloadFile(org.moire.ultrasonic.service.DownloadFile)

Example 14 with DownloadFile

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);
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) DownloadFile(org.moire.ultrasonic.service.DownloadFile) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry)

Aggregations

DownloadFile (org.moire.ultrasonic.service.DownloadFile)14 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)6 File (java.io.File)4 DownloadService (org.moire.ultrasonic.service.DownloadService)4 Intent (android.content.Intent)3 Point (android.graphics.Point)3 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)3 PendingIntent (android.app.PendingIntent)2 MenuItem (android.view.MenuItem)2 AdapterView (android.widget.AdapterView)2 SongListAdapter (org.moire.ultrasonic.view.SongListAdapter)2 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 Drawable (android.graphics.drawable.Drawable)1 MenuInflater (android.view.MenuInflater)1 ListAdapter (android.widget.ListAdapter)1 DragSortListView (com.mobeta.android.dslv.DragSortListView)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PlayerState (org.moire.ultrasonic.domain.PlayerState)1 MusicService (org.moire.ultrasonic.service.MusicService)1