i plan to use clean architecture with MVP.
I am beginning a android project using the clean architecture approach that uncle bob endorses.
i've downloaded a template project that is kind of like a starter template to kickstart you when using clean architecute approach.
The git hub is here: https://github.com/dmilicic/Android-Clean-Boilerplate.git
So we will have 3 layers; domain, presentation and threading per the template.
My question is about a login activity i am designing. I am creating a "sign in with google" button. but i am not sure where to put the googleAPIClient,googleSignInOptions and googleSignInResult calls. and after i get the google account authenticated i then pass it to firebaseAuth to log the user into my site so thats another API call as well that im not sure how it works. To know how to use a google account to log in to firebase application you can check here: https://www.androidtutorialpoint.com/firebase/android-firebase-authentication-tutorial-using-firebase-google-login/
so lets me explain why im having trouble with the template. lets start tracing users steps assuming he wants to sign in using google account:
- User hits the "sign in with google" button. that should trigger the UI to ask the presenter to begin google sign in attempt. so at this point should i make a interactor (use-case) for the presenter to use or should i initialize the googleAPICient directly in the presenter ? The concern is the google sign-in Api works by creating an intent and passing it a googleApiClient as a parameter. you then start that Intent using startActivityForResult. So thats all android code , so should it not be in the presentation layer then and specifically in the activity itself ? so it seems i have no choice but to call the google sign stuff from the view/Activity itself. correct ?
Then after i get the activity result from that call i was planning to log into firebase like this:
//this block of code is in the activity
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from
GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
googleSignInAccount account = result.getSignInAccount();
//******* make the presenter log into firebase not the view
presenter.firebaseAuthWithGoogle(account);
}
else {
// Google Sign In failed, update UI appropriately
// ...
}
}
Then in the presenter code :
//this code will be in the presenter class itself, should it be in in a interactor instead ?
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential =
GoogleAuthProvider.getCredential(acct.getIdToken(), null);
Auth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
}
});
}