Ejemplo n.º 1
0
        private void LoginUser()
        {
            if (ValidateInput())
            {
                if (_isLogginUser)
                {
                    return;
                }

                _isLogginUser = true;

                _email    = this.EmailText.Text;
                _password = this.PasswordText.Text;

                // Prevent user form tapping views while logging
                ((MainActivity)this.Activity).BlockUI();

                // Create a new cancellation token for this request
                _cts0 = new CancellationTokenSource();
                AppController.LoginUser(_cts0, _email, _password,
                                        // Service call success
                                        (data) =>
                {
                    AppController.Settings.LastLoginUsernameUsed = _email;
                    AppController.Settings.AuthAccessToken       = data.AuthAccessToken;
                    AppController.Settings.AuthExpirationDate    = data.AuthExpirationDate.GetValueOrDefault().ToLocalTime();

                    ((ChattyApplication)this.Activity.Application).RegisterToNotificationsHub();

                    var f       = new ChatFragment();
                    f.Arguments = new Bundle();
                    f.Arguments.PutString("Email", _email);
                    this.FragmentManager.BeginTransaction()
                    .AddToBackStack("BeforeChatFragment")
                    .Replace(Resource.Id.ContentLayout, f, "ChatFragment")
                    .Commit();
                },
                                        // Service call error
                                        (error) =>
                {
                    if (error.Contains("confirm"))
                    {
                        this.VerifyButton.Visibility = ViewStates.Visible;
                    }

                    Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show();
                },
                                        // Service call finished
                                        () =>
                {
                    _isLogginUser = false;

                    // Allow user to tap views
                    ((MainActivity)this.Activity).UnblockUI();
                });
            }
        }
Ejemplo n.º 2
0
        public void OnCompleted(JSONObject json, GraphResponse response)
        {
            try
            {
                string fbId    = json.GetString("id");
                string fbToken = AccessToken.CurrentAccessToken.Token;
                string fbEmail = json.GetString("email");

                _email = fbEmail;

                // Create a new cancellation token for this request
                _cts0 = new CancellationTokenSource();
                AppController.LoginUser(_cts0, fbId, fbEmail, fbToken,
                                        // Service call success
                                        (data) =>
                {
                    AppController.Settings.LastLoginUsernameUsed = _email;
                    AppController.Settings.AuthAccessToken       = data.AuthAccessToken;
                    AppController.Settings.AuthExpirationDate    = data.AuthExpirationDate.GetValueOrDefault().ToLocalTime();

                    ((ChattyApplication)this.Activity.Application).RegisterToNotificationsHub();

                    var f       = new ChatFragment();
                    f.Arguments = new Bundle();
                    f.Arguments.PutString("Email", _email);
                    this.FragmentManager.BeginTransaction()
                    .AddToBackStack("BeforeChatFragment")
                    .Replace(Resource.Id.ContentLayout, f, "ChatFragment")
                    .Commit();
                },
                                        // Service call error
                                        (error) =>
                {
                    Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show();
                },
                                        // Service call finished
                                        () =>
                {
                    // Allow user to tap views
                    ((MainActivity)this.Activity).UnblockUI();
                });
            }
            catch (Exception ex)
            {
                ((MainActivity)this.Activity).UnblockUI();

                Toast.MakeText(this.Activity.ApplicationContext, "Error", ToastLength.Long).Show();
            }
            finally
            {
                LoginManager.Instance.LogOut();
            }
        }
Ejemplo n.º 3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            #region Desinger Stuff

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.ActivityMain, Resource.Id.ContentLayout, Resource.Id.Toolbar);

            this.SupportActionBar.SetDisplayShowHomeEnabled(true);
            this.SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            #endregion

            this.LoadLayout.Focusable            = true;
            this.LoadLayout.FocusableInTouchMode = true;
            this.LoadLayout.Clickable            = true;
            this.LoadLayout.Visibility           = ViewStates.Gone;

            bool isResuming = this.SupportFragmentManager.FindFragmentById(Resource.Id.ContentLayout) != null;
            if (!isResuming)
            {
                this.SupportFragmentManager.BeginTransaction()
                .Add(Resource.Id.ContentLayout, new LoginFragment(), "LoginFragment")
                .Commit();

                _userRestored = this.Arguments.GetBoolean("UserRestored", false);
                if (_userRestored)
                {
                    _email = this.Arguments.GetString("Email");

                    var f = new ChatFragment();
                    f.Arguments = new Bundle();
                    f.Arguments.PutString("Email", _email);
                    this.SupportFragmentManager.BeginTransaction()
                    .AddToBackStack("BeforeChatFragment")
                    .Replace(Resource.Id.ContentLayout, f, "ChatFragment")
                    .Commit();
                }
            }
        }