From 065ee13f7c92356679a41d2aa3fedc1d2673516e Mon Sep 17 00:00:00 2001 From: jinuemong Date: Tue, 6 Feb 2024 14:25:14 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=ED=94=BC=EC=BB=A4=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../relation/KakaoFriendRepositoryImpl.kt | 70 +++++++++++++++++++ .../model/feature/relation/KakaoFriendInfo.kt | 6 ++ .../repository/KakaoFriendRepository.kt | 7 ++ .../relation/GetKakaoFriendInfoUseCase.kt | 12 ++++ 4 files changed, 95 insertions(+) create mode 100644 data/src/main/kotlin/ac/dnd/bookkeeping/android/data/repository/feature/relation/KakaoFriendRepositoryImpl.kt create mode 100644 domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/model/feature/relation/KakaoFriendInfo.kt create mode 100644 domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/repository/KakaoFriendRepository.kt create mode 100644 domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/usecase/feature/relation/GetKakaoFriendInfoUseCase.kt diff --git a/data/src/main/kotlin/ac/dnd/bookkeeping/android/data/repository/feature/relation/KakaoFriendRepositoryImpl.kt b/data/src/main/kotlin/ac/dnd/bookkeeping/android/data/repository/feature/relation/KakaoFriendRepositoryImpl.kt new file mode 100644 index 00000000..0fbd36e8 --- /dev/null +++ b/data/src/main/kotlin/ac/dnd/bookkeeping/android/data/repository/feature/relation/KakaoFriendRepositoryImpl.kt @@ -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 { + 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 + ) + ) + } + } + } + } + } +} diff --git a/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/model/feature/relation/KakaoFriendInfo.kt b/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/model/feature/relation/KakaoFriendInfo.kt new file mode 100644 index 00000000..466737a6 --- /dev/null +++ b/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/model/feature/relation/KakaoFriendInfo.kt @@ -0,0 +1,6 @@ +package ac.dnd.bookkeeping.android.domain.model.feature.relation + +data class KakaoFriendInfo( + val name: String, + val profileImageUrl: String, +) diff --git a/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/repository/KakaoFriendRepository.kt b/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/repository/KakaoFriendRepository.kt new file mode 100644 index 00000000..e89eed50 --- /dev/null +++ b/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/repository/KakaoFriendRepository.kt @@ -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 +} diff --git a/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/usecase/feature/relation/GetKakaoFriendInfoUseCase.kt b/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/usecase/feature/relation/GetKakaoFriendInfoUseCase.kt new file mode 100644 index 00000000..cc94367a --- /dev/null +++ b/domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/usecase/feature/relation/GetKakaoFriendInfoUseCase.kt @@ -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{ + return kakaoFriendRepository.loadFriendInfo() + } +}