示例#1
0
        public SettingsViewController() : base(UITableViewStyle.Grouped, null)
        {
            var testButton = new SimpleButton {
                Title      = "Test Connection",
                TitleColor = UIColor.Black,
                Tapped     = async(t) => {
                    View.DismissKeyboard();
                    var f = t.Frame;
                    t.Title = "Testing...";
                    t.Title = string.Format("Test Connection: {0}", await WebService.Main.Test());
                    t.Frame = f;
                }
            };

            this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, (s, e) => save());
            Root = new RootElement("Settings")
            {
                new Section("Server Settings")
                {
                    new EntryElement("Server", "http://10.0.1.2/api/", Settings.Shared.ServerUrl)
                    {
                        ShouldAutoCorrect = false,
                        ValueUpdated      = (v) => {
                            Settings.Shared.ServerUrl = v;
                        },
                    },
                    new EntryElement("Test Server", "http://10.0.1.2/api/", Settings.Shared.TestServerUrl)
                    {
                        ShouldAutoCorrect = false,
                        ValueUpdated      = (v) => {
                            Settings.Shared.TestServerUrl = v;
                        },
                    },
                    new UIViewElement("", testButton, false),
                },
                new Section("iPad Settings")
                {
                    new BooleanElement("Test Mode", Settings.Shared.TestMode)
                    {
                        ValueUpdated = (v) => {
                            Settings.Shared.TestMode = v;
                        }
                    },
                    new EntryElement("Register Id", "1", Settings.Shared.RegisterId.ToString())
                    {
                        ShouldAutoCorrect = false,
                        ValueUpdated      = (v) => {
                            try {
                                Settings.Shared.RegisterId = int.Parse(v);
                            } catch (Exception ex) {
                                Console.WriteLine(ex);
                                new SimpleAlertView("Invalid Register ID", "The Register ID must be a number").Show();
                            }
                        },
                    },
                },
                new Section("Payment Settings")
                {
                    (processorType = new StringElement("Credit Card Processor", Settings.Shared.CreditCardProcessor.ToString(), () => {
                        //
                        var sheet = new SimpleActionSheet();
                        Enum.GetValues(typeof(CreditCardProcessorType)).Cast <CreditCardProcessorType>().ToList().ForEach(x => sheet.Add(x.ToString(), Color.LightBlue, () => {
                            if (x == CreditCardProcessorType.Paypal)
                            {
                                //check if paypal is installed
                            }
                            processorType.Value = x.ToString();
                            Settings.Shared.CreditCardProcessor = x;
                            processorType.Reload();
                            UpdatePaymentDetails();
                        }));
                        sheet.ShowFrom(processorType.GetActiveCell().Bounds, processorType.GetActiveCell(), true);
                    })),
                },
                new Section()
                {
                    new StringElement("Version", NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString()),
                    new StringElement("Check for updates", () => Updater.Shared.Update()),
                }
            };
            UpdatePaymentDetails();
        }