Search in sources :

Example 6 with DownloadFile

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;
            }
        }
    }
}
Also used : DownloadFile(org.moire.ultrasonic.service.DownloadFile) ListAdapter(android.widget.ListAdapter) SongListAdapter(org.moire.ultrasonic.view.SongListAdapter) Point(android.graphics.Point)

Example 7 with DownloadFile

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

Example 8 with DownloadFile

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

Example 9 with DownloadFile

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;
}
Also used : DownloadFile(org.moire.ultrasonic.service.DownloadFile) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 10 with DownloadFile

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

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