async partial void LeftGate_TouchUpInside(UIButton sender) { BTProgressHUD.Show("Contacting Gates...", maskType: ProgressHUD.MaskType.Gradient); APISignInHelper signIn = new APISignInHelper(); if (string.IsNullOrWhiteSpace(Settings.AuthToken)) { await signIn.SignIn(Keys.Email, Keys.Password); BTProgressHUD.Dismiss(); } else { if (TokenValidator.HasExpired(Settings.AuthToken)) { if (await signIn.SignIn(Keys.Email, Keys.Password)) { APIDeviceHelper sendMessage = new APIDeviceHelper(); if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span)) { BTProgressHUD.Dismiss(); BTProgressHUD.ShowSuccessWithStatus("Left Gate Toggled", 1000); } else { BTProgressHUD.Dismiss(); BTProgressHUD.ShowErrorWithStatus(Settings.ErrorMessage, 1000); } } else { BTProgressHUD.Dismiss(); BTProgressHUD.ShowErrorWithStatus(Settings.ErrorMessage, 1000); } } else { APIDeviceHelper sendMessage = new APIDeviceHelper(); if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span)) { BTProgressHUD.Dismiss(); BTProgressHUD.ShowSuccessWithStatus("Left Gate Toggled", 1000); } else { BTProgressHUD.Dismiss(); BTProgressHUD.ShowErrorWithStatus(Settings.ErrorMessage, 1000); } } } }
private async void Timer_Elapsed(object sender, ElapsedEventArgs e) { APISignInHelper signIn = new APISignInHelper(); AndHUD.Shared.Show(this); if (string.IsNullOrWhiteSpace(Settings.AuthToken)) { if (await signIn.SignIn(Keys.Email, Keys.Password)) { AndHUD.Shared.Dismiss(this); var intent = new Intent(this, typeof(MainActivity)); intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask); StartActivity(intent); } else { AndHUD.Shared.Dismiss(this); AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3)); } } else { if (TokenValidator.HasExpired(Settings.AuthToken)) { if (await signIn.SignIn(Keys.Email, Keys.Password)) { AndHUD.Shared.Dismiss(this); var intent = new Intent(this, typeof(MainActivity)); intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask); StartActivity(intent); } else { AndHUD.Shared.Dismiss(this); AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3)); } } else { AndHUD.Shared.Dismiss(this); var intent = new Intent(this, typeof(MainActivity)); intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask); StartActivity(intent); } } }
private async void LeftGateClick(object sender, EventArgs e) { AndHUD.Shared.Show(this, "Contacting Gate...", maskType: MaskType.Black); if (TokenValidator.HasExpired(Settings.AuthToken)) { APISignInHelper signIn = new APISignInHelper(); if (await signIn.SignIn(Keys.Email, Keys.Password)) { APIDeviceHelper sendMessage = new APIDeviceHelper(); if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span)) { AndHUD.Shared.Dismiss(this); AndHUD.Shared.ShowSuccess(this, "Left Gate Toggled", MaskType.Black, TimeSpan.FromSeconds(3)); } else { AndHUD.Shared.Dismiss(this); AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3)); } } else { AndHUD.Shared.Dismiss(this); AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3)); } } else { APIDeviceHelper sendMessage = new APIDeviceHelper(); if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span)) { AndHUD.Shared.Dismiss(this); AndHUD.Shared.ShowSuccess(this, "Left Gate Toggled", MaskType.Black, TimeSpan.FromSeconds(3)); } else { AndHUD.Shared.Dismiss(this); AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3)); } } }