Search in sources :

Example 21 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.

the class PlaylistUtils method renamePlaylistDialog.

public static void renamePlaylistDialog(final Context context, final Playlist playlist, final MaterialDialog.SingleButtonCallback listener) {
    View customView = LayoutInflater.from(context).inflate(R.layout.dialog_playlist, null);
    final CustomEditText editText = (CustomEditText) customView.findViewById(R.id.editText);
    editText.setText(playlist.name);
    MaterialDialog.Builder builder = DialogUtils.getBuilder(context).title(R.string.create_playlist_create_text_prompt).customView(customView, false).positiveText(R.string.save).onPositive((materialDialog, dialogAction) -> {
        String name = editText.getText().toString();
        if (name.length() > 0) {
            ContentResolver resolver = context.getContentResolver();
            ContentValues values = new ContentValues(1);
            values.put(MediaStore.Audio.Playlists.NAME, name);
            resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values, MediaStore.Audio.Playlists._ID + "=?", new String[] { Long.valueOf(playlist.id).toString() });
            playlist.name = name;
            Toast.makeText(context, R.string.playlist_renamed_message, Toast.LENGTH_SHORT).show();
        }
        if (listener != null) {
            listener.onClick(materialDialog, dialogAction);
        }
    }).negativeText(R.string.cancel);
    final MaterialDialog dialog = builder.build();
    TextWatcher textWatcher = new TextWatcher() {

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // check if playlist with current name exists already, and warn the user if so.
            setSaveButton(dialog, playlist, editText.getText().toString());
        }

        public void afterTextChanged(Editable s) {
        }
    };
    editText.addTextChangedListener(textWatcher);
    dialog.show();
}
Also used : R(com.simplecity.amp_library.R) Spannable(android.text.Spannable) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Song(com.simplecity.amp_library.model.Song) CheckBox(android.widget.CheckBox) ContentResolver(android.content.ContentResolver) MediaStore(android.provider.MediaStore) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Log(android.util.Log) Playlist(com.simplecity.amp_library.model.Playlist) BaseColumns(android.provider.BaseColumns) SubMenu(android.view.SubMenu) Query(com.simplecity.amp_library.model.Query) List(java.util.List) TextView(android.widget.TextView) ContentValues(android.content.ContentValues) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) TextWatcher(android.text.TextWatcher) FileType(com.simplecity.amp_library.interfaces.FileType) Context(android.content.Context) Stream(com.annimon.stream.Stream) Environment(android.os.Environment) Dialog(android.app.Dialog) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) Observable(rx.Observable) SpannableStringBuilder(android.text.SpannableStringBuilder) Func1(rx.functions.Func1) Toast(android.widget.Toast) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) Cursor(android.database.Cursor) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) FileWriter(java.io.FileWriter) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) WorkerThread(android.support.annotation.WorkerThread) File(java.io.File) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) Crashlytics(com.crashlytics.android.Crashlytics) CustomEditText(com.simplecity.amp_library.ui.views.CustomEditText) EditText(android.widget.EditText) ContentUris(android.content.ContentUris) ContentValues(android.content.ContentValues) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CustomEditText(com.simplecity.amp_library.ui.views.CustomEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) View(android.view.View) TextView(android.widget.TextView) ContentResolver(android.content.ContentResolver)

Example 22 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.

the class TaggerDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View customView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_tagger, null, false);
    setupViews(customView);
    populateViews();
    materialDialog = DialogUtils.getBuilder(getContext()).title(R.string.edit_tags).customView(customView, false).positiveText(R.string.save).onPositive((dialog, which) -> saveTags()).negativeText(R.string.close).onNegative((dialog, which) -> dismiss()).autoDismiss(false).build();
    materialDialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
    return materialDialog;
}
Also used : R(com.simplecity.amp_library.R) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) Bundle(android.os.Bundle) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Dialog(android.app.Dialog) Intent(android.content.Intent) DialogFragment(android.support.v4.app.DialogFragment) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) ArrayList(java.util.ArrayList) Song(com.simplecity.amp_library.model.Song) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) AudioFile(org.jaudiotagger.audio.AudioFile) Toast(android.widget.Toast) View(android.view.View) CustomMediaScanner(com.simplecity.amp_library.utils.CustomMediaScanner) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Log(android.util.Log) FieldKey(org.jaudiotagger.tag.FieldKey) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) ProgressDialog(android.app.ProgressDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) Tag(org.jaudiotagger.tag.Tag) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) File(java.io.File) Serializable(java.io.Serializable) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) FragmentManager(android.support.v4.app.FragmentManager) List(java.util.List) ScrollView(android.widget.ScrollView) TagException(org.jaudiotagger.tag.TagException) AudioFileIO(org.jaudiotagger.audio.AudioFileIO) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Activity(android.app.Activity) DocumentFile(android.support.v4.provider.DocumentFile) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) View(android.view.View) ScrollView(android.widget.ScrollView)

