Skip to content

Commit

Permalink
[simba/#47] feat:: 10주차 카카오 로그인 구현-1
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed Jun 25, 2024
1 parent e6eecd2 commit ddd0e98
Show file tree
Hide file tree
Showing 58 changed files with 224 additions and 102 deletions.
9 changes: 9 additions & 0 deletions UMC_6th/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}
// repositories {
// google()
// mavenCentral()
// maven { url = uri("https://devrepo.kakao.com/nexus/content/groups/public/") }
// }

}

dependencies {
Expand Down Expand Up @@ -72,4 +78,7 @@ dependencies {

androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

//kakao login
implementation("com.kakao.sdk:v2-user:2.10.0")
}
29 changes: 23 additions & 6 deletions UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UMC_6th"
tools:targetApi="31">
tools:targetApi="31"
android:name=".GlobalApplication">

<service
android:name=".ForegroundService"
android:name=".service.ForegroundService"
android:enabled="true"
android:exported="true"></service>

<activity android:name=".SignUpActivity"/>
<activity android:name=".LoginActivity"/>
<activity android:name=".activity.SignUpActivity"/>
<activity android:name=".activity.LoginActivity"/>

<activity
android:name=".MainActivity"
android:name=".activity.MainActivity"
android:exported="true"
android:theme="@style/SplashTheme">
<intent-filter>
Expand All @@ -34,8 +36,23 @@
<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="kakaodb0a6ee868ee324207d083d8d5de7fcd" />
</intent-filter>
</activity>

<activity
android:name=".SongActivity"
android:name=".activity.SongActivity"
android:exported="true" />
</application>

Expand Down
12 changes: 12 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/GlobalApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.umc_6th

import android.app.Application
import com.kakao.sdk.common.KakaoSdk

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

KakaoSdk.init(this, "db0a6ee868ee324207d083d8d5de7fcd")
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.example.umc_6th
package com.example.umc_6th.activity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.umc_6th.network.AuthService
import com.example.umc_6th.view.LoginView
import com.example.umc_6th.model.Result
import com.example.umc_6th.model.User
import com.example.umc_6th.databinding.ActivityLoginBinding
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.user.UserApiClient

class LoginActivity:AppCompatActivity(), LoginView {

Expand All @@ -19,9 +24,14 @@ class LoginActivity:AppCompatActivity(), LoginView {
binding.loginSignUpTv.setOnClickListener {
startActivity(Intent(this, SignUpActivity::class.java))
}

binding.loginSignInBtn.setOnClickListener{
login()
}

binding.loginKakakoLoginIv.setOnClickListener {
loginKakao()
}
}

private fun login() {
Expand All @@ -44,6 +54,23 @@ class LoginActivity:AppCompatActivity(), LoginView {
authService.login(User(email, pwd, ""))
}

private fun loginKakao() {
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
if (error != null) {
Toast.makeText(this, "카카오 로그인 실패", Toast.LENGTH_SHORT).show()
} else if (token != null) {
Toast.makeText(this, "카카오 로그인 성공", Toast.LENGTH_SHORT).show()
startMainActivity() // 로그인 성공 시 메인 액티비티로 이동
}
}

if (UserApiClient.instance.isKakaoTalkLoginAvailable(this)) {
UserApiClient.instance.loginWithKakaoTalk(this, callback = callback)
} else {
UserApiClient.instance.loginWithKakaoAccount(this, callback = callback)
}
}

private fun startMainActivity() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.example.umc_6th
package com.example.umc_6th.activity

import LookFragment
import com.example.umc_6th.fragment.LookFragment
import androidx.appcompat.app.AppCompatActivity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.example.umc_6th.model.Album
import com.example.umc_6th.fragment.HomeFragment
import com.example.umc_6th.fragment.LockerFragment
import com.example.umc_6th.R
import com.example.umc_6th.fragment.SearchFragment
import com.example.umc_6th.model.Song
import com.example.umc_6th.database.SongDatabase
import com.example.umc_6th.databinding.ActivityMainBinding
import com.google.gson.Gson

Expand Down Expand Up @@ -50,7 +57,7 @@ class MainActivity : AppCompatActivity() {
editor.putInt("songId", song.id)
editor.apply()

val intent = Intent(this,SongActivity::class.java)
val intent = Intent(this, SongActivity::class.java)
startActivity(intent)
activityResultLauncher.launch(intent)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.example.umc_6th
package com.example.umc_6th.activity

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.umc_6th.network.AuthService
import com.example.umc_6th.view.SignUpView
import com.example.umc_6th.model.User
import com.example.umc_6th.databinding.ActivitySignupBinding
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class SignUpActivity : AppCompatActivity(), SignUpView{
class SignUpActivity : AppCompatActivity(), SignUpView {

lateinit var binding : ActivitySignupBinding

Expand All @@ -24,7 +23,7 @@ class SignUpActivity : AppCompatActivity(), SignUpView{
}
}

private fun getUser() : User{
private fun getUser() : User {
val email : String = binding.signUpIdEt.text.toString() + "@" + binding.signUpDirectInputEt.text.toString()
val pwd : String = binding.signUpPasswordEt.text.toString()
val name: String = binding.signUpNameEt.text.toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.umc_6th
package com.example.umc_6th.activity

import android.annotation.SuppressLint
import android.app.ActivityManager
import android.content.Context
import android.content.Intent
Expand All @@ -10,9 +9,12 @@ import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.umc_6th.utils.CustomSnackbar
import com.example.umc_6th.service.ForegroundService
import com.example.umc_6th.R
import com.example.umc_6th.model.Song
import com.example.umc_6th.database.SongDatabase
import com.example.umc_6th.databinding.ActivitySongBinding
import com.google.gson.Gson
import java.util.Timer

class SongActivity : AppCompatActivity() {

Expand Down Expand Up @@ -71,7 +73,7 @@ class SongActivity : AppCompatActivity() {
private fun startStopService() {
if(isServiceRunning(ForegroundService::class.java)){
Toast.makeText(this, "Foreground Service Stopped",Toast.LENGTH_SHORT).show()
stopService(Intent(this,ForegroundService::class.java))
stopService(Intent(this, ForegroundService::class.java))
} else{
Toast.makeText(this, "Foreground Service Started", Toast.LENGTH_SHORT).show()
startService(Intent(this, ForegroundService::class.java))
Expand Down Expand Up @@ -182,7 +184,7 @@ class SongActivity : AppCompatActivity() {
// Toast.makeText(this,"first song", Toast.LENGTH_SHORT).show()
}
else if(nowPos + direct >= songs.size){
CustomSnackbar.make(binding.root,"마지막 곡입니다.").show()
CustomSnackbar.make(binding.root, "마지막 곡입니다.").show()
// Toast.makeText(this,"last song",Toast.LENGTH_SHORT).show()
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.umc_6th.model.Album
import com.example.umc_6th.databinding.ItemAlbumBinding

class AlbumRVAdapter(private val albumList:ArrayList<Album>) : RecyclerView.Adapter<AlbumRVAdapter.ViewHolder>() {
Expand Down Expand Up @@ -32,13 +33,13 @@ class AlbumRVAdapter(private val albumList:ArrayList<Album>) : RecyclerView.Adap
notifyDataSetChanged()
}

override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): AlbumRVAdapter.ViewHolder {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
val binding: ItemAlbumBinding = ItemAlbumBinding.inflate(LayoutInflater.from(viewGroup.context),viewGroup,false)

return ViewHolder(binding)
}

override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(albumList[position])
holder.itemView.setOnClickListener{
mItemClickListener.onItemClick(albumList[position]) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.umc_6th.fragment.DetailFragment
import com.example.umc_6th.fragment.SongFragment
import com.example.umc_6th.fragment.VideoFragment

class AlbumVPAdapter(fragment:Fragment) : FragmentStateAdapter(fragment){
override fun getItemCount(): Int = 3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import android.annotation.SuppressLint
import android.util.SparseBooleanArray
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Recycler
import com.example.umc_6th.model.Song
import com.example.umc_6th.databinding.ItemLockerAlbumBinding

class LockerAlbumRVAdapter () : RecyclerView.Adapter<LockerAlbumRVAdapter.ViewHolder>(){
Expand All @@ -17,14 +17,14 @@ class LockerAlbumRVAdapter () : RecyclerView.Adapter<LockerAlbumRVAdapter.ViewHo
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): LockerAlbumRVAdapter.ViewHolder {
): ViewHolder {
val binding: ItemLockerAlbumBinding = ItemLockerAlbumBinding
.inflate(LayoutInflater.from(parent.context),parent,false)

return ViewHolder(binding)
}

override fun onBindViewHolder(holder: LockerAlbumRVAdapter.ViewHolder, position: Int) {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(songs[position])

holder.binding.itemLockerAlbumMoreIv.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.umc_6th.fragment.MusicFileFragment
import com.example.umc_6th.fragment.SavedAlbumFragment
import com.example.umc_6th.fragment.SavedSongFragment

class LockerVPAdapter(fragment: Fragment) :FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.umc_6th.model.Album
import com.example.umc_6th.databinding.ItemLockerAlbumBinding


Expand All @@ -20,13 +21,13 @@ class SavedAlbumRVAdapter (): RecyclerView.Adapter<SavedAlbumRVAdapter.ViewHolde
mItemClickListener = itemClickListener
}

override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): SavedAlbumRVAdapter.ViewHolder {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
val binding: ItemLockerAlbumBinding = ItemLockerAlbumBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false)

return ViewHolder(binding)
}

override fun onBindViewHolder(holder: SavedAlbumRVAdapter.ViewHolder, position: Int) {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(albums[position])
holder.binding.itemLockerAlbumMoreIv.setOnClickListener {
mItemClickListener.onRemoveSong(albums[position].id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.umc_6th
package com.example.umc_6th.adapter

import android.content.Context
import android.util.Log
Expand All @@ -8,18 +8,19 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.umc_6th.model.FloChartResult
import com.example.umc_6th.databinding.ItemSongBinding

class SongRVAdapter(val context: Context, val result : FloChartResult) : RecyclerView.Adapter<SongRVAdapter.ViewHolder>() {


override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): SongRVAdapter.ViewHolder {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
val binding: ItemSongBinding = ItemSongBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false)

return ViewHolder(binding)
}

override fun onBindViewHolder(holder: SongRVAdapter.ViewHolder, position: Int) {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
//holder.bind(result.songs[position])

if(result.songs[position].coverImgUrl == "" || result.songs[position].coverImgUrl == null){
Expand Down
Loading

0 comments on commit ddd0e98

Please sign in to comment.