Search in sources :

Example 6 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class FileAdapter method getView.

/**
 * Create the actual listview items if no reusable object is provided.
 *
 * @param position    Index of the item to create.
 * @param convertView If != null this view can be reused to optimize performance.
 * @param parent      Parent of the view
 * @return
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get MPDTrack at the given index used for this item.
    MPDFileEntry file = (MPDFileEntry) getItem(position);
    if (file instanceof MPDTrack) {
        MPDTrack track = (MPDTrack) file;
        // Normal file entry
        if (!mShowSectionItems || (VIEW_TYPES.values()[getItemViewType(position)] == VIEW_TYPES.TYPE_FILE_ITEM)) {
            if (convertView == null) {
                convertView = new FileListItem(mContext, mShowIcons);
            }
            ((FileListItem) convertView).setTrack(track, mUseTags, mContext);
            if (!mShowTrackNumbers) {
                ((FileListItem) convertView).setTrackNumber(String.valueOf(position + 1));
            }
            return convertView;
        } else {
            // Section items
            if (convertView == null) {
                // If not create a new Listitem
                convertView = new FileListItem(mContext, track.getTrackAlbum(), mShowIcons, this);
            }
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setSectionHeader(track.getTrackAlbum());
            tracksListViewItem.setTrack(track, mUseTags, mContext);
            if (!mShowTrackNumbers) {
                tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
            }
            // This will prepare the view for fetching the image from the internet if not already saved in local database.
            // Dummy MPDAlbum
            MPDAlbum tmpAlbum = new MPDAlbum(track.getTrackAlbum());
            tmpAlbum.setMBID(track.getTrackAlbumMBID());
            ((FileListItem) convertView).prepareArtworkFetching(ArtworkManager.getInstance(mContext.getApplicationContext()), tmpAlbum);
            // starts the loading.
            if (mScrollSpeed == 0) {
                ((FileListItem) convertView).startCoverImageTask();
            }
            return convertView;
        }
    } else if (file instanceof MPDDirectory) {
        if (convertView == null) {
            convertView = new FileListItem(mContext, mShowIcons);
        }
        ((FileListItem) convertView).setDirectory((MPDDirectory) file, mContext);
        return convertView;
    } else if (file instanceof MPDPlaylist) {
        if (convertView == null) {
            convertView = new FileListItem(mContext, mShowIcons);
        }
        ((FileListItem) convertView).setPlaylist((MPDPlaylist) file, mContext);
        return convertView;
    }
    return new FileListItem(mContext, mShowIcons);
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDDirectory(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) FileListItem(org.gateshipone.malp.application.listviewitems.FileListItem)

Example 7 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class FilesFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
    mLastPosition = position;
    MPDFileEntry file = (MPDFileEntry) mAdapter.getItem(position);
    if (file instanceof MPDDirectory) {
        mCallback.openPath(file.getPath());
    } else if (file instanceof MPDPlaylist) {
        mPlaylistCallback.openPlaylist(file.getPath());
    } else if (file instanceof MPDTrack) {
        switch(mClickAction) {
            case ACTION_SHOW_DETAILS:
                {
                    // Open song details dialog
                    SongDetailsDialog songDetailsDialog = new SongDetailsDialog();
                    Bundle args = new Bundle();
                    args.putParcelable(SongDetailsDialog.EXTRA_FILE, (MPDTrack) mAdapter.getItem(position));
                    songDetailsDialog.setArguments(args);
                    songDetailsDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "SongDetails");
                    return;
                }
            case ACTION_ADD_SONG:
                {
                    MPDTrack track = (MPDTrack) mAdapter.getItem(position);
                    MPDQueryHandler.addPath(track.getPath());
                    return;
                }
            case ACTION_PLAY_SONG:
                {
                    MPDTrack track = (MPDTrack) mAdapter.getItem(position);
                    MPDQueryHandler.playSong(track.getPath());
                    return;
                }
            case ACTION_PLAY_SONG_NEXT:
                {
                    MPDTrack track = (MPDTrack) mAdapter.getItem(position);
                    MPDQueryHandler.playSongNext(track.getPath());
                    return;
                }
        }
    }
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDDirectory(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory) Bundle(android.os.Bundle) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) AppCompatActivity(android.support.v7.app.AppCompatActivity)

Example 8 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class SearchFragment method onContextItemSelected.

/**
 * Hook called when an menu item in the context menu is selected.
 *
 * @param item The menu item that was selected.
 * @return True if the hook was consumed here.
 */
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int position;
    if (info == null) {
        if (mContextMenuPosition == -1) {
            return super.onContextItemSelected(item);
        }
        position = mContextMenuPosition;
        mContextMenuPosition = -1;
    } else {
        position = info.position;
    }
    MPDTrack track = (MPDTrack) mFileAdapter.getItem(position);
    mListView.requestFocus();
    switch(item.getItemId()) {
        case R.id.action_song_play:
            MPDQueryHandler.playSong(track.getPath());
            return true;
        case R.id.action_song_enqueue:
            MPDQueryHandler.addPath(track.getPath());
            return true;
        case R.id.action_song_play_next:
            MPDQueryHandler.playSongNext(track.getPath());
            return true;
        case R.id.action_add_to_saved_playlist:
            {
                // open dialog in order to save the current playlist as a playlist in the mediastore
                ChoosePlaylistDialog choosePlaylistDialog = new ChoosePlaylistDialog();
                Bundle args = new Bundle();
                args.putBoolean(ChoosePlaylistDialog.EXTRA_SHOW_NEW_ENTRY, true);
                choosePlaylistDialog.setCallback(new AddPathToPlaylist((MPDFileEntry) mFileAdapter.getItem(position), getContext()));
                choosePlaylistDialog.setArguments(args);
                choosePlaylistDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "ChoosePlaylistDialog");
                return true;
            }
        case R.id.action_show_details:
            {
                // Open song details dialog
                SongDetailsDialog songDetailsDialog = new SongDetailsDialog();
                Bundle args = new Bundle();
                args.putParcelable(SongDetailsDialog.EXTRA_FILE, (MPDTrack) mFileAdapter.getItem(position));
                songDetailsDialog.setArguments(args);
                songDetailsDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "SongDetails");
                return true;
            }
        case R.id.action_add_album:
            MPDQueryHandler.addArtistAlbum(track.getTrackAlbum(), "", track.getTrackAlbumMBID());
            return true;
        case R.id.action_play_album:
            MPDQueryHandler.playArtistAlbum(track.getTrackAlbum(), "", track.getTrackAlbumMBID());
            return true;
        case R.id.action_add_artist:
            MPDQueryHandler.addArtist(track.getTrackArtist(), mAlbumSortOrder);
            return true;
        case R.id.action_play_artist:
            MPDQueryHandler.playArtist(track.getTrackArtist(), mAlbumSortOrder);
            return true;
        case R.id.menu_group_album:
        case R.id.menu_group_artist:
            // Save position for later use
            mContextMenuPosition = info.position;
        default:
            return super.onContextItemSelected(item);
    }
}
Also used : AddPathToPlaylist(org.gateshipone.malp.application.callbacks.AddPathToPlaylist) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) Bundle(android.os.Bundle) AppCompatActivity(android.support.v7.app.AppCompatActivity) AdapterView(android.widget.AdapterView)

