Skip to content

Commit

Permalink
Merge pull request #347 from team-yello/feat/#344-recommend-profile
Browse files Browse the repository at this point in the history
[FEAT/#344] 추천 친구뷰 / 프로필 추가
  • Loading branch information
minju1459 authored Jan 24, 2024
2 parents a7a4650 + 448e768 commit c4e6972
Show file tree
Hide file tree
Showing 36 changed files with 860 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProfileViewModel @Inject constructor(
private val profileRepository: ProfileRepository,
private val authRepository: AuthRepository,
private val yelloRepository: YelloRepository,
private val payRepository: PayRepository
private val payRepository: PayRepository,
) : ViewModel() {

private val _getUserDataState = MutableStateFlow<UiState<ProfileUserModel>>(UiState.Empty)
Expand Down Expand Up @@ -158,7 +158,7 @@ class ProfileViewModel @Inject constructor(
}

// 서버 통신 - 친구 식제
fun deleteFriendDataToServer(friendId: Int) {
fun deleteFriendDataToServer(friendId: Long) {
viewModelScope.launch {
_deleteFriendState.value = UiState.Loading
profileRepository.deleteFriendData(friendId)
Expand Down Expand Up @@ -211,7 +211,6 @@ class ProfileViewModel @Inject constructor(
_getPurchaseInfoState.value = UiState.Failure(it.message.toString())
}
}

}

fun getVoteCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
if (!viewModel.isItemBottomSheetRunning) {
AmplitudeUtils.trackEventWithProperties("click_profile_friend")
ProfileFriendItemBottomSheet().show(
parentFragmentManager, ITEM_BOTTOM_SHEET
parentFragmentManager,
ITEM_BOTTOM_SHEET,
)
}
}, {
Expand All @@ -127,7 +128,8 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
}, {
// 헤더 상점 버튼 클릭 리스너 설정
AmplitudeUtils.trackEventWithProperties(
"click_go_shop", JSONObject().put("shop_button", "profile_shop")
"click_go_shop",
JSONObject().put("shop_button", "profile_shop"),
)
Intent(activity, PayActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProfileFriendAdapter(
private val viewModel: ProfileViewModel,
private val itemClick: (ProfileUserModel, Int) -> (Unit),
private val buttonClick: (ProfileViewModel) -> (Unit),
private val shopClick: (ProfileViewModel) -> (Unit)
private val shopClick: (ProfileViewModel) -> (Unit),
) : ListAdapter<ProfileUserModel, RecyclerView.ViewHolder>(diffUtil) {

private var itemList = mutableListOf<ProfileUserModel>()
Expand All @@ -30,7 +30,7 @@ class ProfileFriendAdapter(
false,
),
buttonClick,
shopClick
shopClick,
)

VIEW_TYPE_FRIENDS_LIST -> ProfileFriendsListViewHolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class ProfileFriendDeleteBottomSheet :
toast(
getString(
R.string.profile_delete_bottom_sheet_toast,
viewModel.clickedUserData.name
)
viewModel.clickedUserData.name,
),
)
viewModel.setDeleteFriendStateEmpty()
this@ProfileFriendDeleteBottomSheet.dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.example.ui.view.setOnSingleClickListener
class ProfileUserInfoViewHolder(
val binding: ItemProfileUserInfoBinding,
val buttonClick: (ProfileViewModel) -> (Unit),
val shopClick: (ProfileViewModel) -> (Unit)
val shopClick: (ProfileViewModel) -> (Unit),
) : RecyclerView.ViewHolder(binding.root) {

fun onBind(viewModel: ProfileViewModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class ProfileManageActivity :
private fun initQuitBtnListener() {
binding.btnProfileManageQuit.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties(
"click_profile_withdrawal", JSONObject().put("withdrawal_button", "withdrawal1")
"click_profile_withdrawal",
JSONObject().put("withdrawal_button", "withdrawal1"),
)
Intent(this, ProfileQuitOneActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class ProfileQuitDialog :
private fun initQuitBtnListener() {
binding.btnProfileDialogQuit.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties(
"click_profile_withdrawal", JSONObject().put("withdrawal_button", "withdrawal4")
"click_profile_withdrawal",
JSONObject().put("withdrawal_button", "withdrawal4"),
)
viewModel.deleteUserDataToServer()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ProfileQuitOneActivity :
private fun initQuitBtnListener() {
binding.btnProfileQuitResume.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties(
"click_profile_withdrawal", JSONObject().put("withdrawal_button", "withdrawal2")
"click_profile_withdrawal",
JSONObject().put("withdrawal_button", "withdrawal2"),
)
Intent(this, ProfileQuitTwoActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ProfileQuitTwoActivity :
private fun initInviteDialogBtnListener() {
binding.btnProfileQuitForSure.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties(
"click_profile_withdrawal", JSONObject().put("withdrawal_button", "withdrawal3")
"click_profile_withdrawal",
JSONObject().put("withdrawal_button", "withdrawal3"),
)
profileQuitDialog = ProfileQuitDialog()
profileQuitDialog?.show(supportFragmentManager, QUIT_DIALOG)
Expand All @@ -44,4 +45,4 @@ class ProfileQuitTwoActivity :
private companion object {
const val QUIT_DIALOG = "quitDialog"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class RecommendFragment : BindingFragment<FragmentRecommendBinding>(R.layout.fra

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initViewModelProvider()
initSearchBtnListener()
setTabLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
import com.el.yello.presentation.main.recommend.list.RecommendViewHolder
import com.example.domain.entity.RecommendListModel
import com.example.domain.entity.RecommendRequestModel
import com.example.domain.entity.RecommendUserInfoModel
import com.example.domain.repository.AuthRepository
import com.example.domain.repository.RecommendRepository
import com.example.ui.view.UiState
Expand All @@ -13,6 +14,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import retrofit2.HttpException
import javax.inject.Inject
import kotlin.math.ceil

Expand All @@ -31,10 +33,14 @@ class RecommendKakaoViewModel @Inject constructor(
private val _addFriendState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
val addFriendState: StateFlow<UiState<Unit>> = _addFriendState

private val _getUserDataState = MutableStateFlow<UiState<RecommendUserInfoModel>>(UiState.Empty)
val getUserDataState: StateFlow<UiState<RecommendUserInfoModel>> = _getUserDataState

var isSearchViewShowed = false

var itemPosition: Int? = null
var itemHolder: RecommendViewHolder? = null
var clickedUserData = RecommendUserInfoModel(0, "", "", "", "", 0, 0)

private var currentOffset = -100
private var currentPage = -1
Expand Down Expand Up @@ -78,7 +84,7 @@ class RecommendKakaoViewModel @Inject constructor(
totalPage = ceil((friends.totalCount * 0.01)).toInt() - 1
if (totalPage == currentPage) isPagingFinish = true
getListFromServer(
friends.elements?.map { friend -> friend.id.toString() } ?: listOf()
friends.elements?.map { friend -> friend.id.toString() } ?: listOf(),
)
}
}
Expand Down Expand Up @@ -115,5 +121,25 @@ class RecommendKakaoViewModel @Inject constructor(
}
}

// 서버 통신 - 특정 유저 정보 받아오기
fun getUserDataFromServer(userId: Long) {
viewModelScope.launch {
_getUserDataState.value = UiState.Loading
recommendRepository.getRecommendUserInfo(userId)
.onSuccess { userInfo ->
if (userInfo == null) {
_getUserDataState.value = UiState.Empty
return@launch
}
_getUserDataState.value = UiState.Success(userInfo)
}
.onFailure { t ->
if (t is HttpException) {
_getUserDataState.value = UiState.Failure(t.message.toString())
}
}
}
}

fun getYelloId() = authRepository.getYelloId()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.el.yello.presentation.main.recommend.kakao

import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import coil.load
import coil.transform.CircleCropTransformation
import com.el.yello.R
import com.el.yello.databinding.FragmentRecommendKakaoItemBottomSheetBinding
import com.el.yello.presentation.main.profile.ProfileViewModel
import com.example.ui.base.BindingBottomSheetDialog
import com.example.ui.view.setOnSingleClickListener
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class RecommendKakaoBottomSheet :
BindingBottomSheetDialog<FragmentRecommendKakaoItemBottomSheetBinding>(R.layout.fragment_recommend_kakao_item_bottom_sheet) {

private val viewModel by activityViewModels<RecommendKakaoViewModel>()

override fun onStart() {
super.onStart()
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.vm = viewModel
setItemImage()
initAddBtnListener()
}

private fun setItemImage() {
if (viewModel.clickedUserData.profileImageUrl == ProfileViewModel.BASIC_THUMBNAIL) {
binding.ivRecommendFriendThumbnail.load(R.drawable.img_yello_basic)
} else {
binding.ivRecommendFriendThumbnail.load(viewModel.clickedUserData.profileImageUrl) {
transformations(CircleCropTransformation())
}
}
}

private fun initAddBtnListener() {
binding.btnRecommendFriendAdd.setOnSingleClickListener {
binding.btnRecommendFriendAdd.visibility = View.INVISIBLE
binding.btnRecommendItemAddPressed.visibility = View.VISIBLE
lifecycleScope.launch {
viewModel.addFriendToServer(viewModel.clickedUserData.userId)
delay(300)
dismiss()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.el.yello.presentation.util.BaseLinearRcvItemDeco
import com.el.yello.util.Utils.setPullToScrollColor
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
import com.example.domain.entity.RecommendListModel
import com.example.ui.base.BindingFragment
import com.example.ui.view.UiState
import com.example.ui.view.setOnSingleClickListener
Expand All @@ -43,6 +44,7 @@ class RecommendKakaoFragment :

private var inviteYesFriendDialog: InviteFriendDialog? = null
private var inviteNoFriendDialog: InviteFriendDialog? = null
private var lastClickedRecommendModel: RecommendListModel.RecommendFriend? = null

private lateinit var itemDivider: RecommendItemDecoration

Expand All @@ -54,9 +56,10 @@ class RecommendKakaoFragment :
initPullToScrollListener()
setKakaoRecommendList()
setAdapterWithClickListener()
observeKakaoError()
observeUserDataState()
observeAddListState()
observeAddFriendState()
observeKakaoError()
setItemDecoration()
setInfinityScroll()
setDeleteAnimation()
Expand Down Expand Up @@ -146,10 +149,18 @@ class RecommendKakaoFragment :

// 어댑터 클릭 리스너 설정
private fun setAdapterWithClickListener() {
_adapter = RecommendAdapter { recommendModel, position, holder ->
viewModel.setPositionAndHolder(position, holder)
viewModel.addFriendToServer(recommendModel.id.toLong())
}
_adapter = RecommendAdapter(
buttonClick = { recommendModel, position, holder ->
viewModel.setPositionAndHolder(position, holder)
viewModel.addFriendToServer(recommendModel.id.toLong())
},

itemClick = { recommendModel, position, holder ->
viewModel.setPositionAndHolder(position, holder)
viewModel.getUserDataFromServer(recommendModel.id.toLong())
lastClickedRecommendModel = recommendModel
},
)
binding.rvRecommendKakao.adapter = adapter
}

Expand Down Expand Up @@ -226,7 +237,31 @@ class RecommendKakaoFragment :
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}
private fun observeUserDataState() {
viewModel.getUserDataState.flowWithLifecycle(viewLifecycleOwner.lifecycle).onEach { state ->
when (state) {
is UiState.Success -> {
viewModel.clickedUserData = state.data.apply {
if (!this.yelloId.startsWith("@")) this.yelloId = "@" + this.yelloId
}
if (lastClickedRecommendModel != null) {
RecommendKakaoBottomSheet().show(
parentFragmentManager,
ITEM_BOTTOM_SHEET,
)
}
}

is UiState.Failure -> {
yelloSnackbar(requireView(), getString(R.string.profile_error_user_data))
}

is UiState.Empty -> return@onEach

is UiState.Loading -> return@onEach
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}
private fun setDeleteAnimation() {
binding.rvRecommendKakao.itemAnimator = object : DefaultItemAnimator() {
override fun animateRemove(holder: RecyclerView.ViewHolder): Boolean {
Expand Down Expand Up @@ -310,8 +345,8 @@ class RecommendKakaoFragment :

private companion object {
const val INVITE_DIALOG = "inviteDialog"

const val KAKAO_NO_FRIEND = "recommend_kakao_nofriend"
const val KAKAO_YES_FRIEND = "recommend_kakao_yesfriend"
const val ITEM_BOTTOM_SHEET = "itemBottomSheet"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.el.yello.databinding.ItemRecommendListBinding
import com.example.domain.entity.RecommendListModel.RecommendFriend

class RecommendAdapter(
private val buttonClick: (RecommendFriend, Int, RecommendViewHolder) -> (Unit),
private val itemClick: (RecommendFriend, Int, RecommendViewHolder) -> (Unit),
) : RecyclerView.Adapter<RecommendViewHolder>() {

Expand All @@ -17,7 +18,7 @@ class RecommendAdapter(
val inflater by lazy { LayoutInflater.from(parent.context) }
val binding: ItemRecommendListBinding =
ItemRecommendListBinding.inflate(inflater, parent, false)
return RecommendViewHolder(binding, itemClick)
return RecommendViewHolder(binding, buttonClick, itemClick)
}

override fun onBindViewHolder(holder: RecommendViewHolder, position: Int) {
Expand Down
Loading

0 comments on commit c4e6972

Please sign in to comment.