示例#1
0
        private void HandleNewForgotPasswordRequestStatus(ForgotPasswordRequestStatus status)
        {
            switch (status)
            {
            case ForgotPasswordRequestStatus.Idle:
                PasswordResetLiveData.PostValue(RxWrapper <bool> .NoData());
                break;

            case ForgotPasswordRequestStatus.Pending:
                PasswordResetLiveData.PostValue(RxWrapper <bool> .Pending());
                break;

            case ForgotPasswordRequestStatus.Success:
                LongToast(AppRes["ForgotPasswordSuccess"]);
                PasswordResetLiveData.PostValue(RxWrapper <bool> .Ok(true));
                break;

            case ForgotPasswordRequestStatus.BadData:
                ShortToast(AppRes["ForgotPasswordBadData"]);
                PasswordResetLiveData.PostValue(RxWrapper <bool> .Ok(false));
                break;

            case ForgotPasswordRequestStatus.NoNetwork:
                ShortToast(AppRes["NoNetworkToast"]);
                PasswordResetLiveData.PostValue(RxWrapper <bool> .Error(new Exception(AppRes["NoNetworkToast"])));
                break;

            case ForgotPasswordRequestStatus.Error:
            default:
                ShortToast(AppRes["ForgotPasswordError"]);
                Log.Error("ForgotPasswordPageViewModel", "ForgotPasswordRequest returned unknown error");
                PasswordResetLiveData.PostValue(RxWrapper <bool> .Error(new Exception(AppRes["ForgotPasswordError"])));
                break;
            }
        }
示例#2
0
        /// <summary>
        /// Simulated network fetch
        /// Error every third call
        /// </summary>
        public void GetFakeNetworking()
        {
            //Check if request is not already pending
            if (FakeNetworkingLiveData.Value?.Status != RxStatus.Pending)
            {
                //Notify UI that request is pending
                FakeNetworkingLiveData.PostValue(RxWrapper <SampleResponse> .Pending());

                //Fake request latency 0.5-2s
                Task.Delay(_randomGen.Next(500, 2000)).ContinueWith(task =>
                {
                    switch (_fakeNetworkSequence)
                    {
                    case 0:
                        var model1 = new SampleResponse
                        {
                            Id   = 1,
                            Name = "Ok response 1"
                        };

                        //Post fake fetch data to UI
                        FakeNetworkingLiveData.PostValue(RxWrapper <SampleResponse> .Ok(model1));
                        break;

                    case 1:
                        var model2 = new SampleResponse
                        {
                            Id   = 2,
                            Name = "Ok response 2"
                        };

                        //Post fake fetch data to UI
                        FakeNetworkingLiveData.PostValue(RxWrapper <SampleResponse> .Ok(model2));
                        break;

                    case 2:

                        //Fake error has occured during network call
                        FakeNetworkingLiveData.PostValue(RxWrapper <SampleResponse> .Error(new Exception("No network")));
                        break;
                    }

                    ++_fakeNetworkSequence;
                    if (_fakeNetworkSequence > 2)
                    {
                        _fakeNetworkSequence = 0;
                    }
                });
            }
        }
        public void RxWrapperInitTest()
        {
            var testData      = TestUtils.RandomString(32);
            var testStatus    = (RxStatus) new Random().Next(0, 2);
            var testException = new Exception(TestUtils.RandomString(32));

            _rxWrapper = new RxWrapper <string>(testStatus, testData, testException);

            Assert.AreEqual(testData, _rxWrapper.Data);
            Assert.AreEqual(testStatus, _rxWrapper.Status);
            Assert.AreEqual(testException, _rxWrapper.Exception);

            _rxWrapper = new RxWrapper <string>(testData);

            Assert.AreEqual(testData, _rxWrapper.Data);
            Assert.AreEqual(RxStatus.Ok, _rxWrapper.Status);
            Assert.IsNull(_rxWrapper.Exception);

            _rxWrapper = new RxWrapper <string>(testStatus);

            Assert.IsNull(_rxWrapper.Data);
            Assert.AreEqual(testStatus, _rxWrapper.Status);
            Assert.IsNull(_rxWrapper.Exception);

            _rxWrapper = new RxWrapper <string>(testException);

            Assert.IsNull(_rxWrapper.Data);
            Assert.AreEqual(RxStatus.Error, _rxWrapper.Status);
            Assert.AreEqual(testException, _rxWrapper.Exception);

            _rxWrapper = RxWrapper <string> .Ok(testData);

            Assert.AreEqual(testData, _rxWrapper.Data);
            Assert.AreEqual(RxStatus.Ok, _rxWrapper.Status);
            Assert.IsNull(_rxWrapper.Exception);

            _rxWrapper = RxWrapper <string> .Pending();

            Assert.IsNull(_rxWrapper.Data);
            Assert.AreEqual(RxStatus.Pending, _rxWrapper.Status);
            Assert.IsNull(_rxWrapper.Exception);

            _rxWrapper = RxWrapper <string> .Error(testException);

            Assert.IsNull(_rxWrapper.Data);
            Assert.AreEqual(RxStatus.Error, _rxWrapper.Status);
            Assert.AreEqual(testException, _rxWrapper.Exception);
        }
