javaandroiddesign-patternsclean-architecturearchitectural-patterns

Login Flow in Android Clean Architecture


I was looking to implement a simple Firebase Authentication Android Application using Clean Architecture, so as per Firebase Documentation the user can be checked if he's been logged in

@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    updateUI(currentUser);
}

so I am confused to as where should it put this condition, should it be in a UseCase or in the Presenter, called independently with help of same source object

something like

public interface FirebaseAuthDataSource {
    Single<User> loginUser(String username, String password);
    Single<User> isUserLoggedIn();
}
public class LoginUserUseCase {
  public Observable<ResponseValues> buildUseCase(RequestValues requestValues) {
   return firebaseAuthDataSource.loginUser(username,password);
  }
}
public class LoginPresenter{
 public void onStart(){
  firebaseAuthDataSource.isUserLoggedIn()
  .subscribe(LoginView::navigateToMenuScreen);
 }
}

so conditions like these, do they qualify as a Business logic ? or a Flow logic ?


Solution

  • According to Uncle Bob, the UI should not know anything about the database. These conditions belong in the framework layer where all your database stuff should be. And the communication passes through the UseCase and the Data Access Interface.

    If that's too much effort for you, then you could also just transfer the sensitive parts that are probably change in the future to "Clean Architecture". But that's just my opinion. I hope this will help you