private async void SigninButton_Click(object sender, EventArgs e)
        {
            TextView errorTextView = FindViewById <TextView>(Resource.Id.signInErrorTextView);
            bool     loggedIn;

            if (CrossConnectivity.Current.IsConnected)
            {
                errorTextView.Visibility = ViewStates.Gone;
                if (!dataValid)
                {
                    errorTextView.Text       = "Wypełnij dane poprawnie...";
                    errorTextView.Visibility = ViewStates.Visible;
                }
                else
                {
                    loggedUser.RememberMe = true;
                    loggedIn = await WebApiDataController.LogIn(loggedUser);

                    if (loggedIn)
                    {
                        Toast.MakeText(this, "Zalogowano", ToastLength.Short);
                        SetContentView(Resource.Layout.LoadingView);
                        var intent = new Intent(this, typeof(NotificationActivity));
                        StartActivity(intent);
                        Finish();
                    }
                    else
                    {
                        errorTextView.Text       = "Nie udało się zalogować";
                        errorTextView.Visibility = ViewStates.Visible;
                    }
                }
            }
            else
            {
                errorTextView.Text       = "Brak połączenia z internetem";
                errorTextView.Visibility = ViewStates.Visible;
            }
        }
Exemple #2
0
 private void TurnOn()
 {
     user = SQLiteDb.GetUser();
     if (user.Email == "failed")
     {
         var intent = new Intent(this, typeof(SignInActivity));
         StartActivityForResult(intent, 1);
         Finish();
     }
     else if (CrossConnectivity.Current.IsConnected)
     {
         if (user.RememberMe && DateTime.Now.Subtract(user.AuthorizationTime).TotalSeconds >= 86399)
         {
             //Remember me, Authorization key not actve
             var logged = WebApiDataController.LogIn(user).Result;
             if (logged)
             {
                 //logged in
                 var intent = new Intent(this, typeof(LoadDataActivity));
                 StartActivity(intent);
                 Finish();
             }
             else
             {
                 //not logged in
                 AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                 AlertDialog         alert  = dialog.Create();
                 alert.SetTitle("Błąd");
                 alert.SetMessage("Logowanie nie było możliwe. Wprowadź dane logowania.");
                 alert.SetButton("OK", (c, ev) =>
                 {
                     alert.Hide();
                     var intent = new Intent(this, typeof(SignInActivity));
                     StartActivity(intent);
                     Finish();
                 });
                 alert.Show();
             }
         }
         else if (!user.RememberMe && DateTime.Now.Subtract(user.AuthorizationTime).TotalSeconds >= 86399)
         {
             //Dont remember me
             var intent = new Intent(this, typeof(SignInActivity));
             StartActivityForResult(intent, 1);
             Finish();
         }
         else
         {   //Authorization key still active
             var intent = new Intent(this, typeof(LoadDataActivity));
             StartActivity(intent);
             Finish();
         }
     }
     else
     {
         AlertDialog.Builder dialog = new AlertDialog.Builder(this);
         AlertDialog         alert  = dialog.Create();
         alert.SetTitle("Błąd");
         alert.SetMessage("Brak połączenia z internetem");
         alert.SetButton("SPRÓBUJ PONOWNIE", (c, ev) =>
         {
             alert.Hide();
             TurnOn();
         });
         alert.SetButton2("OK", (c, ev) =>
         {
             alert.Hide();
             Finish();
         });
         alert.Show();
     }
 }