use of com.afollestad.materialdialogs.MaterialDialog in project PocketHub by pockethub.
the class LabelsDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
Bundle arguments = getArguments();
Activity activity = getActivity();
ArrayList<Label> choices = getChoices();
boolean[] selectedChoices = arguments.getBooleanArray(ARG_SELECTED_CHOICES);
List<String> selected = new ArrayList<>();
if (selectedChoices != null) {
for (int i = 0; i < choices.size(); i++) {
if (selectedChoices[i]) {
selected.add(choices.get(i).name());
}
}
}
arguments.putStringArrayList(ARG_SELECTED, (ArrayList<String>) selected);
LayoutInflater inflater = activity.getLayoutInflater();
ListView view = (ListView) inflater.inflate(R.layout.dialog_list_view, null);
LabelListAdapter adapter = new LabelListAdapter(inflater, choices.toArray(new Label[choices.size()]), selectedChoices);
view.setAdapter(adapter);
view.setOnItemClickListener(adapter);
return new MaterialDialog.Builder(activity).cancelable(true).cancelListener(this).negativeText(R.string.cancel).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
LabelsDialogFragment.this.onClick(dialog, BUTTON_NEGATIVE);
}
}).neutralText(R.string.clear).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
LabelsDialogFragment.this.onClick(dialog, BUTTON_NEUTRAL);
}
}).positiveText(R.string.apply).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
LabelsDialogFragment.this.onClick(dialog, BUTTON_POSITIVE);
}
}).title(getTitle()).content(getMessage()).customView(view, false).build();
}
use of com.afollestad.materialdialogs.MaterialDialog in project PocketHub by pockethub.
the class MilestoneDialogFragment 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) {
MilestoneDialogFragment.this.onClick(dialog, BUTTON_NEGATIVE);
}
}).neutralText(R.string.clear).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
MilestoneDialogFragment.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<Milestone> choices = getChoices();
int selected = arguments.getInt(ARG_SELECTED_CHOICE);
MilestoneListAdapter adapter = new MilestoneListAdapter(inflater, choices.toArray(new Milestone[choices.size()]), selected);
view.setAdapter(adapter);
if (selected >= 0) {
view.setSelection(selected);
}
dialogBuilder.customView(view, false);
return dialogBuilder.build();
}
use of com.afollestad.materialdialogs.MaterialDialog in project XposedInstaller by rovo89.
the class StatusInstallerFragment method showActionDialog.
private void showActionDialog(final Context context, final String title, final FrameworkZips.Type type) {
final int ACTION_FLASH = 0;
final int ACTION_FLASH_RECOVERY = 1;
final int ACTION_SAVE = 2;
final int ACTION_DELETE = 3;
boolean isDownloaded = FrameworkZips.hasLocal(title, type);
int itemCount = isDownloaded ? 3 : 2;
String[] texts = new String[itemCount];
int[] ids = new int[itemCount];
int i = 0;
texts[i] = context.getString(type.text_flash);
ids[i++] = ACTION_FLASH;
texts[i] = context.getString(type.text_flash_recovery);
ids[i++] = ACTION_FLASH_RECOVERY;
if (FrameworkZips.hasLocal(title, type)) {
texts[i] = context.getString(R.string.framework_delete);
ids[i++] = ACTION_DELETE;
}
new MaterialDialog.Builder(context).title(title).items(texts).itemsIds(ids).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
final int action = itemView.getId();
// Handle delete simple actions.
if (action == ACTION_DELETE) {
FrameworkZips.delete(context, title, type);
LOCAL_ZIP_LOADER.triggerReload(true);
return;
}
// Handle actions that need a download first.
RunnableWithParam<File> runAfterDownload = null;
if (action == ACTION_FLASH) {
runAfterDownload = new RunnableWithParam<File>() {
@Override
public void run(File file) {
flash(context, new FlashDirectly(file, type, title, false));
}
};
} else if (action == ACTION_FLASH_RECOVERY) {
runAfterDownload = new RunnableWithParam<File>() {
@Override
public void run(File file) {
flash(context, new FlashRecoveryAuto(file, type, title));
}
};
} else if (action == ACTION_SAVE) {
runAfterDownload = new RunnableWithParam<File>() {
@Override
public void run(File file) {
saveTo(context, file);
}
};
}
LocalFrameworkZip local = FrameworkZips.getLocal(title, type);
if (local != null) {
runAfterDownload.run(local.path);
} else {
download(context, title, type, runAfterDownload);
}
}
}).show();
}
use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.
the class DialogUtils method showBlacklistDialog.
public static void showBlacklistDialog(final Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
final MaterialDialog.Builder builder = getBuilder(context).title(R.string.blacklist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_blacklist).onNegative((materialDialog, dialogAction) -> {
BlacklistHelper.deleteAllSongs();
Toast.makeText(context, R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
});
final Dialog dialog = builder.build();
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
final BlacklistAdapter blacklistAdapter = new BlacklistAdapter();
blacklistAdapter.setBlackListListener((v, position, song) -> {
BlacklistHelper.deleteSong(song.id);
if (blacklistAdapter.items.size() == 0) {
dialog.dismiss();
}
});
recyclerView.setAdapter(blacklistAdapter);
Observable<List<Song>> songsObservable = SqlBriteUtils.createContinuousQuery(ShuttleApplication.getInstance(), Song::new, Song.getQuery()).first();
Observable<List<BlacklistedSong>> blacklistObservable = BlacklistHelper.getBlacklistSongsObservable();
Subscription subscription = Observable.combineLatest(songsObservable, blacklistObservable, (songs, blacklistedSongs) -> Stream.of(songs).filter(song -> Stream.of(blacklistedSongs).anyMatch(blacklistedSong -> blacklistedSong.songId == song.id)).sorted((a, b) -> ComparisonUtils.compare(a.albumArtistName, b.albumArtistName)).sorted((a, b) -> ComparisonUtils.compareInt(b.year, a.year)).sorted((a, b) -> ComparisonUtils.compareInt(a.track, b.track)).sorted((a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber)).sorted((a, b) -> ComparisonUtils.compare(a.albumName, b.albumName)).map(song -> (AdaptableItem) new BlacklistView(song)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(blacklistViews -> {
if (blacklistViews.size() == 0) {
blacklistAdapter.addItem(0, new EmptyView(R.string.blacklist_empty));
} else {
blacklistAdapter.setItems(blacklistViews);
}
});
dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
dialog.show();
}
use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.
the class DialogUtils method showWeekSelectorDialog.
public static void showWeekSelectorDialog(final Context context, final MaterialDialog.SingleButtonCallback listener) {
View view = LayoutInflater.from(context).inflate(R.layout.weekpicker, null);
final NumberPicker numberPicker;
numberPicker = (NumberPicker) view.findViewById(R.id.weeks);
numberPicker.setMaxValue(12);
numberPicker.setMinValue(1);
numberPicker.setValue(MusicUtils.getIntPref(context, "numweeks", 2));
getBuilder(context).title(R.string.week_selector).customView(view, false).negativeText(R.string.cancel).positiveText(R.string.picker_set).onPositive((materialDialog, dialogAction) -> {
int numweeks;
numweeks = numberPicker.getValue();
MusicUtils.setIntPref(context, "numweeks", numweeks);
if (listener != null) {
listener.onClick(materialDialog, dialogAction);
}
}).show();
}
Aggregations