public void OnButtonLoginClicked(View v) { var empresa = FindViewById <EditText>(Resource.Id.empresa_editTxtUser); var senha = FindViewById <EditText>(Resource.Id.login_editTxtPass); var usuario = FindViewById <EditText>(Resource.Id.login_editTxtUser); progressDialog = ProgressDialog.Show(this, Resources.GetString(Resource.String.carregando), Resources.GetString(Resource.String.msg_popup_login), true); new Thread(new ThreadStart(delegate { try { var infoUser = controller.DoLogin(empresa.Text, usuario.Text, senha.Text); infoUser = GetAvatarDeUsuario(infoUser); RunOnUiThread(delegate { controller.InsertNewUser(infoUser); Sincronizador.context = ApplicationContext; Sincronizador.TryExecSync(); }); if (Intent.GetBooleanExtra("isToAddNewUser", false)) { RunOnUiThread(() => Toast.MakeText(this, Resources.GetString(Resource.String.msg_new_user_ok), ToastLength.Long).Show()); } progressDialog.Dismiss(); StartActivity(typeof(MenuPdvs)); OverridePendingTransition(Resource.Animation.abc_slide_in_bottom, Resource.Animation.abc_slide_out_bottom); } catch (InvalidLoginException loginError) { RunOnUiThread(() => Toast.MakeText(this, loginError.Message, ToastLength.Long).Show()); if ((progressDialog != null) && progressDialog.IsShowing) { progressDialog.Dismiss(); } } catch (Exception) { RunOnUiThread(() => Toast.MakeText(this, Resources.GetString(Resource.String.msg_erro_inesperado_login), ToastLength.Long).Show()); if ((progressDialog != null) && progressDialog.IsShowing) { progressDialog.Dismiss(); } } })).Start(); }
void ExecLogin() { model.empresa = txtEmpresaLogin.Text; model.login = txtUsuarioLogin.Text; model.password = txtSenhaLogin.Text; var bounds = UIScreen.MainScreen.Bounds; loadingOverlay = new LoadingOverlay(bounds); loadingOverlay.ExecOverLay(); View.Add(loadingOverlay); new Thread(new ThreadStart(delegate { try { SyncronizerModel modelSync; SyncronizerCon controllerSync; var infoUser = controller.DoLogin(model.empresa, model.login, model.password); infoUser = GetAvatarDeUsuario(infoUser); GetLogoEmpresa(infoUser.SERVIDOR.Substring(0, infoUser.SERVIDOR.IndexOf(".", StringComparison.CurrentCulture)), infoUser); InvokeOnMainThread(() => { controller.InsertNewUser(infoUser); modelSync = new SyncronizerModel() { db = new SyncronizerDA(Sqlite_IOS.DB.dataBase), dbCache = new CacheDA(Sqlite_IOS.DB.dataBase) }; controllerSync = new SyncronizerCon(modelSync); controllerSync.ExecRestApis(); #if !DEBUG BITHockeyManager.SharedHockeyManager.UserId = infoUser.ID; BITHockeyManager.SharedHockeyManager.UserEmail = infoUser.SERVIDOR; BITHockeyManager.SharedHockeyManager.StartManager(); #endif MoveToFeedPDV(); }); } catch (InvalidLoginException loginError) { InvokeOnMainThread(() => { var alert = UIAlertController.Create(loginError.Message, null, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); alert.View.TintColor = UIColor.FromRGB(10, 88, 90); PresentViewController(alert, true, null); }); } catch (Exception ex) { var exi = ex.Message; InvokeOnMainThread(() => { var alert = UIAlertController.Create( "Ocorreu um erro inesperado, verifique sua conexão e os dados de login", null, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); alert.View.TintColor = UIColor.FromRGB(10, 88, 90); PresentViewController(alert, true, null); }); } finally { InvokeOnMainThread(() => { loadingOverlay.Hide(); }); } })).Start(); }