Search in sources :

Example 16 with MPDTrack

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

the class PlaylistTracksFragment 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)

Example 17 with MPDTrack

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

the class PlaylistTracksFragment 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();
    if (info == null) {
        return super.onContextItemSelected(item);
    }
    switch(item.getItemId()) {
        case R.id.action_song_enqueue:
            enqueueTrack(info.position);
            return true;
        case R.id.action_song_play:
            play(info.position);
            return true;
        case R.id.action_song_play_next:
            playNext(info.position);
            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(info.position), getActivity()));
                choosePlaylistDialog.setArguments(args);
                choosePlaylistDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "ChoosePlaylistDialog");
                return true;
            }
        case R.id.action_remove_from_list:
            MPDQueryHandler.removeSongFromSavedPlaylist(mPath, info.position);
            refreshContent();
            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(info.position));
                songDetailsDialog.setArguments(args);
                songDetailsDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "SongDetails");
                return true;
            }
        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 18 with MPDTrack

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

the class AlbumTracksFragment method playNext.

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

Example 19 with MPDTrack

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

the class WidgetProvider method onReceive.

/**
 * This is the broadcast receiver for NowPlayingInformation objects sent by the PBS
 *
 * @param context Context used for this receiver
 * @param intent  Intent containing the NowPlayingInformation as a payload.
 */
@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    // Type checks
    if (intent.getAction().equals(BackgroundService.ACTION_STATUS_CHANGED)) {
        // Extract the payload from the intent
        MPDCurrentStatus status = intent.getParcelableExtra(BackgroundService.INTENT_EXTRA_STATUS);
        // Check if a payload was sent
        if (null != status) {
            // Save the information for later usage (when the asynchronous bitmap loader finishes)
            mLastStatus = status;
        }
    } else if (intent.getAction().equals(BackgroundService.ACTION_TRACK_CHANGED)) {
        // Extract the payload from the intent
        MPDTrack track = intent.getParcelableExtra(BackgroundService.INTENT_EXTRA_TRACK);
        // Check if a payload was sent
        if (null != track) {
            boolean newImage = false;
            // Check if new album is played and remove image if it is.
            if (mLastTrack == null || !track.getTrackAlbum().equals(mLastTrack.getTrackAlbum()) || !track.getTrackAlbumMBID().equals(mLastTrack.getTrackAlbumMBID())) {
                mLastCover = null;
                newImage = true;
            }
            // Save the information for later usage (when the asynchronous bitmap loader finishes)
            mLastTrack = track;
            if (newImage) {
                CoverBitmapLoader coverLoader = new CoverBitmapLoader(context, new CoverReceiver(context, this));
                coverLoader.getImage(track, false, -1, -1);
            }
        }
    } else if (intent.getAction().equals(BackgroundService.ACTION_SERVER_DISCONNECTED)) {
        mLastStatus = null;
        mLastTrack = null;
    } else if (intent.getAction().equals(ArtworkManager.ACTION_NEW_ARTWORK_READY)) {
        // Check if the new artwork matches the currently playing track. If so reload artwork
        if (mLastTrack != null && mLastTrack.getTrackAlbum().equals(intent.getStringExtra(ArtworkManager.INTENT_EXTRA_KEY_ALBUM_NAME))) {
            // Got new artwork
            mLastCover = null;
            CoverBitmapLoader coverLoader = new CoverBitmapLoader(context, new CoverReceiver(context, this));
            coverLoader.getImage(mLastTrack, false, -1, -1);
        }
    }
    // Refresh the widget with the new information
    updateWidget(context);
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus) CoverBitmapLoader(org.gateshipone.malp.application.utils.CoverBitmapLoader)

Example 20 with MPDTrack

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

the class CurrentPlaylistAdapter method getItemViewType.

/**
 * Returns the type (section track or normal track) of the item at the given position
 * @param position Position of the item in question
 * @return the int value of the enum {@link VIEW_TYPES}
 */
@Override
public int getItemViewType(int position) {
    // If playlist sections are disabled, just return track type here
    if (!mSectionsEnabled) {
        return VIEW_TYPES.TYPE_TRACK_ITEM.ordinal();
    }
    // Get MPDTrack at the given index used for this item.
    MPDTrack track = getTrack(position);
    boolean newAlbum = false;
    // Check if the track was available in local data set already (or is currently fetching)
    if (track != null) {
        MPDTrack previousTrack;
        if (position > 0) {
            previousTrack = getTrack(position - 1);
            if (previousTrack != null) {
                newAlbum = !previousTrack.getTrackAlbum().equals(track.getTrackAlbum());
            }
        } else {
            return VIEW_TYPES.TYPE_SECTION_TRACK_ITEM.ordinal();
        }
    }
    return newAlbum ? VIEW_TYPES.TYPE_SECTION_TRACK_ITEM.ordinal() : VIEW_TYPES.TYPE_TRACK_ITEM.ordinal();
}
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