public static void CreateNewActivity(BaseAniDroidActivity context, Func <string, Task> saveAction)
        {
            var dialog     = new AlertDialog.Builder(context, context.GetThemedResourceId(Resource.Attribute.Dialog_Theme)).Create();
            var dialogView = context.LayoutInflater.Inflate(Resource.Layout.Dialog_AniListActivityCreate, null);

            dialog.SetView(dialogView);

            dialog.SetButton((int)DialogButtonType.Negative, "Cancel", (send, args) => dialog.Dismiss());
            dialog.SetButton((int)DialogButtonType.Positive, "Post", (send, args) => { });

            dialog.ShowEvent += (sender2, e2) =>
            {
                var activityText = dialogView.FindViewById <EditText>(Resource.Id.AniListActivityCreate_Text);
                var createButton = dialog.GetButton((int)DialogButtonType.Positive);
                createButton.SetOnClickListener(new InterceptClickListener(async() =>
                {
                    if (string.IsNullOrWhiteSpace(activityText.Text))
                    {
                        Toast.MakeText(context, "Text can't be empty!", ToastLength.Short).Show();
                        return;
                    }

                    await saveAction(activityText.Text);
                    dialog.Dismiss();
                }));
            };

            dialog.Show();
        }
Exemple #2
0
        private static void CreateEditReply(BaseAniDroidActivity context, string oldText, Func <string, Task> saveAction, Func <Task> deleteAction)
        {
            var dialog          = new AlertDialog.Builder(context, context.GetThemedResourceId(Resource.Attribute.Dialog_Theme)).Create();
            var dialogView      = context.LayoutInflater.Inflate(Resource.Layout.Dialog_AniListActivityCreate, null);
            var replyText       = dialogView.FindViewById <EditText>(Resource.Id.AniListActivityCreate_Text);
            var replyTextLayout = dialogView.FindViewById <TextInputLayout>(Resource.Id.AniListActivityCreate_TextLayout);

            replyTextLayout.Hint = "Reply Text";

            replyText.Text = oldText;

            dialog.SetView(dialogView);

            dialog.SetButton((int)DialogButtonType.Negative, "Cancel", (send, args) => dialog.Dismiss());
            dialog.SetButton((int)DialogButtonType.Positive, "Save", (send, args) => { });
            dialog.SetButton((int)DialogButtonType.Neutral, "Delete", (send, args) =>
            {
                var confirmationDialog = new AlertDialog.Builder(context,
                                                                 context.GetThemedResourceId(Resource.Attribute.Dialog_Theme)).Create();
                confirmationDialog.SetTitle("Delete Reply");
                confirmationDialog.SetMessage("Are you sure you wish to delete this reply?");

                confirmationDialog.SetButton((int)DialogButtonType.Negative, "Cancel",
                                             (cSend, cArgs) => confirmationDialog.Dismiss());
                confirmationDialog.SetButton((int)DialogButtonType.Positive, "Delete",
                                             (cSend, cArgs) =>
                {
                    confirmationDialog.Dismiss();
                    dialog.Dismiss();
                    deleteAction?.Invoke();
                });

                confirmationDialog.Show();
            });

            dialog.ShowEvent += (sender2, e2) =>
            {
                var createButton = dialog.GetButton((int)DialogButtonType.Positive);
                createButton.SetOnClickListener(new InterceptClickListener(async() =>
                {
                    if (string.IsNullOrWhiteSpace(replyText.Text))
                    {
                        Toast.MakeText(context, "Text can't be empty!", ToastLength.Short).Show();
                        return;
                    }

                    await saveAction(replyText.Text);
                    dialog.Dismiss();
                }));
            };

            dialog.Show();
        }
Exemple #3
0
        private void ShowUpdateDialog(int ID)
        {
            Product p    = ProductDB.GetByID(ID);
            var     view = LayoutInflater.Inflate(Resource.Layout.productCard, null);

            var name       = view.FindViewById <EditText>(Resource.Id.nameInputCard);
            var desc       = view.FindViewById <EditText>(Resource.Id.descriptionInputCard);
            var price      = view.FindViewById <EditText>(Resource.Id.priceInputCard);
            var code       = view.FindViewById <EditText>(Resource.Id.codeInputCard);
            var scanButton = view.FindViewById <ImageButton>(Resource.Id.scanCodeImgBtn);

            name.Text  = p.ProductName;
            price.Text = p.Price.ToString();
            code.Text  = p.BarCodeInfo;
            desc.Text  = p.Description;

            scanButton.Click += async delegate
            {
                _barcodeScanner.UseCustomOverlay = false;
                //We can customize the top and bottom text of the default overlay
                _barcodeScanner.TopText    = "Hold the camera up to the barcode\nAbout 6 inches away";
                _barcodeScanner.BottomText = "Wait for the barcode to automatically scan!";

                //Start scanning
                var result = await _barcodeScanner.Scan();

                HandleScanResult(result, code);
            };

            var dialog =
                new AlertDialog.Builder(this)
                .SetView(view)
                .SetTitle("Edit item")
                .SetPositiveButton("SAVE", (EventHandler <Android.Content.DialogClickEventArgs>)null)
                .SetNegativeButton("Cancel", (s, args) => { }).Create();

            dialog.Show();

            var okButton = dialog.GetButton((int)DialogButtonType.Positive);

            okButton.Click += delegate
            {
                if (string.IsNullOrWhiteSpace(name.Text))
                {
                    RunOnUiThread(() => Toast.MakeText(this, "Fill Name"
                                                       , ToastLength.Short).Show());
                    name.RequestFocus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(price.Text))
                {
                    RunOnUiThread(() => Toast.MakeText(this, "Fill Valid Price"
                                                       , ToastLength.Short).Show());
                    price.RequestFocus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(code.Text))
                {
                    RunOnUiThread(() => Toast.MakeText(this, "Fill Valid Barcode"
                                                       , ToastLength.Short).Show());
                    code.RequestFocus();
                    return;
                }
                if (!string.Equals(p.BarCodeInfo, code.Text.Trim()) &&
                    ProductDB.FindByBarcode(code.Text.Trim()) != null)
                {
                    RunOnUiThread(() => Toast.MakeText(this, "Barcode muast be unique"
                                                       , ToastLength.Short).Show());
                    code.RequestFocus();
                    return;
                }

                /*
                 * Product p = new Product
                 * {
                 *  ProductName = name.Text,
                 *  Price = float.Parse(price.Text),
                 *  Description = desc.Text,
                 *  BarCodeInfo = code.Text
                 * };
                 * ProductDB.Insert(p);
                 */
                //_adapter.RefreshData();
                p.ProductName = name.Text.Trim();
                p.Description = desc.Text.Trim();
                p.Price       = float.Parse(price.Text.Trim());
                p.BarCodeInfo = code.Text.Trim();

                ProductDB.Update(p);
                _adapter.RefreshData();
                dialog.Dismiss();
            };
        }