0

in the code shown below how can i return boolean values from this observable (lambda expression)

loginActivityViewModel.checkEmailAndPassword(email,password).observe(this,(response)->{
        switch(response){

            case LoginActivityViewModel.EMPTY_EMAIL:
                handleError(emailWrapper, R.string.error_email_required);
                return false;

            case LoginActivityViewModel.INVALID_EMAIL:
                handleError(emailWrapper, R.string.error_enter_valid_email);
                return false;
            case LoginActivityViewModel.EMPTY_PASSWORD:
                handleError(passwordWrapper, R.string.error_password_required);
                return false;
        }
    });

this block of statement is inside an function that returns boolean values but IDE is telling me unexpected return statement inside the cases. Thankyou for helping in advance

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Simar
  • 21
  • 2

2 Answers2

0

You are trying to return from within the observable function, not the function that contains your code block. This does not work. Assuming the call on checkEmailAndPassword is the whole point of your method, a better option is to pass a callback function to your method instead of returning a boolean.

Androidas
  • 169
  • 10
0

You missing default:

loginActivityViewModel.checkEmailAndPassword(email,password).observe(this,(response)->{
    switch(response){

        case LoginActivityViewModel.EMPTY_EMAIL:
            handleError(emailWrapper, R.string.error_email_required);
            return false;

        case LoginActivityViewModel.INVALID_EMAIL:
            handleError(emailWrapper, R.string.error_enter_valid_email);
            return false;
        case LoginActivityViewModel.EMPTY_PASSWORD:
            handleError(passwordWrapper, R.string.error_password_required);
            return false;

        default:
            return false;

    }
});
quangminhs
  • 151
  • 5