Search in sources :

Example 16 with MaterialDialog

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Bundle(android.os.Bundle) Label(com.meisolsson.githubsdk.model.Label) ArrayList(java.util.ArrayList) BaseActivity(com.github.pockethub.android.ui.BaseActivity) Activity(android.app.Activity) ListView(android.widget.ListView) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater)

Example 17 with MaterialDialog

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Bundle(android.os.Bundle) Milestone(com.meisolsson.githubsdk.model.Milestone) 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)

Example 18 with MaterialDialog

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) RunnableWithParam(de.robv.android.xposed.installer.util.RunnableWithParam) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) LocalFrameworkZip(de.robv.android.xposed.installer.util.FrameworkZips.LocalFrameworkZip) File(java.io.File)

Example 19 with MaterialDialog

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();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProgressBar(android.widget.ProgressBar) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Drawable(android.graphics.drawable.Drawable) FileProvider(android.support.v4.content.FileProvider) Song(com.simplecity.amp_library.model.Song) FileObject(com.simplecity.amp_library.model.FileObject) Schedulers(rx.schedulers.Schedulers) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) R.id.album(com.simplecity.amp_library.R.id.album) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) R.id.artist(com.simplecity.amp_library.R.id.artist) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) FileNotFoundException(java.io.FileNotFoundException) CustomColorPicker(com.simplecity.amp_library.ui.views.CustomColorPicker) List(java.util.List) TextView(android.widget.TextView) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) Html(android.text.Html) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) ListView(android.widget.ListView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) Subscription(rx.Subscription) NumberPicker(android.widget.NumberPicker) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) Context(android.content.Context) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) HttpClient(com.simplecity.amp_library.http.HttpClient) Dialog(android.app.Dialog) Intent(android.content.Intent) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) SettingsFragment(com.simplecity.amp_library.ui.fragments.SettingsFragment) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BlacklistedSong(com.simplecity.amp_library.model.BlacklistedSong) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) IntentCompat(android.support.v4.content.IntentCompat) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) ArrayAdapter(android.widget.ArrayAdapter) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) ArrayList(java.util.ArrayList) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) Subscription(rx.Subscription) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 20 with MaterialDialog

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();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProgressBar(android.widget.ProgressBar) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Drawable(android.graphics.drawable.Drawable) FileProvider(android.support.v4.content.FileProvider) Song(com.simplecity.amp_library.model.Song) FileObject(com.simplecity.amp_library.model.FileObject) Schedulers(rx.schedulers.Schedulers) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) R.id.album(com.simplecity.amp_library.R.id.album) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) R.id.artist(com.simplecity.amp_library.R.id.artist) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) FileNotFoundException(java.io.FileNotFoundException) CustomColorPicker(com.simplecity.amp_library.ui.views.CustomColorPicker) List(java.util.List) TextView(android.widget.TextView) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) Html(android.text.Html) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) ListView(android.widget.ListView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) Subscription(rx.Subscription) NumberPicker(android.widget.NumberPicker) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) Context(android.content.Context) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) HttpClient(com.simplecity.amp_library.http.HttpClient) Dialog(android.app.Dialog) Intent(android.content.Intent) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) SettingsFragment(com.simplecity.amp_library.ui.fragments.SettingsFragment) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BlacklistedSong(com.simplecity.amp_library.model.BlacklistedSong) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) IntentCompat(android.support.v4.content.IntentCompat) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) ArrayAdapter(android.widget.ArrayAdapter) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) NumberPicker(android.widget.NumberPicker) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView)

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