use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist 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.MPDPlaylist 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.MPDPlaylist in project malp by gateship-one.
the class SavedPlaylistsFragment 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);
}
final MPDPlaylist playlist = (MPDPlaylist) mPlaylistAdapter.getItem(info.position);
switch(item.getItemId()) {
case R.id.action_add_playlist:
MPDQueryHandler.loadPlaylist(playlist.getPath());
return true;
case R.id.action_remove_playlist:
final AlertDialog.Builder removeListBuilder = new AlertDialog.Builder(getContext());
removeListBuilder.setTitle(getContext().getString(R.string.action_delete_playlist));
removeListBuilder.setMessage(getContext().getString(R.string.dialog_message_delete_playlist) + ' ' + playlist.getSectionTitle() + '?');
removeListBuilder.setPositiveButton(R.string.dialog_action_yes, (dialog, which) -> {
MPDQueryHandler.removePlaylist(playlist.getPath());
mPlaylistAdapter.swapModel(null);
getLoaderManager().destroyLoader(0);
getLoaderManager().initLoader(0, getArguments(), SavedPlaylistsFragment.this);
});
removeListBuilder.setNegativeButton(R.string.dialog_action_no, (dialog, which) -> {
});
removeListBuilder.create().show();
return true;
case R.id.action_play_playlist:
MPDQueryHandler.playPlaylist(playlist.getPath());
return true;
default:
return super.onContextItemSelected(item);
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist in project malp by gateship-one.
the class ChoosePlaylistDialog method onCreateDialog.
/**
* Create the dialog to choose to override an existing bookmark or to create a new bookmark.
*/
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments();
if (null != args) {
mShowNewEntry = args.getBoolean(EXTRA_SHOW_NEW_ENTRY);
}
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
mPlaylistsListViewAdapter = new FileAdapter(getActivity(), false, false);
builder.setTitle(getString(R.string.dialog_choose_playlist)).setAdapter(mPlaylistsListViewAdapter, (dialog, which) -> {
if (null == mSaveCallback) {
return;
}
if (which == 0) {
// open save dialog to create a new playlist
mSaveCallback.onCreateNewObject();
} else {
// override existing playlist
MPDPlaylist playlist = (MPDPlaylist) mPlaylistsListViewAdapter.getItem(which);
String objectTitle = playlist.getPath();
mSaveCallback.onSaveObject(objectTitle);
}
}).setNegativeButton(R.string.dialog_action_cancel, (dialog, id) -> {
// User cancelled the dialog don't save object
getDialog().cancel();
});
// Prepare loader ( start new one or reuse old )
getLoaderManager().initLoader(0, getArguments(), this);
// set divider
AlertDialog dlg = builder.create();
dlg.getListView().setDivider(new ColorDrawable(ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_background_selected)));
dlg.getListView().setDividerHeight(getResources().getDimensionPixelSize(R.dimen.list_divider_size));
return dlg;
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist in project malp by gateship-one.
the class FilesFragment method onCreateContextMenu.
/**
* Create the context menu.
*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getActivity().getMenuInflater();
int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
MPDFileEntry file = (MPDFileEntry) mAdapter.getItem(position);
if (file instanceof MPDTrack) {
inflater.inflate(R.menu.context_menu_track, menu);
} else if (file instanceof MPDDirectory) {
inflater.inflate(R.menu.context_menu_directory, menu);
} else if (file instanceof MPDPlaylist) {
inflater.inflate(R.menu.context_menu_playlist, menu);
}
}
Aggregations