async void enviaSms (PanicContacts pr, String id) { try { Console.WriteLine ("SMS de panico para:" + pr); await Task.Delay (1); // InvokeOnMainThread(() => { //Para evitar:.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread. //at UIKit.UIApplication.EnsureUIThread()[0x00023] var smsTask = MessagingPlugin.SmsMessenger; if (!smsTask.CanSendSms) Console.WriteLine ("User nao pode enviar SMS de panico..."); else { string sms = String.Format (smsLink, Settings.nome, id); smsTask.SendSms (pr.phoneNumber, sms); } // }); } catch (Exception ex) { Console.WriteLine ("Exception enviando SMS:" + ex.Message); } }
public async Task updateProtector (PanicContacts panicContact) { await PanicContactRp.UpdateAsync (panicContact); }
public async Task removeProtegido (PanicContacts panicContact) { protegidos.Remove (panicContact); panicContact.Estado = 'R'; //Apenas marca como rejeitado await PanicContactRp.UpdateAsync (panicContact); }
public async Task removeProtetor (PanicContacts panicContact) { protetores.Remove (panicContact); await PanicContactRp.RemoveAsync (panicContact); }
async void protetor_ContactSelected (object sender, ContactPickedEventArgs e) { if (string.IsNullOrEmpty (e.Email)) { await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error, "MySafety", "O contato nao tem email", TimeSpan.FromSeconds (3)); return; } foreach (var pr in protetores) if (pr.Email == e.Email) { await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error, "MySafety", "O contato já está cadastrado...", TimeSpan.FromSeconds (3)); return; } var x = new Repository<MysafetyUser> ().GetAllAsync ().Result.Where (pr => pr.Email == e.Email); var panicProtector = new PanicContacts (); if (x == null) { await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error, "Erro Consultando Servidor", "Deseja enviar continuar cadastro?", TimeSpan.FromSeconds (3)); panicProtector.Estado = 'S'; } else if (x.Count () == 0) { //TODO terminar codigo necessario await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error, "Protetor nao tem MySafety", "Deseja enviar link para download do App?", TimeSpan.FromSeconds (3)); panicProtector.Estado = 'S'; //TODO panicProtector.Protector_user_Id tem que ser setado quando o protetor fizer cadastro.. } else { panicProtector.Estado = 'C'; panicProtector.ProtUserId = x.ElementAtOrDefault (0).Id; } panicProtector.Id = ++nextIDProtetor + ""; panicProtector.Name = e.Name; panicProtector.phoneNumber = e.Phone; panicProtector.Email = e.Email; panicProtector.SendSms = true; panicProtector.SendEmail = true; panicProtector.CanPanic = true; panicProtector.CanTrack = true; panicProtector.UserId = Settings.user_Id; protetores.Add (panicProtector); await PanicContactRp.CreateAsync (panicProtector); //Apenas para testes: O meu protetor me cadastrando como seu protetor panicProtector.Id = Extensions.Randomize (); panicProtector.Name = Settings.nome; panicProtector.phoneNumber = string.Empty; //seria o meu fone panicProtector.Email = Settings.email; panicProtector.SendSms = true; panicProtector.SendEmail = true; panicProtector.CanPanic = true; panicProtector.CanTrack = true; panicProtector.Id = panicProtector.ProtUserId; panicProtector.ProtUserId = Settings.user_Id; protegidos.Add (panicProtector); await PanicContactRp.CreateAsync (panicProtector); }
public MyProtectorConfigView(AcoesDePanicoViewModel viewModel, PanicContacts protetor) { BindingContext = viewModel; RepositoryReceiver = protetor; Title = protetor.Name; smsSwitch.IsToggled = protetor.SendSms; emailSwitch.IsToggled = protetor.SendEmail; isPanicSwitch.IsToggled = protetor.CanPanic; trackSwitch.IsToggled = protetor.CanTrack; StackLayout smsStack = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Orientation = StackOrientation.Horizontal, Padding = new Thickness (15, 0, 15, 0), Children = { iconSms, smsLabel, smsSwitch } }; StackLayout emailStack = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Orientation = StackOrientation.Horizontal, Padding = new Thickness (15, 0, 15, 0), Children = { iconEmail, emailLabel, emailSwitch } }; StackLayout isPanicStack = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Orientation = StackOrientation.Horizontal, Padding = new Thickness (15, 0, 15, 0), Children = { iconRemote, isPanicLabel, isPanicSwitch } }; StackLayout trackStack = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Orientation = StackOrientation.Horizontal, Padding = new Thickness (15, 0, 15, 0), Children = { iconTrack, trackLabel, trackSwitch } }; // StackLayout deleteStack = new StackLayout // { // HorizontalOptions = LayoutOptions.FillAndExpand, // VerticalOptions = LayoutOptions.FillAndExpand, // Orientation = StackOrientation.Horizontal, // Padding = new Thickness(15, 0, 15, 0), // Children = // { // deleteButton // } // }; ConfigTable = new TableView { Intent = TableIntent.Settings, BackgroundColor = Color.Transparent, Root = new TableRoot { new TableSection ("Configurações do protetor") { new ViewCell { View = smsStack }, new ViewCell { View = emailStack }, new ViewCell { View = isPanicStack }, new ViewCell { View = trackStack }, }, //new TableSection() //{ // new ViewCell { View = deleteStack } //} } }; Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Orientation = StackOrientation.Vertical, Children = { ConfigTable, deleteButton } }; //deleteSwitch.Toggled += async (object sender, ToggledEventArgs e) => //{ // if (e.Value) // { // await ((AcoesDePanicoViewModel)BindingContext).removeProtetor(receiver); // await Navigation.PopAsync(true); // } //}; deleteButton.Clicked += async (s, e) => { var ask = await UserDialogs.Instance.ConfirmAsync ("Deseja realmente deletar o protetor?", null, "Sim", "Não"); if (ask) { UserDialogs.Instance.ShowLoading ("Removendo", MaskType.Black); await ((AcoesDePanicoViewModel)BindingContext).removeProtetor (protetor); await Navigation.PopAsync (true); UserDialogs.Instance.HideLoading (); } }; smsSwitch.Toggled += async (object sender, ToggledEventArgs e) => { protetor.SendSms = e.Value; await ((AcoesDePanicoViewModel)BindingContext).updateProtector (protetor); }; emailSwitch.Toggled += async (object sender, ToggledEventArgs e) => { protetor.SendEmail = e.Value; await ((AcoesDePanicoViewModel)BindingContext).updateProtector (protetor); }; isPanicSwitch.Toggled += async (object sender, ToggledEventArgs e) => { protetor.CanPanic = e.Value; await ((AcoesDePanicoViewModel)BindingContext).updateProtector (protetor); }; trackSwitch.Toggled += async (object sender, ToggledEventArgs e) => { protetor.CanTrack = e.Value; await ((AcoesDePanicoViewModel)BindingContext).updateProtector (protetor); }; }