Search in sources :

Example 26 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project ListenerMusicPlayer by hefuyicoder.

the class SearchAdapter method setSongPopupMenu.

private void setSongPopupMenu(ItemHolder itemHolder, final int position) {
    final Song song = (Song) searchResults.get(position);
    itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(mContext, v);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_song_play_next:
                            MusicPlayer.playNext(mContext, new long[] { song.id }, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_goto_album:
                            NavigationUtil.goToAlbum(mContext, song.albumId, song.title);
                            break;
                        case R.id.popup_song_goto_artist:
                            NavigationUtil.goToArtist(mContext, song.artistId, song.artistName);
                            break;
                        case R.id.popup_song_addto_queue:
                            MusicPlayer.addToQueue(mContext, new long[] { song.id }, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_addto_playlist:
                            ListenerUtil.showAddPlaylistDialog(mContext, new long[] { song.id });
                            break;
                        case R.id.popup_song_delete:
                            ListenerUtil.showDeleteDialog(mContext, song.title, new long[] { song.id }, new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    searchResults.remove(position);
                                    notifyItemRemoved(position);
                                }
                            });
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_song);
            menu.show();
        }
    });
}
Also used : Song(io.hefuyi.listener.mvp.model.Song) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu)

Example 27 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project ListenerMusicPlayer by hefuyicoder.

the class SongsListAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) {
    final int realSongPosition;
    if (withHeader) {
        realSongPosition = position - 1;
    } else {
        realSongPosition = position;
    }
    itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(mContext, v);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_song_play_next:
                            long[] ids = new long[1];
                            ids[0] = arraylist.get(realSongPosition).id;
                            MusicPlayer.playNext(mContext, ids, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_goto_album:
                            NavigationUtil.goToAlbum(mContext, arraylist.get(realSongPosition).albumId, arraylist.get(realSongPosition).title);
                            break;
                        case R.id.popup_song_goto_artist:
                            NavigationUtil.goToArtist(mContext, arraylist.get(realSongPosition).artistId, arraylist.get(realSongPosition).artistName);
                            break;
                        case R.id.popup_song_addto_queue:
                            long[] id = new long[1];
                            id[0] = arraylist.get(realSongPosition).id;
                            MusicPlayer.addToQueue(mContext, id, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_addto_playlist:
                            ListenerUtil.showAddPlaylistDialog(mContext, new long[] { arraylist.get(realSongPosition).id });
                            break;
                        case R.id.popup_song_delete:
                            long[] deleteIds = { arraylist.get(realSongPosition).id };
                            switch(action) {
                                case Constants.NAVIGATE_PLAYLIST_FAVOURATE:
                                    ListenerUtil.showDeleteFromFavourate(mContext, deleteIds);
                                    break;
                                case Constants.NAVIGATE_PLAYLIST_RECENTPLAY:
                                    ListenerUtil.showDeleteFromRecentlyPlay(mContext, deleteIds);
                                    break;
                                default:
                                    ListenerUtil.showDeleteDialog(mContext, arraylist.get(realSongPosition).title, deleteIds, new MaterialDialog.SingleButtonCallback() {

                                        @Override
                                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                            arraylist.remove(realSongPosition);
                                            songIDs = getSongIds();
                                            notifyItemRemoved(position);
                                        }
                                    });
                                    break;
                            }
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_song);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) FastScrollRecyclerView(io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu)

Example 28 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project ListenerMusicPlayer by hefuyicoder.

