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();
}
});
}
use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.
the class FileChooserDialog method onCreateDialog.
@SuppressWarnings("ConstantConditions")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
return new MaterialDialog.Builder(getActivity()).title(R.string.md_error_label).content(R.string.md_storage_perm_error).positiveText(android.R.string.ok).build();
}
if (getArguments() == null || !getArguments().containsKey("builder")) {
throw new IllegalStateException("You must create a FileChooserDialog using the Builder.");
}
if (!getArguments().containsKey("current_path")) {
getArguments().putString("current_path", getBuilder().initialPath);
}
parentFolder = new File(getArguments().getString("current_path"));
checkIfCanGoUp();
parentContents = listFiles(getBuilder().mimeType, getBuilder().extensions);
return new MaterialDialog.Builder(getActivity()).title(parentFolder.getAbsolutePath()).items(getContentsArray()).itemsCallback(this).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
}
}).autoDismiss(false).negativeText(getBuilder().cancelButton).build();
}
use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.
the class MaterialEditTextPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).dismissListener(this).onAny(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
switch(which) {
default:
MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
break;
case NEUTRAL:
MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
break;
case NEGATIVE:
MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
break;
}
}
}).dismissListener(this);
@SuppressLint("InflateParams") View layout = LayoutInflater.from(getContext()).inflate(R.layout.md_stub_inputpref, null);
onBindDialogView(layout);
MDTintHelper.setTint(editText, color);
TextView message = (TextView) layout.findViewById(android.R.id.message);
if (getDialogMessage() != null && getDialogMessage().toString().length() > 0) {
message.setVisibility(View.VISIBLE);
message.setText(getDialogMessage());
} else {
message.setVisibility(View.GONE);
}
mBuilder.customView(layout, false);
PrefUtil.registerOnActivityDestroyListener(this, this);
dialog = mBuilder.build();
if (state != null) {
dialog.onRestoreInstanceState(state);
}
requestInputMethod(dialog);
dialog.show();
}
use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.
the class MaterialListPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
if (getEntries() == null || getEntryValues() == null) {
throw new IllegalStateException("ListPreference requires an entries array and an entryValues array.");
}
int preselect = findIndexOfValue(getValue());
MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getDialogTitle()).icon(getDialogIcon()).dismissListener(this).onAny(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
switch(which) {
default:
MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
break;
case NEUTRAL:
MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
break;
case NEGATIVE:
MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
break;
}
}
}).negativeText(getNegativeButtonText()).items(getEntries()).autoDismiss(// immediately close the dialog after selection
true).itemsCallbackSingleChoice(preselect, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
onClick(null, DialogInterface.BUTTON_POSITIVE);
if (which >= 0 && getEntryValues() != null) {
try {
Field clickedIndex = ListPreference.class.getDeclaredField("mClickedDialogEntryIndex");
clickedIndex.setAccessible(true);
clickedIndex.set(MaterialListPreference.this, which);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
});
final View contentView = onCreateDialogView();
if (contentView != null) {
onBindDialogView(contentView);
builder.customView(contentView, false);
} else {
builder.content(getDialogMessage());
}
PrefUtil.registerOnActivityDestroyListener(this, this);
dialog = builder.build();
if (state != null) {
dialog.onRestoreInstanceState(state);
}
onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
dialog.show();
}
use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.
the class MaterialMultiSelectListPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
List<Integer> indices = new ArrayList<>();
for (String s : getValues()) {
int index = findIndexOfValue(s);
if (index >= 0) {
indices.add(findIndexOfValue(s));
}
}
MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getDialogTitle()).icon(getDialogIcon()).negativeText(getNegativeButtonText()).positiveText(getPositiveButtonText()).onAny(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
switch(which) {
default:
MaterialMultiSelectListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
break;
case NEUTRAL:
MaterialMultiSelectListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
break;
case NEGATIVE:
MaterialMultiSelectListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
break;
}
}
}).items(getEntries()).itemsCallbackMultiChoice(indices.toArray(new Integer[indices.size()]), new MaterialDialog.ListCallbackMultiChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
onClick(null, DialogInterface.BUTTON_POSITIVE);
dialog.dismiss();
final Set<String> values = new HashSet<>();
for (int i : which) {
values.add(getEntryValues()[i].toString());
}
if (callChangeListener(values)) {
setValues(values);
}
return true;
}
}).dismissListener(this);
final View contentView = onCreateDialogView();
if (contentView != null) {
onBindDialogView(contentView);
builder.customView(contentView, false);
} else {
builder.content(getDialogMessage());
}
PrefUtil.registerOnActivityDestroyListener(this, this);
mDialog = builder.build();
if (state != null) {
mDialog.onRestoreInstanceState(state);
}
mDialog.show();
}
Aggregations