Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class FriendListDetailBottomSheetFragment : BottomSheetDialogFragment() {

is UiState.ApiError -> {
messageListBottomSheet?.dismiss()
showPokeToast(getString(R.string.poke_user_alert_exceeded))
showPokeToast(getString(R.string.toast_poke_error))
}

is UiState.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class FriendListSummaryActivity : AppCompatActivity() {

is UiState.ApiError -> {
messageListBottomSheet?.dismiss()
showPokeToast(getString(R.string.poke_user_alert_exceeded))
showPokeToast(getString(R.string.toast_poke_error))
}

is UiState.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ fun FriendListSummaryScreen(

is UiState.ApiError -> {
dismissBottomSheet(fragmentManager, bottomSheetTag)
fragmentActivity?.showPokeToast(context.getString(R.string.poke_user_alert_exceeded))
fragmentActivity?.showPokeToast(context.getString(R.string.toast_poke_error))
}

is UiState.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,22 @@ class PokeMainActivity : AppCompatActivity() {
.onEach {
when (it) {
is UiState.Loading -> {}
is UiState.Success<PokeUser> -> initPokeFriendView(it.data)
is UiState.ApiError -> showPokeToast(getString(R.string.toast_poke_error))
is UiState.Failure -> showPokeToast(it.throwable.message ?: getString(R.string.toast_poke_error))
is UiState.Success<PokeUser> -> {
binding.layoutPokeMyFriend.setVisible(true)
initPokeFriendView(it.data)
}

is UiState.ApiError -> {
binding.layoutPokeMyFriend.setVisible(false)
if (it.statusCode != POKE_FRIEND_EMPTY_STATUS_CODE) {
showPokeToast(getString(R.string.toast_poke_error))
}
}

is UiState.Failure -> {
binding.layoutPokeMyFriend.setVisible(false)
showPokeToast(it.throwable.message ?: getString(R.string.toast_poke_error))
}
}
}
.launchIn(lifecycleScope)
Expand Down Expand Up @@ -261,7 +274,7 @@ class PokeMainActivity : AppCompatActivity() {

is UiState.ApiError -> {
messageListBottomSheet?.dismiss()
showPokeToast(getString(R.string.poke_user_alert_exceeded))
showPokeToast(getString(R.string.toast_poke_error))
}

is UiState.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import org.sopt.official.feature.poke.UiState
import timber.log.Timber
import javax.inject.Inject

internal const val POKE_FRIEND_EMPTY_STATUS_CODE = "EMPTY_POKE_FRIEND"

@HiltViewModel
class PokeMainViewModel @Inject constructor(
private val getPokeMeUseCase: GetPokeMeUseCase,
Expand Down Expand Up @@ -87,8 +89,10 @@ class PokeMainViewModel @Inject constructor(
viewModelScope.launch {
_pokeFriendUiState.emit(UiState.Loading)
getPokeFriendUseCase.invoke()
.onSuccess {
_pokeFriendUiState.emit(UiState.Success(it[0]))
.onSuccess { friendList ->
friendList.firstOrNull()?.let {
_pokeFriendUiState.emit(UiState.Success(it))
} ?: _pokeFriendUiState.emit(UiState.ApiError(POKE_FRIEND_EMPTY_STATUS_CODE, ""))
}
.onApiError { statusCode, responseMessage ->
_pokeFriendUiState.emit(UiState.ApiError(statusCode, responseMessage))
Expand Down Expand Up @@ -163,15 +167,24 @@ class PokeMainViewModel @Inject constructor(
}
if (_pokeSimilarFriendUiState.value is UiState.Success<List<PokeRandomUserList.PokeRandomUsers>>) {
val oldData = (_pokeSimilarFriendUiState.value as UiState.Success<List<PokeRandomUserList.PokeRandomUsers>>).data
for (friend in oldData) {
friend.userInfoList.find { it.userId == userId }?.isAlreadyPoke = true
val updatedSimilarFriends = oldData.map { randomUsers ->
randomUsers.copy(
userInfoList = randomUsers.userInfoList.map { pokeUser ->
if (pokeUser.userId == userId) pokeUser.copy(isAlreadyPoke = true)
else pokeUser
}
)
}
_pokeSimilarFriendUiState.emit(UiState.Loading)
_pokeSimilarFriendUiState.emit(UiState.Success(oldData))
_pokeSimilarFriendUiState.emit(UiState.Success(updatedSimilarFriends))
}
}
}

fun resetPokeUserUiState() {
_pokeUserUiState.value = UiState.Loading
}

fun setAnonymousFriend(pokeUser: PokeUser?) {
_anonymousFriend.value = pokeUser
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ import org.sopt.official.feature.poke.friend.summary.FriendListSummaryActivity
import org.sopt.official.feature.poke.message.MessageListBottomSheetFragment
import org.sopt.official.feature.poke.user.PokeUserListClickListener
import org.sopt.official.feature.poke.util.addOnAnimationEndListener
import org.sopt.official.feature.poke.util.dismissBottomSheet
import org.sopt.official.feature.poke.util.isBestFriend
import org.sopt.official.feature.poke.util.isSoulMate
import org.sopt.official.feature.poke.util.setRelationStrokeColor
import org.sopt.official.feature.poke.util.showPokeToast
import org.sopt.official.model.UserStatus

private const val MESSAGE_LIST_BOTTOM_SHEET_TAG = "MessageListBottomSheet"

@Composable
fun PokeScreen(
paddingValues: PaddingValues,
Expand All @@ -88,6 +91,8 @@ fun PokeScreen(
context.findActivity<FragmentActivity>()
}

val fragmentManager = fragmentActivity?.supportFragmentManager

val pokeMeUiState by viewModel.pokeMeUiState.collectAsStateWithLifecycle()
val pokeFriendUiState by viewModel.pokeFriendUiState.collectAsStateWithLifecycle()
val pokeSimilarFriendUiState by viewModel.pokeSimilarFriendUiState.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -151,10 +156,12 @@ fun PokeScreen(
pokeMainListAdapter.submitList(state.data)
currentBinding.refreshLayoutPokeMain.isRefreshing = false
}

is UiState.ApiError, is UiState.Failure -> {
activity?.showPokeToast(context.getString(R.string.toast_poke_error))
currentBinding.refreshLayoutPokeMain.isRefreshing = false
}

is UiState.Loading -> {}
}
}
Expand All @@ -168,9 +175,11 @@ fun PokeScreen(
initPokeMeView(currentBinding, state.data, tracker, userStatus, activity, viewModel)
}
}

is UiState.ApiError, is UiState.Failure -> {
currentBinding.layoutSomeonePokeMe.setVisible(false)
}

else -> {}
}
}
Expand All @@ -180,12 +189,23 @@ fun PokeScreen(
binding?.let { currentBinding ->
when (val state = pokeFriendUiState) {
is UiState.Success -> {
currentBinding.layoutPokeMyFriend.setVisible(true)
if (activity is FragmentActivity) {
initPokeFriendView(currentBinding, state.data, tracker, userStatus, activity, viewModel)
}
}
is UiState.ApiError -> activity?.showPokeToast(context.getString(R.string.toast_poke_error))
is UiState.Failure -> activity?.showPokeToast(state.throwable.message ?: context.getString(R.string.toast_poke_error))

is UiState.ApiError -> {
currentBinding.layoutPokeMyFriend.setVisible(false)
if (state.statusCode != POKE_FRIEND_EMPTY_STATUS_CODE) {
activity?.showPokeToast(context.getString(R.string.toast_poke_error))
}
}

is UiState.Failure -> {
currentBinding.layoutPokeMyFriend.setVisible(false)
activity?.showPokeToast(state.throwable.message ?: context.getString(R.string.toast_poke_error))
}
else -> {}
}
}
Expand Down Expand Up @@ -231,10 +251,19 @@ fun PokeScreen(
}
}
}
is UiState.ApiError -> activity?.showPokeToast(context.getString(R.string.poke_user_alert_exceeded))
is UiState.Failure -> activity?.showPokeToast(state.throwable.message ?: context.getString(R.string.toast_poke_error))

is UiState.ApiError -> {
activity?.showPokeToast(context.getString(R.string.toast_poke_error))
}

is UiState.Failure -> {
activity?.showPokeToast(state.throwable.message ?: context.getString(R.string.toast_poke_error))
}

else -> {}
}
dismissBottomSheet(fragmentManager, MESSAGE_LIST_BOTTOM_SHEET_TAG)
viewModel.resetPokeUserUiState()
}
}

Expand Down Expand Up @@ -335,9 +364,7 @@ private fun initPokeMeView(
}

if (pokeMeItem.isAnonymous) {
pokeMeItem.anonymousImage.takeIf { it.isNotEmpty() }?.let {
imgUserProfileSomeonePokeMe.load(it) { transformations(CircleCropTransformation()) }
} ?: imgUserProfileSomeonePokeMe.setImageResource(R.drawable.ic_empty_profile)
imgUserProfileSomeonePokeMe.load(R.drawable.image_anonymous_profile) { transformations(CircleCropTransformation()) }
tvUserNameSomeonePokeMe.text = pokeMeItem.anonymousName
tvFriendsStatusSomeonePokeMe.visibility = View.GONE
tvUserGenerationSomeonePokeMe.visibility = View.GONE
Expand Down Expand Up @@ -414,7 +441,7 @@ private fun initPokeFriendView(
}

if (pokeFriendItem.isAnonymous) {
imgUserProfilePokeMyFriend.load(pokeFriendItem.anonymousImage) { transformations(CircleCropTransformation()) }
imgUserProfilePokeMyFriend.load(R.drawable.image_anonymous_profile) { transformations(CircleCropTransformation()) }
tvUserNamePokeMyFriend.text = pokeFriendItem.anonymousName
} else {
pokeFriendItem.profileImage.takeIf { it.isNotEmpty() }?.let {
Expand Down Expand Up @@ -447,7 +474,7 @@ private fun showMessageListBottomSheet(
viewModel: PokeMainViewModel,
userId: Int,
pokeMessageType: PokeMessageType,
isFirstMeet: Boolean = false
isFirstMeet: Boolean = false,
) {
val messageListBottomSheet =
MessageListBottomSheetFragment.Builder()
Expand All @@ -462,5 +489,5 @@ private fun showMessageListBottomSheet(
}
.create()

messageListBottomSheet.show(activity.supportFragmentManager, messageListBottomSheet.tag)
messageListBottomSheet.show(activity.supportFragmentManager, MESSAGE_LIST_BOTTOM_SHEET_TAG)
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fun NavGraphBuilder.pokeNavGraph(
PokeNotificationScreen(
paddingValues = paddingValues,
userStatus = userStatus,
navigateUp = navController::navigateUp,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class PokeNotificationActivity : AppCompatActivity() {

is UiState.ApiError -> {
messageListBottomSheet?.dismiss()
showPokeToast(getString(R.string.poke_user_alert_exceeded))
showPokeToast(getString(R.string.toast_poke_error))
}

is UiState.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ class PokeNotificationAdapter(
fun onBind(item: PokeUser) {
with(viewBinding) {
if (item.isAnonymous) {
item.anonymousImage.takeIf { it.isNotEmpty() }?.let {
imgUserProfile.load(it) { transformations(CircleCropTransformation()) }
} ?: imgUserProfile.setImageResource(R.drawable.ic_empty_profile)
imgUserProfile.load(R.drawable.image_anonymous_profile) { transformations(CircleCropTransformation()) }
tvUserName.text = item.anonymousName
tvUserGeneration.visibility = View.GONE
tvUserFriendsStatus.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import kotlinx.coroutines.launch
import org.sopt.official.analytics.EventType
import org.sopt.official.analytics.compose.LocalTracker
import org.sopt.official.common.context.findActivity
import org.sopt.official.common.util.setOnSingleClickListener
import org.sopt.official.domain.poke.entity.PokeUser
import org.sopt.official.domain.poke.type.PokeMessageType
import org.sopt.official.feature.poke.R
Expand All @@ -74,6 +75,7 @@ import org.sopt.official.model.UserStatus
fun PokeNotificationScreen(
paddingValues: PaddingValues,
userStatus: UserStatus,
navigateUp: () -> Unit,
viewModel: PokeNotificationViewModel = hiltViewModel()
) {
val context = LocalContext.current
Expand Down Expand Up @@ -189,14 +191,17 @@ fun PokeNotificationScreen(
if (!currentBinding.animationFriendViewLottie.isAnimating) {
if (isBestFriend) {
currentBinding.layoutAnonymousFriendLottie.visibility = View.VISIBLE
currentBinding.tvFreindLottie.text = context.getString(R.string.anonymous_to_friend, user.anonymousName, "단짝친구가")
currentBinding.tvFreindLottieHint.text = context.getString(R.string.anonymous_user_info_part, user.generation, user.part)
currentBinding.tvFreindLottie.text =
context.getString(R.string.anonymous_to_friend, user.anonymousName, "단짝친구가")
currentBinding.tvFreindLottieHint.text =
context.getString(R.string.anonymous_user_info_part, user.generation, user.part)
currentBinding.animationFriendViewLottie.setAnimation(R.raw.friendtobestfriend)
currentBinding.animationFriendViewLottie.playAnimation()
} else if (isSoulMate) {
viewModel.setAnonymousFriend(user)
currentBinding.layoutAnonymousFriendLottie.visibility = View.VISIBLE
currentBinding.tvFreindLottie.text = context.getString(R.string.anonymous_to_friend, user.anonymousName, "천생연분이")
currentBinding.tvFreindLottie.text =
context.getString(R.string.anonymous_to_friend, user.anonymousName, "천생연분이")
currentBinding.animationFriendViewLottie.setAnimation(R.raw.bestfriendtosoulmate)
currentBinding.animationFriendViewLottie.playAnimation()
}
Expand All @@ -207,7 +212,7 @@ fun PokeNotificationScreen(

is UiState.ApiError -> {
dismissBottomSheet(fragmentManager, bottomSheetTag)
fragmentActivity?.showPokeToast(context.getString(R.string.poke_user_alert_exceeded))
fragmentActivity?.showPokeToast(context.getString(R.string.toast_poke_error))
}

is UiState.Failure -> {
Expand All @@ -225,7 +230,7 @@ fun PokeNotificationScreen(
properties = mapOf("view_type" to userStatus.name),
)

onPauseOrDispose { }
onPauseOrDispose { }
}

AndroidViewBinding(
Expand All @@ -237,6 +242,7 @@ fun PokeNotificationScreen(
binding = this
if (recyclerviewPokeNotification.adapter == null) {
includeAppBar.textViewTitle.text = root.context.getString(R.string.poke_title)
includeAppBar.toolbar.setOnSingleClickListener { navigateUp() }

recyclerviewPokeNotification.adapter = adapter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ class OnboardingPokeUserViewModel @Inject constructor(
_onboardingPokeUserListUiState.emit(UiState.Loading)
getOnboardingPokeUserListUseCase.invoke(randomType = randomType.value, size = 6)
.onSuccess { response ->
_onboardingPokeUserListUiState.emit(UiState.Success(response.randomInfoList[0]))
val nextRandomUsers = response.randomInfoList.firstOrNull()
?: PokeRandomUserList.PokeRandomUsers(
randomType = randomType.value,
randomTitle = "",
userInfoList = emptyList(),
)
_onboardingPokeUserListUiState.emit(UiState.Success(nextRandomUsers))
Comment on lines +60 to +66
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 이 코드는 어떤 의미일까요?
온보딩 기준으로 유저가 없을 경우를 대비 하신 걸까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞습니다. 기존에 콕지르기를 다한경우, 리스트에 값이 안들어와서 앱이 크래시되는 현상을 수정했습니다

}
.onApiError { statusCode, responseMessage ->
_onboardingPokeUserListUiState.emit(UiState.ApiError(statusCode, responseMessage))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sealed class PokeUserViewHolder(
binding.apply {
imageViewFriendRelationOutline.setRelationStrokeColor(pokeUser.relationName)
if (pokeUser.isAnonymous) {
imageViewProfile.load(pokeUser.anonymousImage) {
imageViewProfile.load(R.drawable.image_anonymous_profile) {
crossfade(true)
transformations(CircleCropTransformation())
}
Expand All @@ -74,20 +74,27 @@ sealed class PokeUserViewHolder(
) : PokeUserViewHolder(binding) {
override fun onBind(pokeUser: PokeUser) {
binding.apply {
when (pokeUser.profileImage.isBlank()) {
true ->
when {
pokeUser.isAnonymous ->
imageViewProfile.load(R.drawable.image_anonymous_profile) {
crossfade(true)
transformations(CircleCropTransformation())
}

pokeUser.profileImage.isBlank() ->
imageViewProfile.load(null) {
crossfade(true)
transformations(CircleCropTransformation())
}

false ->
else ->
imageViewProfile.load(pokeUser.profileImage) {
crossfade(true)
transformations(CircleCropTransformation())
}
}
textViewUserName.text = pokeUser.name
textViewUserName.text = if (pokeUser.isAnonymous) pokeUser.anonymousName else pokeUser.name
textViewUserInfo.isVisible = !pokeUser.isAnonymous
textViewUserInfo.text = binding.root.context.getString(R.string.poke_user_info, pokeUser.generation, pokeUser.part)
imageButtonPoke.isEnabled = !pokeUser.isAlreadyPoke
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading