Skip to content

Commit

Permalink
[Feat]: 카카오 피커 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong committed Feb 6, 2024
1 parent fb70083 commit 065ee13
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package ac.dnd.bookkeeping.android.data.repository.feature.relation

import ac.dnd.bookkeeping.android.domain.model.error.ServerException
import ac.dnd.bookkeeping.android.domain.model.feature.relation.KakaoFriendInfo
import ac.dnd.bookkeeping.android.domain.repository.KakaoFriendRepository
import android.content.Context
import com.kakao.sdk.friend.client.PickerClient
import com.kakao.sdk.friend.model.OpenPickerFriendRequestParams
import com.kakao.sdk.friend.model.PickerOrientation
import com.kakao.sdk.friend.model.ViewAppearance
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

class KakaoFriendRepositoryImpl @Inject constructor(
@ApplicationContext private val context: Context
) : KakaoFriendRepository {

override suspend fun loadFriendInfo(): Result<KakaoFriendInfo> {
return runCatching {
PickerClient.findKakaoFriend()
}
.onSuccess {
Result.success(it)
}
.onFailure { error ->
throw ServerException("Error",error.message.toString())
}
}


private suspend fun PickerClient.Companion.findKakaoFriend(): KakaoFriendInfo {
return suspendCoroutine { continuation ->
val openPickerFriendRequestParams = OpenPickerFriendRequestParams(
title = "팝업 싱글 친구 피커",
viewAppearance = ViewAppearance.AUTO,
orientation = PickerOrientation.AUTO,
enableSearch = true,
enableIndex = true,
showMyProfile = true,
showFavorite = true
)

instance.selectFriendPopup(
context = context,
params = openPickerFriendRequestParams
) { selectedUsers, error ->
if (error != null) {
continuation.resumeWithException(error)
} else {
val user = selectedUsers?.users?.firstOrNull()
val name = user?.profileNickname ?: ""
val image = user?.profileThumbnailImage ?: ""
if (name.isEmpty() || image.isEmpty()) {
continuation.resumeWithException(RuntimeException("Can't find user"))
} else {
continuation.resume(
KakaoFriendInfo(
name = name,
profileImageUrl = image
)
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ac.dnd.bookkeeping.android.domain.model.feature.relation

data class KakaoFriendInfo(
val name: String,
val profileImageUrl: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ac.dnd.bookkeeping.android.domain.repository

import ac.dnd.bookkeeping.android.domain.model.feature.relation.KakaoFriendInfo

interface KakaoFriendRepository {
suspend fun loadFriendInfo(): Result<KakaoFriendInfo>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ac.dnd.bookkeeping.android.domain.usecase.feature.relation

import ac.dnd.bookkeeping.android.domain.model.feature.relation.KakaoFriendInfo
import ac.dnd.bookkeeping.android.domain.repository.KakaoFriendRepository

class GetKakaoFriendInfoUseCase(
private val kakaoFriendRepository: KakaoFriendRepository
) {
suspend operator fun invoke(): Result<KakaoFriendInfo>{
return kakaoFriendRepository.loadFriendInfo()
}
}

0 comments on commit 065ee13

Please sign in to comment.