Android干净架构 - googleApiClient调用的位置?

时间:2017-05-09 00:51:38

标签: android mvp clean-architecture

我打算在MVP中使用干净的架构 我正在开始一个使用清洁架构方法的android项目,叔叔鲍勃认可。 我已经下载了一个模板项目,它有点像初学者模板,可以在使用干净的架构方法时启动你。 git中心位于:https://github.com/dmilicic/Android-Clean-Boilerplate.git

所以我们将有3层;每个模板的域名,演示文稿和线程。

我的问题是关于我正在设计的登录活动。我正在创建一个"登录谷歌"按钮。 但我不知道在哪里放googleAPIClient,googleSignInOptions和googleSignInResult调用。 我得到谷歌帐户验证后,然后将其传递给firebaseAuth以将用户登录到我的帐户 网站,以便另一个API调用,我不知道它是如何工作的。要知道如何使用Google帐户登录firebase应用程序 可以在这里查看:https://www.androidtutorialpoint.com/firebase/android-firebase-authentication-tutorial-using-firebase-google-login/

所以让我解释为什么我的模板有问题。 假设他想使用谷歌帐户登录,让我们开始跟踪用户的步骤:

  1. 用户点击"使用google"按钮。 应该触发用户界面要求演示者开始谷歌登录尝试。 所以在这一点上我应该为演示者制作一个交互器(用例)或者我应该使用 直接在演示者中初始化googleAPICient? 关注的是谷歌登录Api的工作原理是创建一个意图并将googleApiClient作为参数传递给它。然后使用startActivityForResult启动Intent。这就是所有的android代码,那么它不应该在表示层中,特别是在活动本身吗? 所以我似乎别无选择只能从视图/活动本身调用谷歌标志的东西。对吗?
  2. 然后在我从该调用中获得活动结果后,我计划像这样登录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
     // ...
                }
                  }
                      }
    

    然后在演示者代码中:

    //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());
                   }
                 });
                   }
    

0 个答案:

没有答案