private void AddNewItem() { _dialogs.Prompt(new PromptConfig { OnAction = CreateNewItem, Title = "New Task List", Placeholder = "List Name" }); }
public static Task <PromptResult> Prompt(this IUserDialogs dialogs, string message, string title = null, string okText = null, string cancelText = null) => dialogs.Prompt(new PromptConfig { Title = title, Message = message, OkLabel = okText, CancelLabel = cancelText });
public PeripheralViewModel(ICentralManager centralManager, IUserDialogs dialogs) { this.centralManager = centralManager; this.dialogs = dialogs; this.SelectCharacteristic = ReactiveCommand.Create <GattCharacteristicViewModel>(x => x.Select()); this.ConnectionToggle = ReactiveCommand.Create(() => { // don't cleanup connection - force user to d/c if (this.peripheral.Status == ConnectionState.Disconnected) { this.peripheral.Connect(); } else { this.peripheral.CancelConnection(); } }); this.PairToDevice = ReactiveCommand.Create(() => { var pair = this.peripheral as ICanPairPeripherals; if (pair == null) { dialogs.Alert("Pairing is not supported on this platform"); } else if (pair.PairingStatus == PairingState.Paired) { dialogs.Toast("Peripheral is already paired"); } else { pair .PairingRequest() .Subscribe(x => { var txt = x ? "Peripheral Paired Successfully" : "Peripheral Pairing Failed"; dialogs.Toast(txt); this.RaisePropertyChanged(nameof(this.PairingText)); }); } }); this.RequestMtu = ReactiveCommand.CreateFromTask( async x => { var mtu = this.peripheral as ICanRequestMtu; if (mtu == null) { await dialogs.Alert("MTU requests are not supported on this platform"); } else { var result = await dialogs.Prompt("Range 20-512", "MTU Request"); if (result.Ok) { var actual = await mtu.RequestMtu(Int32.Parse(result.Value)); dialogs.Toast("MTU Changed to " + actual); } } }, this.WhenAny( x => x.ConnectText, x => x.GetValue().Equals("Disconnect") ) ); }
public PeripheralViewModel(ICentralManager centralManager, IUserDialogs dialogs) { this.dialogs = dialogs; this.SelectCharacteristic = ReactiveCommand.Create <GattCharacteristicViewModel>(x => x.Select()); this.ConnectionToggle = ReactiveCommand.Create(() => { // don't cleanup connection - force user to d/c if (this.peripheral.Status == ConnectionState.Disconnected) { this.peripheral.Connect(); } else { this.peripheral.CancelConnection(); } }); this.PairToDevice = ReactiveCommand.Create(() => { if (!centralManager.Features.HasFlag(BleFeatures.PairingRequests)) { dialogs.Toast("Pairing is not supported on this platform"); } else if (this.peripheral.PairingStatus == PairingState.Paired) { dialogs.Toast("Peripheral is already paired"); } else { this.peripheral .PairingRequest() .Subscribe(x => { var txt = x ? "Peripheral Paired Successfully" : "Peripheral Pairing Failed"; dialogs.Toast(txt); this.RaisePropertyChanged(nameof(this.PairingText)); }); } }); this.RequestMtu = ReactiveCommand.CreateFromTask( async x => { if (!centralManager.Features.HasFlag(BleFeatures.MtuRequests)) { await dialogs.Alert("MTU Request not supported on this platform"); } else { var result = await dialogs.Prompt("Range 20-512", "MTU Request"); //.SetTitle("MTU Request") //.SetMessage("Range 20-512") // .SetInputMode(InputType.Number) // .SetOnTextChanged(args => // { // var len = args.Value?.Length ?? 0; // if (len > 0) // { // if (len > 3) // { // args.Value = args.Value.Substring(0, 3); // } // else // { // var value = Int32.Parse(args.Value); // args.IsValid = value >= 20 && value <= 512; // } // } // }) //); if (result.Ok) { var actual = await this.peripheral.RequestMtu(Int32.Parse(result.Value)); dialogs.Toast("MTU Changed to " + actual); } } }, this.WhenAny( x => x.ConnectText, x => x.GetValue().Equals("Disconnect") ) ); }