-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Team-HMH/feat/kakao_login
[feat/kakao_login]: 카카오 소셜 로그인, 닉네임 불러오기, 로그아웃 구현
- Loading branch information
Showing
25 changed files
with
451 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
hmh("feature") | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "com.hmh.hamyeonham.feature.login" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.common) | ||
implementation(libs.appcompat) | ||
implementation(libs.material) | ||
implementation(libs.constraintlayout) | ||
|
||
// kakao | ||
implementation(libs.kakao.login) | ||
|
||
implementation(libs.dot.indicator) | ||
implementation(libs.coil.core) | ||
} |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
<activity | ||
android:name=".UserInfoActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".LoginActivity" | ||
android:exported="false" /> | ||
</application> | ||
|
||
</manifest> |
92 changes: 92 additions & 0 deletions
92
feature/login/src/main/java/com/hmh/hamyeonham/feature/login/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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.hmh.hamyeonham.feature.login | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.hmh.hamyeonham.common.context.toast | ||
import com.hmh.hamyeonham.feature.login.data.DummyImage | ||
import com.hmh.hamyeonham.feature.login.databinding.ActivityLoginBinding | ||
import com.kakao.sdk.auth.model.OAuthToken | ||
import com.kakao.sdk.common.model.ClientError | ||
import com.kakao.sdk.common.model.ClientErrorCause | ||
import com.kakao.sdk.user.UserApiClient | ||
|
||
class LoginActivity : AppCompatActivity() { | ||
private lateinit var binding: ActivityLoginBinding | ||
|
||
private val loginViewModel: LoginViewModel by viewModels() | ||
private lateinit var loginViewPagerAdapter: LoginViewPagerAdapter | ||
|
||
// 삭제 예정 | ||
private val dummyImageList = listOf( | ||
DummyImage( | ||
Image = R.drawable.login_sample_rectagle_viewpager, | ||
), | ||
DummyImage( | ||
Image = R.drawable.login_sample_rectagle_viewpager, | ||
), | ||
DummyImage( | ||
Image = R.drawable.login_sample_rectagle_viewpager, | ||
), | ||
) | ||
|
||
private val callback: (OAuthToken?, Throwable?) -> Unit = { token, error -> | ||
when { | ||
error != null -> { | ||
} | ||
|
||
token != null -> { | ||
moveToUserInfoActivity() | ||
} | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
binding = ActivityLoginBinding.inflate(layoutInflater) | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
|
||
binding.btnLogin.setOnClickListener { | ||
loginWithKakaoApp() | ||
} | ||
setLoginViewPager() | ||
} | ||
|
||
private fun setLoginViewPager() { | ||
loginViewPagerAdapter = LoginViewPagerAdapter(dummyImageList) | ||
binding.run { | ||
vpLogin.adapter = loginViewPagerAdapter | ||
indicatorLoginDots.attachTo(binding.vpLogin) | ||
} | ||
} | ||
|
||
private fun loginWithKakaoApp() { | ||
if (UserApiClient.instance.isKakaoTalkLoginAvailable(this)) { | ||
UserApiClient.instance.loginWithKakaoTalk(this) { token, error -> | ||
if (error != null) { | ||
toast("카카오 로그인 실패") | ||
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) { | ||
toast("다시 로그인 해주세요.") | ||
return@loginWithKakaoTalk | ||
} | ||
loginWithKakaoAccount() | ||
} else if (token != null) { | ||
toast("카카오 로그인 성공") | ||
moveToUserInfoActivity() | ||
} | ||
} | ||
} else { | ||
loginWithKakaoAccount() | ||
} | ||
} | ||
|
||
private fun loginWithKakaoAccount() { | ||
UserApiClient.instance.loginWithKakaoAccount(this, callback = callback) | ||
} | ||
|
||
private fun moveToUserInfoActivity() { | ||
startActivity(Intent(this, UserInfoActivity::class.java)) | ||
finish() | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginViewModel.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.hmh.hamyeonham.feature.login | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
|
||
class LoginViewModel : ViewModel(){ | ||
|
||
private val _kakaoLoginResult = MutableLiveData<Boolean>() | ||
val kakaoLoginResult: LiveData<Boolean> get() = _kakaoLoginResult | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginViewPagerAdapter.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.hmh.hamyeonham.feature.login | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import coil.load | ||
import com.hmh.hamyeonham.feature.login.data.DummyImage | ||
import com.hmh.hamyeonham.feature.login.databinding.ItemLoginViewPagerBinding | ||
|
||
class LoginViewPagerAdapter(private val imageList: List<DummyImage>) : | ||
RecyclerView.Adapter<LoginViewPagerAdapter.PagerViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PagerViewHolder { | ||
val view = LayoutInflater.from(parent.context) | ||
.inflate(R.layout.item_login_view_pager, parent, false) | ||
return PagerViewHolder(ItemLoginViewPagerBinding.bind(view)) | ||
} | ||
|
||
class PagerViewHolder(private val binding: ItemLoginViewPagerBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun onBindView(imageInfo: DummyImage) { | ||
binding.run { | ||
ivLoginViewPagerItem.load(imageInfo.Image) { | ||
placeholder(R.drawable.login_sample_rectagle_viewpager) | ||
error(R.drawable.login_sample_rectagle_viewpager) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int = imageList.size | ||
|
||
override fun onBindViewHolder(holder: PagerViewHolder, position: Int) { | ||
val exploreImage = imageList[position] | ||
holder.onBindView(exploreImage) | ||
} | ||
} |
Oops, something went wrong.