Example #1
0
        protected override void OnResume()
        {
            base.OnResume();
            if (_dropboxApi != null && _session != null && (_populateAfterAuthorize || _startActivityAfterAuthorize || _insertAfterAuthorize || _doNothingAfterAuthorize))
            {
                // After you allowed to link the app with Dropbox,
                // you need to finish the Authentication process
                var androidAuthSession = _dropboxApi.Session as AndroidAuthSession;
                //_session = androidAuthSession;
                if (!_session.AuthenticationSuccessful())
                {
                    return;
                }

                try {
                    // Call this method to finish the authentication process
                    // Will bind the user's access token to the session.
                    _session.FinishAuthentication();
                    _accessToken = _session.OAuth2AccessToken;
                    _dbHandler.MergeSettings(new InsertTaskSetting()
                    {
                        Name  = ACCESS_TOKEN_PROP,
                        Value = _accessToken
                    });
                    if (_populateAfterAuthorize)
                    {
                        _populateAfterAuthorize = false;
                        RepopulateTasks();
                        FindViewById <SwipeRefreshLayout>(Resource.Id.slSwipeContainer).Refreshing = false;
                    }
                    else if (_startActivityAfterAuthorize)
                    {
                        _startActivityAfterAuthorize = false;
                        StartDetailsActivity();
                    }
                    else if (_insertAfterAuthorize)
                    {
                        _insertAfterAuthorize = false;
                        StartInsertTask();
                    }
                    else if (_doNothingAfterAuthorize)
                    {
                        _doNothingAfterAuthorize = false;
                    }
                    // Save the Access Token somewhere
                } catch (IllegalStateException ex) {
                    Toast.MakeText(this, ex.LocalizedMessage, ToastLength.Short).Show();
                }
            }
        }