generated from ajou4095/template-android
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
.../ac/dnd/bookkeeping/android/data/repository/feature/relation/KakaoFriendRepositoryImpl.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,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 | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...c/main/kotlin/ac/dnd/bookkeeping/android/domain/model/feature/relation/KakaoFriendInfo.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,6 @@ | ||
package ac.dnd.bookkeeping.android.domain.model.feature.relation | ||
|
||
data class KakaoFriendInfo( | ||
val name: String, | ||
val profileImageUrl: String, | ||
) |
7 changes: 7 additions & 0 deletions
7
domain/src/main/kotlin/ac/dnd/bookkeeping/android/domain/repository/KakaoFriendRepository.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,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> | ||
} |
12 changes: 12 additions & 0 deletions
12
...n/ac/dnd/bookkeeping/android/domain/usecase/feature/relation/GetKakaoFriendInfoUseCase.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 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() | ||
} | ||
} |