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