Example 23 with MaterialDialog

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

the class CreatePlaylistDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new MaterialDialog.Builder(getActivity()).title(R.string.create_new_playlist).positiveText(R.string.create).negativeText(R.string.cancel).input(getString(R.string.playlist_name), "", false, new MaterialDialog.InputCallback() {

        @Override
        public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
            long[] songs = getArguments().getLongArray("songs");
            long playistId = MusicPlayer.createPlaylist(getActivity(), input.toString());
            if (playistId != -1) {
                if (songs != null && songs.length != 0) {
                    MusicPlayer.addToPlaylist(getActivity(), songs, playistId);
                } else {
                    Toast.makeText(getActivity(), R.string.create_playlist_success, Toast.LENGTH_SHORT).show();
                }
                RxBus.getInstance().post(new PlaylistUpdateEvent());
            } else {
                Toast.makeText(getActivity(), R.string.create_playlist_fail, Toast.LENGTH_SHORT).show();
            }
        }
    }).build();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) PlaylistUpdateEvent(io.hefuyi.listener.event.PlaylistUpdateEvent) NonNull(android.support.annotation.NonNull) NonNull(android.support.annotation.NonNull)

Example 24 with MaterialDialog

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

the class AlbumAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(final AlbumAdapter.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 Album album = arraylist.get(adapterPosition);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_album_addto_queue:
                            getSongListIdByAlbum(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_album_addto_playlist:
                            getSongListIdByAlbum(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_album_goto_artist:
                            NavigationUtil.goToArtist(mContext, arraylist.get(position).artistId, arraylist.get(position).artistName);
                            break;
                        case R.id.popup_artist_delete:
                            switch(action) {
                                case Constants.NAVIGATE_PLAYLIST_FAVOURATE:
                                    getSongListIdByAlbum(album.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:
                                    getSongListIdByAlbum(album.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                        @Override
                                        public void call(long[] ids) {
                                            ListenerUtil.showDeleteFromRecentlyPlay(mContext, ids);
                                        }
                                    });
                                    break;
                                default:
                                    AlbumSongLoader.getSongsForAlbum(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_album);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Album(io.hefuyi.listener.mvp.model.Album) 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) 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 25 with MaterialDialog

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

the class AlbumSongsAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(final ItemHolder itemHolder, final int 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(position).id;
                            MusicPlayer.playNext(mContext, ids, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_goto_album:
                            NavigationUtil.goToAlbum(mContext, arraylist.get(position).albumId, arraylist.get(position).title);
                            break;
                        case R.id.popup_song_goto_artist:
                            NavigationUtil.goToArtist(mContext, arraylist.get(position).artistId, arraylist.get(position).artistName);
                            break;
                        case R.id.popup_song_addto_queue:
                            long[] id = new long[1];
                            id[0] = arraylist.get(position).id;
                            MusicPlayer.addToQueue(mContext, id, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_addto_playlist:
                            ListenerUtil.showAddPlaylistDialog(mContext, new long[] { arraylist.get(itemHolder.getAdapterPosition()).id });
                            break;
                        case R.id.popup_song_delete:
                            long[] deleteIds = { arraylist.get(position).id };
                            ListenerUtil.showDeleteDialog(mContext, arraylist.get(position).title, deleteIds, new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    arraylist.remove(position);
                                    songIDs = getSongIds();
                                    notifyDataSetChanged();
                                }
                            });
                            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) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.widget.PopupMenu)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)80 View (android.view.View)49 DialogAction (com.afollestad.materialdialogs.DialogAction)44 NonNull (android.support.annotation.NonNull)32 TextView (android.widget.TextView)32 Intent (android.content.Intent)19 ImageView (android.widget.ImageView)19 RecyclerView (android.support.v7.widget.RecyclerView)17 File (java.io.File)17 MenuItem (android.view.MenuItem)14 PopupMenu (android.widget.PopupMenu)12 List (java.util.List)12 ListView (android.widget.ListView)11 Activity (android.app.Activity)9 Toast (android.widget.Toast)9 SuppressLint (android.annotation.SuppressLint)8 Context (android.content.Context)8 Bundle (android.os.Bundle)8 ArrayList (java.util.ArrayList)8 LayoutInflater (android.view.LayoutInflater)7