public async void ShowInputDialog(InputDialogMessage message) { using(var loc = await MDialog.ALocker.LockAsync()) { InputBox.Text = String.Empty; if (!String.IsNullOrWhiteSpace(message.Title)) { Title = message.Title; } else { Title = ""; } if (!String.IsNullOrWhiteSpace(message.Description)) { Description.Text = message.Description; } else { Description.Text = ""; } if (message.Buttons?.Length == 1) { IsSecondaryButtonEnabled = false; PrimaryButtonText = message.Buttons[0]; } else if(message.Buttons?.Length > 1) { IsSecondaryButtonEnabled = true; PrimaryButtonText = message.Buttons[0]; SecondaryButtonText = message.Buttons[1]; } var result = await ShowAsync(); if(message.CallBack != null) { if(result == ContentDialogResult.Primary) { message.CallBack(PrimaryButtonText, InputBox.Text); } else if(result == ContentDialogResult.Secondary) { message.CallBack(SecondaryButtonText, InputBox.Text); } else { message.CallBack(null, InputBox.Text); } } } }
private async void inputDialogMessageReceiver(InputDialogMessage dm) { InputDialog.InputText = ""; String result = ""; using (await alock.LockAsync()) { if (dm.Buttons != null) { result = await InputDialog.ShowAsync(dm.Title ?? "", dm.Description ?? "", dm.Buttons); } else { result = await InputDialog.ShowAsync(dm.Title ?? "", dm.Description ?? ""); } } if (dm.CallBack != null) { dm.CallBack(result, InputDialog.InputText); } }
private async void addDeviceReceived(String button, String text) { if(String.Compare(button, MM.M.GetString("Add_Device_Button")) == 0) { if (String.IsNullOrWhiteSpace(text)) { ViewModelLocator.Messenger.Send(new DialogMessage() { Description = MM.M.GetString("Invalid_Device_Id") }); } else { var result = await ViewModelLocator.Cloud.ClaimDeviceAsync(text); if (result.Success) { var idm = new InputDialogMessage(); idm.Title = MM.M.GetString("NameDevice_Dialog_Title"); idm.Description = MM.M.GetString("NameDevice_Dialog_Description"); idm.Buttons = new String[] { MM.M.GetString("NameDevice_Dialog_Button") }; idm.CallBack = async (act, resp) => { if (String.IsNullOrWhiteSpace(resp)) { ViewModelLocator.Messenger.Send(new DialogMessage { Description = MM.M.GetString("NameDevice_Dialog_Error"), CallBack = (i)=> { ViewModelLocator.Messenger.Send(idm); } }); } else { var devices = await ViewModelLocator.Cloud.GetDevicesAsync(); if(devices.Success) { var d = devices?.Data.FirstOrDefault(i => String.Compare(i.Id, text) == 0); if(d != null) { await d.RenameAsync(resp); } } if (RefreshCommand.CanExecute(null)) { RefreshCommand.Execute(null); } } }; ViewModelLocator.Messenger.Send(idm); } else { ViewModelLocator.Messenger.Send(new DialogMessage() { Description = result.Error }); } } } }