Skip to content

Commit

Permalink
feat #725: 변수 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Jun 8, 2024
1 parent 7a1564a commit 6010b94
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import coil.load
import coil.transform.CircleCropTransformation
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.User
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand Down Expand Up @@ -215,22 +214,18 @@ class PokeMainActivity : AppCompatActivity() {
}
.launchIn(lifecycleScope)

viewModel.apply {
pokeFriendOfFriendUiState
.onEach {
when (it) {
is UiState.Loading -> "Loading"
is UiState.Success<List<PokeRandomUserList.PokeRandomUsers>> -> {
pokeMainListAdapter?.submitList(it.data)
binding.refreshLayoutPokeMain.isRefreshing = false
}

is UiState.ApiError -> showPokeToast(getString(R.string.toast_poke_error))
is UiState.Failure -> showPokeToast(it.throwable.message ?: getString(R.string.toast_poke_error))
}
viewModel.pokeSimilarFriendUiState.onEach {
when (it) {
is UiState.Loading -> "Loading"
is UiState.Success<List<PokeRandomUserList.PokeRandomUsers>> -> {
pokeMainListAdapter?.submitList(it.data)
binding.refreshLayoutPokeMain.isRefreshing = false
}
.launchIn(lifecycleScope)
}

is UiState.ApiError -> showPokeToast(getString(R.string.toast_poke_error))
is UiState.Failure -> showPokeToast(it.throwable.message ?: getString(R.string.toast_poke_error))
}
}.launchIn(lifecycleScope)

viewModel.pokeUserUiState
.onEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ class PokeMainListAdapter(
ItemDiffCallback(
onItemsTheSame = { old, new -> old == new },
onContentsTheSame = { old, new ->
old.userInfoList[0].userId == new.userInfoList[0].userId &&
old.userInfoList[0].name == new.userInfoList[0].name &&
old.userInfoList[0].profileImage == new.userInfoList[0].profileImage &&
old.userInfoList[0].generation == new.userInfoList[0].generation
old.userInfoList == new.userInfoList
},
),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ class PokeMainViewHolder(
textViewUserName.text = user.name
textViewUserInfo.text = root.context.getString(R.string.poke_user_info, user.generation, user.part)

imageViewProfile.setOnClickListener {
clickListener.onClickProfileImage(user.playgroundId)
}
imageButtonPoke.isEnabled = !user.isAlreadyPoke
imageButtonPoke.setOnClickListener {
if (user.isAlreadyPoke) return@setOnClickListener
clickListener.onClickPokeButton(user)
}
imageViewProfile.setOnClickListener {
clickListener.onClickProfileImage(user.playgroundId)
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package org.sopt.official.feature.poke.main

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -57,8 +56,8 @@ class PokeMainViewModel @Inject constructor(
private val _pokeFriendUiState = MutableStateFlow<UiState<PokeUser>>(UiState.Loading)
val pokeFriendUiState: StateFlow<UiState<PokeUser>> get() = _pokeFriendUiState

private val _pokeFriendOfFriendUiState = MutableStateFlow<UiState<List<PokeRandomUserList.PokeRandomUsers>>>(UiState.Loading)
val pokeFriendOfFriendUiState: StateFlow<UiState<List<PokeRandomUserList.PokeRandomUsers>>> get() = _pokeFriendOfFriendUiState
private val _pokeSimilarFriendUiState = MutableStateFlow<UiState<List<PokeRandomUserList.PokeRandomUsers>>>(UiState.Loading)
val pokeSimilarFriendUiState: StateFlow<UiState<List<PokeRandomUserList.PokeRandomUsers>>> get() = _pokeSimilarFriendUiState

private val _pokeUserUiState = MutableStateFlow<UiState<PokeUser>>(UiState.Loading)
val pokeUserUiState: StateFlow<UiState<PokeUser>> get() = _pokeUserUiState
Expand Down Expand Up @@ -103,16 +102,16 @@ class PokeMainViewModel @Inject constructor(

fun getPokeSimilarFriends() {
viewModelScope.launch {
_pokeFriendOfFriendUiState.emit(UiState.Loading)
_pokeSimilarFriendUiState.emit(UiState.Loading)
getOnboardingPokeUserListUseCase.invoke(randomType = "ALL", size = 2)
.onSuccess {
_pokeFriendOfFriendUiState.emit(UiState.Success(it.randomInfoList))
_pokeSimilarFriendUiState.emit(UiState.Success(it.randomInfoList))
}
.onApiError { statusCode, responseMessage ->
_pokeFriendOfFriendUiState.emit(UiState.ApiError(statusCode, responseMessage))
_pokeSimilarFriendUiState.emit(UiState.ApiError(statusCode, responseMessage))
}
.onFailure {
_pokeFriendOfFriendUiState.emit(UiState.Failure(it))
_pokeSimilarFriendUiState.emit(UiState.Failure(it))
Timber.e(it)
}
}
Expand Down Expand Up @@ -162,13 +161,13 @@ class PokeMainViewModel @Inject constructor(
)
}
}
if (_pokeFriendOfFriendUiState.value is UiState.Success<List<PokeRandomUserList.PokeRandomUsers>>) {
val oldData = (_pokeFriendOfFriendUiState.value as UiState.Success<List<PokeRandomUserList.PokeRandomUsers>>).data
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
}
_pokeFriendOfFriendUiState.emit(UiState.Loading)
_pokeFriendOfFriendUiState.emit(UiState.Success(oldData))
_pokeSimilarFriendUiState.emit(UiState.Loading)
_pokeSimilarFriendUiState.emit(UiState.Success(oldData))
}
}
}
Expand Down

0 comments on commit 6010b94

Please sign in to comment.