示例#4
0
        private void OnPasswordReset(RxWrapper <bool> status)
        {
            switch (status.Status)
            {
            case RxStatus.NoData:
                SetCanceledOnTouchOutside(true);
                _progressBarContainer.Visibility = ViewStates.Gone;
                break;

            case RxStatus.Ok:
                if (status.Data)
                {
                    Dismiss();
                }
                else
                {
                    SetCanceledOnTouchOutside(true);
                    _progressBarContainer.Visibility = ViewStates.Gone;
                    _resetPassButton.Enabled         = true;
                    _resetPassButton.SetBackgroundColor(
                        Context.Resources.GetColor(Resource.Color.colorPrimary, Context.Theme));
                }
                break;

            case RxStatus.Pending:
                if (CurrentFocus != null)
                {
                    var inputManager = (InputMethodManager)Context.GetSystemService(Context.InputMethodService);
                    inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways);
                }

                SetCanceledOnTouchOutside(false);
                _progressBarContainer.Visibility = ViewStates.Visible;
                _resetPassButton.Enabled         = false;
                _resetPassButton.SetBackgroundColor(
                    Context.Resources.GetColor(Resource.Color.lightGray, Context.Theme));
                break;

            default:
            case RxStatus.Error:
                SetCanceledOnTouchOutside(true);
                _progressBarContainer.Visibility = ViewStates.Gone;
                _resetPassButton.Enabled         = true;
                _resetPassButton.SetBackgroundColor(
                    Context.Resources.GetColor(Resource.Color.colorPrimary, Context.Theme));
                break;
            }
        }
示例#5
0
        private void HandleNewLoginStatus(RxWrapper <Tuple <bool, string> > status)
        {
            switch (status.Status)
            {
            case RxStatus.NoData:
                _loginStatus.Visibility          = ViewStates.Gone;
                _progressBarContainer.Visibility = ViewStates.Gone;
                _loginButton.Enabled             = true;
                _loginButton.SetBackgroundColor(Resources.GetColor(Resource.Color.colorPrimary, Context.Theme));
                break;

            case RxStatus.Ok:
                if (status.Data.Item1)
                {
                    _loginStatus.Visibility          = ViewStates.Visible;
                    _progressBarContainer.Visibility = ViewStates.Gone;
                    _loginStatus.Text = status.Data.Item2;

                    (Activity as ILoginFragmentContract)?.SwitchToSplashActivity();
                }
                else
                {
                    _loginStatus.Visibility          = ViewStates.Visible;
                    _progressBarContainer.Visibility = ViewStates.Gone;
                    _loginButton.Enabled             = true;
                    _loginButton.SetBackgroundColor(Resources.GetColor(Resource.Color.colorPrimary, Context.Theme));

                    _loginStatus.Text = status.Data.Item2;
                }
                break;

            case RxStatus.Pending:
                _loginStatus.Visibility          = ViewStates.Gone;
                _progressBarContainer.Visibility = ViewStates.Visible;
                _loginButton.Enabled             = false;
                _loginButton.SetBackgroundColor(Resources.GetColor(Resource.Color.lightGray, Context.Theme));
                break;

            default:
            case RxStatus.Error:
                _loginStatus.Visibility          = ViewStates.Visible;
                _progressBarContainer.Visibility = ViewStates.Gone;
                _loginButton.Enabled             = true;
                _loginStatus.Text = AppRes["LoginStatusToast.error"];
                _loginButton.SetBackgroundColor(Resources.GetColor(Resource.Color.colorPrimary, Context.Theme));
                break;
            }
        }
示例#6
0
        /// <summary>
        /// Response from network fetch in RxWrapper
        /// </summary>
        /// <param name="response">Sample use of RxWrapper</param>
        private void OnNextNetworkData(RxWrapper <SampleResponse> response)
        {
            switch (response.Status)
            {
            case RxStatus.Ok:
                networkButton.Enabled = true;
                networkLabel.Text     = $"{response.Data.Id}. - {response.Data.Name}";
                break;

            case RxStatus.Pending:
                networkButton.Enabled = false;
                networkLabel.Text     = "Pending request...";
                break;

            case RxStatus.Error:
                networkButton.Enabled = true;
                networkLabel.Text     = "Error has occured";
                break;
            }
        }
        /// <summary>
        /// Response from network fetch in RxWrapper
        /// </summary>
        /// <param name="response">Sample use of RxWrapper</param>
        private void OnNextNetworkData(RxWrapper <SampleResponse> response)
        {
            switch (response.Status)
            {
            case RxStatus.Ok:
                _requestNetworkFetchButton.Enabled = true;
                _networkFetchTextView.Text         = $"{response.Data.Id}. - {response.Data.Name}";
                break;

            case RxStatus.Pending:
                _requestNetworkFetchButton.Enabled = false;
                _networkFetchTextView.Text         = "Pending request...";
                break;

            case RxStatus.Error:
                _requestNetworkFetchButton.Enabled = true;
                _networkFetchTextView.Text         = "Error has occured";
                Toast.MakeText(Context, "No network", ToastLength.Short).Show();
                break;
            }
        }