public Dialog Build(AppCompatActivity activity, ActionSheetConfig config)
        {
            var dlg = new AppCompatAlertDialog.Builder(activity, config.AndroidStyleId ?? 0)
                      .SetTitle(config.Title);

            //.SetCustomTitle(new TextView(activity) {
            //    Text = config.Title,
            //    TextSize = 18.0f
            //});

            if (config.ItemIcon != null || config.Options.Any(x => x.ItemIcon != null))
            {
                var adapter = new ActionSheetListAdapter(activity, Android.Resource.Layout.SelectDialogItem,
                                                         Android.Resource.Id.Text1, config);
                dlg.SetAdapter(adapter, (s, a) => config.Options[a.Which].Action?.Invoke());
            }
            else
            {
                var array = config
                            .Options
                            .Select(x => x.Text)
                            .ToArray();

                dlg.SetSingleChoiceItems(array, config.SelectedIndex, (s, args) =>
                {
                    config.Options[args.Which].Action?.Invoke();
                    (s as AppCompatAlertDialog).Dismiss();
                });
            }

            if (config.Destructive != null)
            {
                dlg.SetNegativeButton(config.Destructive.Text, (s, a) => config.Destructive.Action?.Invoke());
            }

            if (!string.IsNullOrEmpty(config.Cancel?.Text))
            {
                dlg.SetNeutralButton(config.Cancel.Text, (s, a) => config.Cancel.Action?.Invoke());
            }

            return(dlg.Create());
        }
Exemple #2
0
        public static AppCompatAlertDialog.Builder Build(AppCompatActivity activity, ActionSheetConfig config)
        {
            var dlg = new AppCompatAlertDialog
                      .Builder(activity)
                      .SetCancelable(false)
                      .SetTitle(config.Title);

            //.SetCustomTitle(new TextView(activity) {
            //    Text = config.Title,
            //    TextSize = 18.0f
            //});

            if (config.ItemIcon != null || config.Options.Any(x => x.ItemIcon != null))
            {
                var adapter = new ActionSheetListAdapter(activity, Android.Resource.Layout.SelectDialogItem,
                                                         Android.Resource.Id.Text1, config);
                dlg.SetAdapter(adapter, (s, a) => config.Options[a.Which].Action?.Invoke());
            }
            else
            {
                var array = config
                            .Options
                            .Select(x => x.Text)
                            .ToArray();

                dlg.SetItems(array, (s, args) => config.Options[args.Which].Action?.Invoke());
            }

            if (config.Destructive != null)
            {
                dlg.SetNegativeButton(config.Destructive.Text, (s, a) => config.Destructive.Action?.Invoke());
            }

            if (config.Cancel != null)
            {
                dlg.SetNeutralButton(config.Cancel.Text, (s, a) => config.Cancel.Action?.Invoke());
            }

            return(dlg);
        }