-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc95e3b
commit a71b04b
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
presentation/src/main/java/com/example/draven/ui/sign/LoginActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,40 @@ | ||
package com.example.draven.ui.sign | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.result.ActivityResult | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import com.example.draven.R | ||
import com.example.draven.base.BaseActivity | ||
import com.example.draven.databinding.ActivityLoginBinding | ||
import com.google.android.gms.auth.api.signin.GoogleSignIn | ||
import com.google.android.gms.auth.api.signin.GoogleSignInOptions | ||
import com.google.android.gms.common.api.ApiException | ||
|
||
class LoginActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_login) { | ||
|
||
private lateinit var activityLauncher: ActivityResultLauncher<Intent> | ||
private val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | ||
.requestEmail() | ||
.build() | ||
private val client = GoogleSignIn.getClient(this, gso) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
activityLauncher = | ||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult -> | ||
if (result.resultCode == RESULT_OK) { | ||
try { | ||
val task = GoogleSignIn.getSignedInAccountFromIntent(result.data) | ||
val account = task.result | ||
} catch (e: ApiException) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun onLogin() = activityLauncher.launch(client.signInIntent) | ||
} |