Search in sources :

Example 1 with MPDPlaylist

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);
}
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 2 with MPDPlaylist

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;
                }
        }
    }
}
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 3 with MPDPlaylist

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);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) AdapterView(android.widget.AdapterView)

Example 4 with MPDPlaylist

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;
}
Also used : AlertDialog(android.app.AlertDialog) FileAdapter(org.gateshipone.malp.application.adapters.FileAdapter) PlaylistsLoader(org.gateshipone.malp.application.loaders.PlaylistsLoader) Loader(android.support.v4.content.Loader) Bundle(android.os.Bundle) R(org.gateshipone.malp.R) ThemeUtils(org.gateshipone.malp.application.utils.ThemeUtils) MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) Dialog(android.app.Dialog) ColorDrawable(android.graphics.drawable.ColorDrawable) NonNull(android.support.annotation.NonNull) FileAdapter(org.gateshipone.malp.application.adapters.FileAdapter) AlertDialog(android.app.AlertDialog) OnSaveDialogListener(org.gateshipone.malp.application.callbacks.OnSaveDialogListener) List(java.util.List) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) ColorDrawable(android.graphics.drawable.ColorDrawable) Bundle(android.os.Bundle) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) NonNull(android.support.annotation.NonNull)

Example 5 with MPDPlaylist

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);
    }
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MenuInflater(android.view.MenuInflater) MPDDirectory(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)

Aggregations

MPDPlaylist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)7 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)5 MPDDirectory (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory)4 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)4 Bundle (android.os.Bundle)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 NonNull (android.support.annotation.NonNull)1 Loader (android.support.v4.content.Loader)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 MenuInflater (android.view.MenuInflater)1 AdapterView (android.widget.AdapterView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 R (org.gateshipone.malp.R)1 FileAdapter (org.gateshipone.malp.application.adapters.FileAdapter)1 OnSaveDialogListener (org.gateshipone.malp.application.callbacks.OnSaveDialogListener)1 FileListItem (org.gateshipone.malp.application.listviewitems.FileListItem)1