Example 9 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class AlbumTracksFragment method play.

private void play(int index) {
    MPDTrack track = (MPDTrack) mFileAdapter.getItem(index);
    MPDQueryHandler.playSong(track.getPath());
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)

Example 10 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class AlbumTracksFragment method enqueueTrack.

private void enqueueTrack(int index) {
    MPDTrack track = (MPDTrack) mFileAdapter.getItem(index);
    MPDQueryHandler.addPath(track.getPath());
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)

Aggregations

MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)25 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)7 Bundle (android.os.Bundle)4 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)4 MPDDirectory (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory)4 MPDPlaylist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)4 AppCompatActivity (android.support.v7.app.AppCompatActivity)3 AdapterView (android.widget.AdapterView)3 AddPathToPlaylist (org.gateshipone.malp.application.callbacks.AddPathToPlaylist)3 MPDCurrentStatus (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)3 FileListItem (org.gateshipone.malp.application.listviewitems.FileListItem)2 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)2 Bitmap (android.graphics.Bitmap)1 MenuInflater (android.view.MenuInflater)1 VolleyError (com.android.volley.VolleyError)1 ArrayList (java.util.ArrayList)1 ImageNotFoundException (org.gateshipone.malp.application.artworkdatabase.ImageNotFoundException)1 FanartFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.FanartFetchError)1 TrackAlbumFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)1 ChoosePlaylistDialog (org.gateshipone.malp.application.fragments.serverfragments.ChoosePlaylistDialog)1