Skip to content

Commit

Permalink
(윌로우)Feat: 화면 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
rnk00 committed Jan 31, 2024
1 parent 52ac5a7 commit c8ee18f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.notation.campusnote.login

import android.app.Application
import android.util.Log
import com.kakao.sdk.common.KakaoSdk
import com.kakao.sdk.common.util.Utility


class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()

//Kakao SDK 초기화
KakaoSdk.init(this, "3fb9a572bb1f2e3cd66d370d2f7888dd")

Log.d("hash", "keyhash : ${Utility.getKeyHash(this)}")
}
}
66 changes: 66 additions & 0 deletions app/src/main/java/com/notation/campusnote/login/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.notation.campusnote.login

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.notation.campusnote.databinding.ActivityLoginBinding
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.user.UserApiClient
import com.notation.campusnote.signUp.SignUpActivity

class LoginActivity :AppCompatActivity(){
private val TAG = "KakaoLoginExample"
private lateinit var binding: ActivityLoginBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.kakaoLoginButton.setOnClickListener {
login()
}
}

private fun login() {
// 카카오계정으로 로그인 공통 콜백 설정
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
if (error != null) {
Log.e(TAG, "카카오계정으로 로그인 실패", error)
} else if (token != null) {
Log.i(TAG, "카카오계정으로 로그인 성공 ${token.accessToken}")
}
}

// 카카오톡이 설치되어 있으면 카카오톡으로 로그인, 아니면 카카오계정으로 로그인
if (UserApiClient.instance.isKakaoTalkLoginAvailable(this)) {
UserApiClient.instance.loginWithKakaoTalk(this) { token, error ->
if (error != null) {
Log.e(TAG, "카카오톡으로 로그인 실패", error)

// 특정 상황(취소 등)에 대한 처리 추가
} else if (token != null) {
Log.i(TAG, "카카오톡으로 로그인 성공 ${token.accessToken}")
// 성공적인 로그인 처리 추가
val intent = Intent(this, SignUpActivity::class.java)
startActivity(intent)
}
}
} else {
UserApiClient.instance.loginWithKakaoAccount(this, callback = callback)
}
}

private fun updateKakaoLoginUi() {
UserApiClient.instance.me { user, error ->
if (error != null) {
Log.e(TAG, "사용자 정보 요청 실패", error)
}
else if (user != null) {
Log.i(TAG, "사용자 정보 요청 성공" +
"\n회원번호: ${user.id}" +
"\n프로필사진: ${user.kakaoAccount?.profile?.thumbnailImageUrl}")
}
}
}
}

0 comments on commit c8ee18f

Please sign in to comment.