Skip to content

Commit

Permalink
(willow) Feat: 로그인 화면
Browse files Browse the repository at this point in the history
  • Loading branch information
rnk00 committed Jan 31, 2024
2 parents f48c62a + a1a6557 commit 52ac5a7
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.storage.CacheResetOnProcessCanceled.enabled

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
Expand Down Expand Up @@ -42,6 +40,7 @@ android {
}

dependencies {
implementation ("com.kakao.sdk:v2-user:2.19.0") // 카카오 로그인

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
Expand Down
24 changes: 20 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".GlobalApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -12,18 +15,31 @@
android:supportsRtl="true"
android:theme="@style/Theme.CampusNote"
tools:targetApi="31">

<activity android:name=".MainActivity"
android:exported="false"/>

<activity
android:name=".MainActivity"
android:exported="false" />
<activity
android:name=".signUp.SignUpActivity"
android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:host="oauth"
android:scheme="kakao3fb9a572bb1f2e3cd66d370d2f7888dd" />
</intent-filter>
</activity>
</application>

</manifest>
18 changes: 18 additions & 0 deletions app/src/main/java/com/notation/campusnote/GlobalApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.notation.campusnote

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)}")
}
}
49 changes: 49 additions & 0 deletions app/src/main/java/com/notation/campusnote/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.notation.campusnote

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

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}")
// 성공적인 로그인 처리 추가
}
}
} else {
UserApiClient.instance.loginWithKakaoAccount(this, callback = callback)
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/icon_kakao.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="27dp"
android:viewportWidth="28"
android:viewportHeight="27">
<path
android:pathData="M14,0.963C6.268,0.963 0,5.75 0,11.653C0,15.324 2.424,18.56 6.116,20.485L4.563,26.093C4.425,26.588 4.999,26.983 5.439,26.696L12.248,22.255C12.822,22.31 13.406,22.342 14,22.342C21.732,22.342 28,17.556 28,11.653C28,5.75 21.732,0.963 14,0.963Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity">


<Button
android:id="@+id/kakao_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="카카오 로그인"
android:background="@color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="40dp"/>


</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("https://devrepo.kakao.com/nexus/content/groups/public/")
}
}

Expand Down

0 comments on commit 52ac5a7

Please sign in to comment.