Search in sources :

Example 1 with MPDQueryHandler

use of org.gateshipone.malp.mpdservice.handlers.serverhandler.MPDQueryHandler in project malp by gateship-one.

the class NowPlayingView method onMenuItemClick.

/**
 * Menu click listener. This method gets called when the user selects an item of the popup menu (right top corner).
 *
 * @param item MenuItem that was clicked.
 * @return Returns true if the item was handled by this method. False otherwise.
 */
@Override
public boolean onMenuItemClick(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_clear_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_current_playlist));
            removeListBuilder.setPositiveButton(R.string.dialog_action_yes, (dialog, which) -> MPDQueryHandler.clearPlaylist());
            removeListBuilder.setNegativeButton(R.string.dialog_action_no, (dialog, which) -> {
            });
            removeListBuilder.create().show();
            break;
        case R.id.action_shuffle_playlist:
            {
                final AlertDialog.Builder shuffleListBuilder = new AlertDialog.Builder(getContext());
                shuffleListBuilder.setTitle(getContext().getString(R.string.action_shuffle_playlist));
                shuffleListBuilder.setMessage(getContext().getString(R.string.dialog_message_shuffle_current_playlist));
                shuffleListBuilder.setPositiveButton(R.string.dialog_action_yes, (dialog, which) -> MPDQueryHandler.shufflePlaylist());
                shuffleListBuilder.setNegativeButton(R.string.dialog_action_no, (dialog, which) -> {
                });
                shuffleListBuilder.create().show();
            }
            break;
        case R.id.action_save_playlist:
            OnSaveDialogListener plDialogCallback = new OnSaveDialogListener() {

                @Override
                public void onSaveObject(final String title) {
                    AlertDialog.Builder overWriteBuilder = new AlertDialog.Builder(getContext());
                    overWriteBuilder.setTitle(getContext().getString(R.string.action_overwrite_playlist));
                    overWriteBuilder.setMessage(getContext().getString(R.string.dialog_message_overwrite_playlist) + ' ' + title + '?');
                    overWriteBuilder.setPositiveButton(R.string.dialog_action_yes, (dialog, which) -> {
                        MPDQueryHandler.removePlaylist(title);
                        MPDQueryHandler.savePlaylist(title);
                    });
                    overWriteBuilder.setNegativeButton(R.string.dialog_action_no, (dialog, which) -> {
                    });
                    overWriteBuilder.create().show();
                }

                @Override
                public void onCreateNewObject() {
                    // open dialog in order to save the current playlist as a playlist in the mediastore
                    TextDialog textDialog = new TextDialog();
                    Bundle args = new Bundle();
                    args.putString(TextDialog.EXTRA_DIALOG_TITLE, getResources().getString(R.string.dialog_save_playlist));
                    args.putString(TextDialog.EXTRA_DIALOG_TEXT, getResources().getString(R.string.default_playlist_title));
                    textDialog.setCallback(MPDQueryHandler::savePlaylist);
                    textDialog.setArguments(args);
                    textDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "SavePLTextDialog");
                }
            };
            // 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(plDialogCallback);
            choosePlaylistDialog.setArguments(args);
            choosePlaylistDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "ChoosePlaylistDialog");
            break;
        case R.id.action_add_url:
            TextDialog addURLDialog = new TextDialog();
            addURLDialog.setCallback(MPDQueryHandler::addPath);
            Bundle textDialogArgs = new Bundle();
            textDialogArgs.putString(TextDialog.EXTRA_DIALOG_TEXT, "http://...");
            textDialogArgs.putString(TextDialog.EXTRA_DIALOG_TITLE, getResources().getString(R.string.action_add_url));
            addURLDialog.setArguments(textDialogArgs);
            addURLDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "AddURLDialog");
            break;
        case R.id.action_jump_to_current:
            mPlaylistView.jumpToCurrentSong();
            break;
        case R.id.action_toggle_single_mode:
            if (null != mLastStatus) {
                if (mLastStatus.getSinglePlayback() == 0) {
                    MPDCommandHandler.setSingle(true);
                } else {
                    MPDCommandHandler.setSingle(false);
                }
            }
            break;
        case R.id.action_toggle_consume_mode:
            if (null != mLastStatus) {
                if (mLastStatus.getConsume() == 0) {
                    MPDCommandHandler.setConsume(true);
                } else {
                    MPDCommandHandler.setConsume(false);
                }
            }
            break;
        case R.id.action_open_fanart:
            Intent intent = new Intent(getContext(), FanartActivity.class);
            getContext().startActivity(intent);
            return true;
        case R.id.action_wikipedia_album:
            Intent albumIntent = new Intent(Intent.ACTION_VIEW);
            // albumIntent.setData(Uri.parse("https://" + Locale.getDefault().getLanguage() + ".wikipedia.org/wiki/index.php?search=" + mLastTrack.getTrackAlbum() + "&title=Special:Search&go=Go"));
            if (mUseEnglishWikipedia) {
                albumIntent.setData(Uri.parse("https://en.wikipedia.org/wiki/" + mLastTrack.getTrackAlbum()));
            } else {
                albumIntent.setData(Uri.parse("https://" + Locale.getDefault().getLanguage() + ".wikipedia.org/wiki/" + mLastTrack.getTrackAlbum()));
            }
            getContext().startActivity(albumIntent);
            return true;
        case R.id.action_wikipedia_artist:
            Intent artistIntent = new Intent(Intent.ACTION_VIEW);
            // artistIntent.setData(Uri.parse("https://" + Locale.getDefault().getLanguage() + ".wikipedia.org/wiki/index.php?search=" + mLastTrack.getTrackAlbumArtist() + "&title=Special:Search&go=Go"));
            if (mUseEnglishWikipedia) {
                artistIntent.setData(Uri.parse("https://en.wikipedia.org/wiki/" + mLastTrack.getTrackArtist()));
            } else {
                artistIntent.setData(Uri.parse("https://" + Locale.getDefault().getLanguage() + ".wikipedia.org/wiki/" + mLastTrack.getTrackArtist()));
            }
            getContext().startActivity(artistIntent);
            return true;
        case R.id.action_start_streaming:
            {
                if (mStreamingStatus == BackgroundService.STREAMING_STATUS.PLAYING || mStreamingStatus == BackgroundService.STREAMING_STATUS.BUFFERING) {
                    try {
                        mBackgroundServiceConnection.getService().stopStreamingPlayback();
                    } catch (RemoteException e) {
                    }
                } else {
                    try {
                        mBackgroundServiceConnection.getService().startStreamingPlayback();
                    } catch (RemoteException e) {
                    }
                }
                return true;
            }
        case R.id.action_share_current_song:
            {
                shareCurrentTrack();
                return true;
            }
        default:
            return false;
    }
    return false;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ImageButton(android.widget.ImageButton) ViewDragHelper(android.support.v4.widget.ViewDragHelper) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) MPDStateMonitoringHandler(org.gateshipone.malp.mpdservice.handlers.serverhandler.MPDStateMonitoringHandler) DrawableCompat(android.support.v4.graphics.drawable.DrawableCompat) Uri(android.net.Uri) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) VolumeButtonLongClickListener(org.gateshipone.malp.application.utils.VolumeButtonLongClickListener) ColorStateList(android.content.res.ColorStateList) ChoosePlaylistDialog(org.gateshipone.malp.application.fragments.serverfragments.ChoosePlaylistDialog) AttributeSet(android.util.AttributeSet) Locale(java.util.Locale) Looper(android.os.Looper) PopupMenu(android.widget.PopupMenu) View(android.view.View) MPDStatusChangeHandler(org.gateshipone.malp.mpdservice.handlers.MPDStatusChangeHandler) ViewCompat(android.support.v4.view.ViewCompat) PreferenceManager(android.preference.PreferenceManager) ViewSwitcher(android.widget.ViewSwitcher) BackgroundServiceConnection(org.gateshipone.malp.application.background.BackgroundServiceConnection) IntentFilter(android.content.IntentFilter) ThemeUtils(org.gateshipone.malp.application.utils.ThemeUtils) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) TextDialog(org.gateshipone.malp.application.fragments.TextDialog) FormatHelper(org.gateshipone.malp.application.utils.FormatHelper) TextView(android.widget.TextView) MPDInterface(org.gateshipone.malp.mpdservice.mpdprotocol.MPDInterface) OutputResponseMenuHandler(org.gateshipone.malp.application.utils.OutputResponseMenuHandler) MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus) RelativeLayout(android.widget.RelativeLayout) ArtworkManager(org.gateshipone.malp.application.artworkdatabase.ArtworkManager) Context(android.content.Context) R(org.gateshipone.malp.R) MPDConnectionStateChangeHandler(org.gateshipone.malp.mpdservice.handlers.MPDConnectionStateChangeHandler) Intent(android.content.Intent) RemoteException(android.os.RemoteException) NonNull(android.support.annotation.NonNull) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) BackgroundService(org.gateshipone.malp.application.background.BackgroundService) MenuItem(android.view.MenuItem) SeekBar(android.widget.SeekBar) MotionEvent(android.view.MotionEvent) Menu(android.view.Menu) MPDQueryHandler(org.gateshipone.malp.mpdservice.handlers.serverhandler.MPDQueryHandler) CoverBitmapLoader(org.gateshipone.malp.application.utils.CoverBitmapLoader) ConnectionManager(org.gateshipone.malp.mpdservice.ConnectionManager) WeakReference(java.lang.ref.WeakReference) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDCommandHandler(org.gateshipone.malp.mpdservice.handlers.serverhandler.MPDCommandHandler) OnSaveDialogListener(org.gateshipone.malp.application.callbacks.OnSaveDialogListener) FanartActivity(org.gateshipone.malp.application.activities.FanartActivity) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) Activity(android.app.Activity) TextDialog(org.gateshipone.malp.application.fragments.TextDialog) Bundle(android.os.Bundle) ChoosePlaylistDialog(org.gateshipone.malp.application.fragments.serverfragments.ChoosePlaylistDialog) MPDQueryHandler(org.gateshipone.malp.mpdservice.handlers.serverhandler.MPDQueryHandler) Intent(android.content.Intent) RemoteException(android.os.RemoteException) OnSaveDialogListener(org.gateshipone.malp.application.callbacks.OnSaveDialogListener)

Aggregations

Activity (android.app.Activity)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 ColorStateList (android.content.res.ColorStateList)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Looper (android.os.Looper)1 RemoteException (android.os.RemoteException)1 PreferenceManager (android.preference.PreferenceManager)1 NonNull (android.support.annotation.NonNull)1 DrawableCompat (android.support.v4.graphics.drawable.DrawableCompat)1 ViewCompat (android.support.v4.view.ViewCompat)1 ViewDragHelper (android.support.v4.widget.ViewDragHelper)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1