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帐户登录):
然后,在从该调用获得活动结果之后,我打算像这样登录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)
| 归档时间: |
|
| 查看次数: |
686 次 |
| 最近记录: |