the class ArtistAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(final ArtistAdapter.ItemHolder itemHolder, final int position) {
    itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(mContext, v);
            int adapterPosition = itemHolder.getAdapterPosition();
            final Artist artist = arraylist.get(adapterPosition);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_artist_addto_queue:
                            getSongListIdByArtist(arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.NA);
                                }
                            });
                            break;
                        case R.id.popup_artist_addto_playlist:
                            getSongListIdByArtist(arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    ListenerUtil.showAddPlaylistDialog(mContext, ids);
                                }
                            });
                            break;
                        case R.id.popup_artist_delete:
                            switch(action) {
                                case Constants.NAVIGATE_PLAYLIST_FAVOURATE:
                                    getSongListIdByArtist(artist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                        @Override
                                        public void call(long[] ids) {
                                            ListenerUtil.showDeleteFromFavourate(mContext, ids);
                                        }
                                    });
                                    break;
                                case Constants.NAVIGATE_PLAYLIST_RECENTPLAY:
                                    getSongListIdByArtist(artist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                        @Override
                                        public void call(long[] ids) {
                                            ListenerUtil.showDeleteFromRecentlyPlay(mContext, ids);
                                        }
                                    });
                                    break;
                                default:
                                    ArtistSongLoader.getSongsForArtist(mContext, arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Song>>() {

                                        @Override
                                        public void call(List<Song> songs) {
                                            long[] ids = new long[songs.size()];
                                            int i = 0;
                                            for (Song song : songs) {
                                                ids[i] = song.id;
                                                i++;
                                            }
                                            if (ids.length == 1) {
                                                ListenerUtil.showDeleteDialog(mContext, songs.get(0).title, ids, new MaterialDialog.SingleButtonCallback() {

                                                    @Override
                                                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                        arraylist.remove(position);
                                                        notifyDataSetChanged();
                                                    }
                                                });
                                            } else {
                                                String songCount = ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, arraylist.get(position).songCount);
                                                ListenerUtil.showDeleteDialog(mContext, songCount, ids, new MaterialDialog.SingleButtonCallback() {

                                                    @Override
                                                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                        arraylist.remove(position);
                                                        notifyDataSetChanged();
                                                    }
                                                });
                                            }
                                        }
                                    });
                                    break;
                            }
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_artist);
            menu.show();
        }
    });
}
Also used : Artist(io.hefuyi.listener.mvp.model.Artist) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) FastScrollRecyclerView(io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Song(io.hefuyi.listener.mvp.model.Song) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) List(java.util.List) PopupMenu(android.widget.PopupMenu)

Example 29 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project CoCoin by Nightonke.

the class AccountBookSettingActivity method changeLogo.

// change the user logo/////////////////////////////////////////////////////////////////////////////
private void changeLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user == null) {
        new MaterialDialog.Builder(this).iconRes(R.drawable.cocoin_logo).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.login_first_title).content(R.string.login_first_content).positiveText(R.string.ok).neutralText(R.string.cancel).onAny(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                if (which == DialogAction.POSITIVE) {
                    userOperator();
                }
            }
        }).show();
        return;
    }
    new MaterialDialog.Builder(this).iconRes(R.drawable.cocoin_logo).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.change_logo_title).content(R.string.change_logo_content).positiveText(R.string.from_gallery).negativeText(R.string.from_camera).neutralText(R.string.cancel).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            if (which == DialogAction.POSITIVE) {
                Intent intent1 = new Intent(Intent.ACTION_PICK, null);
                intent1.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                startActivityForResult(intent1, 1);
            } else if (which == DialogAction.NEGATIVE) {
                Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent2.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)));
                startActivityForResult(intent2, 2);
            }
        }
    }).show();
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File)

Example 30 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project PocketHub by pockethub.

the class AssigneeDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    Activity activity = getActivity();
    Bundle arguments = getArguments();
    final MaterialDialog.Builder dialogBuilder = createDialogBuilder().negativeText(R.string.cancel).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            AssigneeDialogFragment.this.onClick(dialog, BUTTON_NEGATIVE);
        }
    }).neutralText(R.string.clear).onNeutral(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            AssigneeDialogFragment.this.onClick(dialog, BUTTON_NEUTRAL);
        }
    });
    LayoutInflater inflater = activity.getLayoutInflater();
    ListView view = (ListView) inflater.inflate(R.layout.dialog_list_view, null);
    view.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            onClick(getDialog(), position);
        }
    });
    ArrayList<User> choices = getChoices();
    int selected = arguments.getInt(ARG_SELECTED_CHOICE);
    UserListAdapter adapter = new UserListAdapter(inflater, choices.toArray(new User[choices.size()]), selected, loader);
    view.setAdapter(adapter);
    if (selected >= 0) {
        view.setSelection(selected);
    }
    dialogBuilder.customView(view, false);
    return dialogBuilder.build();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) User(com.meisolsson.githubsdk.model.User) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Bundle(android.os.Bundle) BaseActivity(com.github.pockethub.android.ui.BaseActivity) Activity(android.app.Activity) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater)

Aggregations

DialogAction (com.afollestad.materialdialogs.DialogAction)42 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)42 NonNull (android.support.annotation.NonNull)27 View (android.view.View)27 TextView (android.widget.TextView)21 ImageView (android.widget.ImageView)15 RecyclerView (android.support.v7.widget.RecyclerView)13 MenuItem (android.view.MenuItem)12 PopupMenu (android.widget.PopupMenu)12 Intent (android.content.Intent)7 File (java.io.File)7 LayoutInflater (android.view.LayoutInflater)6 Song (io.hefuyi.listener.mvp.model.Song)6 FastScrollRecyclerView (io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView)6 List (java.util.List)6 Activity (android.app.Activity)4 Bundle (android.os.Bundle)4 ListView (android.widget.ListView)4 IOException (java.io.IOException)4 SuppressLint (android.annotation.SuppressLint)3