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