Android Clean架构-在哪里放置googleApiClient调用?

j2e*_*nue 5 mvp android clean-architecture

我计划在MVP中使用干净的体系结构。
我正在使用bob叔叔认可的干净架构方法来开始一个android项目。我已经下载了一个模板项目,该项目有点像入门模板,可以在使用干净的architecute方法时启动您。git中心在这里:https : //github.com/dmilicic/Android-Clean-Boilerplate.git

因此,我们将分为3层;域,演示文稿和每个模板的线程。

我的问题是关于我正在设计的登录活动。我正在创建“使用Google登录”按钮。但我不确定在哪里放置googleAPIClient,googleSignInOptions和googleSignInResult调用。在我获得通过身份验证的Google帐户后,我将其传递给firebaseAuth以将用户登录到我的网站,以便进行另一个API调用,但我不确定其工作原理。要了解如何使用Google帐户登录Firebase应用程序,可以在此处进行检查:https : //www.androidtutorialpoint.com/firebase/android-firebase-authentication-tutorial-using-firebase-google-login/

所以让我解释一下为什么我在使用模板时遇到麻烦。让我们开始跟踪用户的步骤(假设他要使用Google帐户登录):

  1. 用户点击“使用Google登录”按钮。这应该会触发用户界面,要求演示者开始google登录尝试。所以在这一点上,我应该为演示者创建一个交互器(用例),还是直接在演示者中初始化googleAPICient?值得关注的是,google登录Api的工作原理是创建一个意图并将其传递给googleApiClient作为参数。然后,您可以使用startActivityForResult启动该Intent。这就是所有的android代码,那么它不应该在表示层中,特别是在活动本身中吗?所以看来我别无选择,只能从视图/活动本身中调用Google标牌。对吗

然后,在从该调用获得活动结果之后,我打算像这样登录firebase:

//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
 // ...
            }
              }
                  }
Run Code Online (Sandbox Code Playgroud)

然后在演示者代码中:

//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);
         mAuth.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());
               }
             });
               }
Run Code Online (Sandbox Code Playgroud)