Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#372] Profile / 프로필 배너 설정 #375

Merged
merged 7 commits into from
Feb 7, 2024
Merged
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
@@ -1,7 +1,6 @@
package com.el.yello.presentation.main.profile

import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -12,7 +11,9 @@ import com.example.domain.entity.PayInfoModel
import com.example.domain.entity.ProfileFriendsListModel
import com.example.domain.entity.ProfileQuitReasonModel
import com.example.domain.entity.ProfileUserModel
import com.example.domain.entity.notice.ProfileBanner
import com.example.domain.repository.AuthRepository
import com.example.domain.repository.NoticeRepository
import com.example.domain.repository.PayRepository
import com.example.domain.repository.ProfileRepository
import com.example.ui.view.UiState
Expand All @@ -32,6 +33,7 @@ class ProfileViewModel @Inject constructor(
private val profileRepository: ProfileRepository,
private val authRepository: AuthRepository,
private val payRepository: PayRepository,
private val noticeRepository: NoticeRepository
) : ViewModel() {

init {
Expand All @@ -41,7 +43,8 @@ class ProfileViewModel @Inject constructor(
private val _getUserDataResult = MutableSharedFlow<Boolean>()
val getUserDataResult: SharedFlow<Boolean> = _getUserDataResult

private val _getFriendListState = MutableStateFlow<UiState<ProfileFriendsListModel>>(UiState.Empty)
private val _getFriendListState =
MutableStateFlow<UiState<ProfileFriendsListModel>>(UiState.Empty)
val getFriendListState: StateFlow<UiState<ProfileFriendsListModel>> = _getFriendListState

private val _deleteUserState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
Expand Down Expand Up @@ -79,12 +82,20 @@ class ProfileViewModel @Inject constructor(
val etcText = MutableLiveData("")
private val _quitReasonData: MutableLiveData<List<String>> = MutableLiveData()
val quitReasonData: LiveData<List<String>> = _quitReasonData

private val _getBannerResult = MutableSharedFlow<Boolean>()
val getBannerResult: SharedFlow<Boolean> = _getBannerResult

var profileBanner = ProfileBanner()

fun setEtcText(etc: String) {
etcText.value = etc
}

fun setQuitReason(reason: String) {
quitReasonText.value = reason
}

fun addQuitReasonList(context: Context) {
val quitReasonArray = context.resources.getStringArray(R.array.quit_reasons)
_quitReasonData.value = quitReasonArray.toList()
Expand Down Expand Up @@ -112,6 +123,7 @@ class ProfileViewModel @Inject constructor(
_getFriendListState.value = UiState.Empty
_getPurchaseInfoState.value = UiState.Empty
_getUserDataResult.resetReplayCache()
_getBannerResult.resetReplayCache()
}

fun getUserDataFromServer() {
Expand Down Expand Up @@ -229,6 +241,19 @@ class ProfileViewModel @Inject constructor(
}
}

fun getProfileBannerFromServer() {
viewModelScope.launch {
noticeRepository.getProfileBanner()
.onSuccess { banner ->
profileBanner = banner ?: return@launch
_getBannerResult.emit(true)
}
.onFailure {
_getBannerResult.emit(false)
}
}
}

private fun clearLocalInfo() {
authRepository.clearLocalPref()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.el.yello.presentation.main.profile.info

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.animation.AnimationUtils
Expand Down Expand Up @@ -60,6 +62,7 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
observeFriendsDataState()
observeFriendDeleteState()
observeCheckIsSubscribed()
observeGetBannerState()
AmplitudeUtils.trackEventWithProperties("view_profile")
}

Expand Down Expand Up @@ -113,6 +116,7 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
},
shopClick = { initShopClickListener() },
modClick = { initProfileModClickListener() },
bannerClick = { redirectUrl -> initProfileBannerClickListener(redirectUrl) }
)
binding.rvProfileFriendsList.adapter = adapter
}
Expand Down Expand Up @@ -143,6 +147,10 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
viewModel.resetStateVariable()
}

private fun initProfileBannerClickListener(redirectUrl: String) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(redirectUrl)))
}

private fun initPullToScrollListener() {
binding.layoutProfileSwipe.apply {
setOnRefreshListener {
Expand All @@ -163,7 +171,7 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
resetStateVariable()
getPurchaseInfoFromServer()
getUserDataFromServer()
getFriendsListFromServer()
getProfileBannerFromServer()
}
}

Expand Down Expand Up @@ -259,6 +267,15 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
}.launchIn(lifecycleScope)
}

private fun observeGetBannerState() {
viewModel.getBannerResult.flowWithLifecycle(lifecycle).onEach { result ->
if (!result) {
yelloSnackbar(binding.root, getString(R.string.my_yello_get_banner_failure))
}
viewModel.getFriendsListFromServer()
}.launchIn(lifecycleScope)
}

private fun setDeleteAnimation() {
binding.rvProfileFriendsList.itemAnimator = object : DefaultItemAnimator() {
override fun animateRemove(holder: RecyclerView.ViewHolder): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProfileFriendAdapter(
private val itemClick: (ProfileUserModel, Int) -> (Unit),
private val shopClick: (Unit) -> (Unit),
private val modClick: (Unit) -> (Unit),
private val bannerClick: (String) -> (Unit),
) : ListAdapter<ProfileUserModel, RecyclerView.ViewHolder>(diffUtil) {

private var itemList = mutableListOf<ProfileUserModel>()
Expand All @@ -27,7 +28,8 @@ class ProfileFriendAdapter(
VIEW_TYPE_USER_INFO -> ProfileUserInfoViewHolder(
ItemProfileUserInfoBinding.inflate(inflater, parent, false),
shopClick,
modClick
modClick,
bannerClick
)

VIEW_TYPE_FRIENDS_LIST -> ProfileListInfoViewHolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package com.el.yello.presentation.main.profile.info

import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.el.yello.databinding.ItemProfileUserInfoBinding
import com.el.yello.presentation.main.profile.ProfileViewModel
import com.el.yello.util.Utils.setImageOrBasicThumbnail
import com.example.ui.view.setOnSingleClickListener

class ProfileUserInfoViewHolder(
val binding: ItemProfileUserInfoBinding,
val shopClick: (Unit) -> (Unit),
val modClick: (Unit) -> (Unit),
private val shopClick: (Unit) -> (Unit),
private val modClick: (Unit) -> (Unit),
private val bannerClick: (String) -> (Unit)
) : RecyclerView.ViewHolder(binding.root) {

fun onBind(viewModel: ProfileViewModel) {
Expand All @@ -25,6 +27,13 @@ class ProfileUserInfoViewHolder(
btnPrifileMod.setOnSingleClickListener { modClick(Unit) }

ivProfileInfoThumbnail.setImageOrBasicThumbnail(viewModel.myUserData.profileImageUrl)

ivProfileBanner.isVisible = viewModel.profileBanner.isAvailable
}

if (viewModel.profileBanner.isAvailable) {
binding.ivProfileBanner.load(viewModel.profileBanner.imageUrl)
binding.ivProfileBanner.setOnSingleClickListener { bannerClick(viewModel.profileBanner.redirectUrl) }
Copy link
Contributor

Choose a reason for hiding this comment

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

coil 사용 좋네요 ~~~!

}
}
}
20 changes: 17 additions & 3 deletions app/src/main/res/layout/item_profile_user_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,31 @@

</LinearLayout>

<ImageView
android:id="@+id/iv_profile_banner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
Copy link
Contributor

Choose a reason for hiding this comment

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

오 이거 이미지 비율 맞추는 거군요 ~~!

android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_profile_shop"
tools:src="@drawable/ic_pay_under_first"
tools:visibility="visible" />

<TextView
android:id="@+id/tv_profile_friend_list_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="40dp"
android:layout_marginTop="14dp"
android:text="@string/profile_user_info_friends_list_title"
android:textAppearance="?textAppearanceSubtitle2"
android:textColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_profile_shop" />
app:layout_constraintTop_toBottomOf="@id/iv_profile_banner" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
Expand All @@ -337,8 +351,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:fontFamily="@font/pretendard_bold"
android:text="@{@string/to_string(vm.myFriendCount)}"
android:textColor="@color/white"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface NoticeDataSource {
suspend fun getNotice(): BaseResponse<ResponseGetNotice>

suspend fun getBanner(): BaseResponse<ResponseGetNotice>

suspend fun getProfileBanner(): BaseResponse<ResponseGetNotice>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ class NoticeDataSourceImpl @Inject constructor(
override suspend fun getBanner(): BaseResponse<ResponseGetNotice> =
service.getNotice(TAG_BANNER)

override suspend fun getProfileBanner(): BaseResponse<ResponseGetNotice> =
service.getNotice(TAG_PROFILE_BANNER)

companion object {
private const val TAG_NOTICE = "NOTICE"
private const val TAG_BANNER = "BANNER"
private const val TAG_PROFILE_BANNER = "PROFILE-BANNER"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.data.model.response.notice

import com.example.domain.entity.notice.Banner
import com.example.domain.entity.notice.Notice
import com.example.domain.entity.notice.ProfileBanner
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -33,4 +34,10 @@ data class ResponseGetNotice(
redirectUrl = redirectUrl,
isAvailable = isAvailable,
)

fun toProfileBanner() : ProfileBanner = ProfileBanner(
imageUrl = imageUrl,
redirectUrl = redirectUrl,
isAvailable = isAvailable
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.example.data.datasource.NoticeDataSource
import com.example.domain.YelloDataStore
import com.example.domain.entity.notice.Banner
import com.example.domain.entity.notice.Notice
import com.example.domain.entity.notice.ProfileBanner
import com.example.domain.repository.NoticeRepository
import javax.inject.Inject

Expand All @@ -15,10 +16,14 @@ class NoticeRepositoryImpl @Inject constructor(
dataSource.getNotice().data?.toNotice()
}

override suspend fun getBanner(): Result<Banner?> = kotlin.runCatching {
override suspend fun getBanner(): Result<Banner?> = runCatching {
dataSource.getBanner().data?.toBanner()
}

override suspend fun getProfileBanner(): Result<ProfileBanner?> = runCatching {
dataSource.getProfileBanner().data?.toProfileBanner()
}

override fun isDisabledNoticeUrl(url: String): Boolean =
yelloDataStore.disabledNoticeUrl == url

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.domain.entity.notice

data class ProfileBanner(
val imageUrl: String,
val redirectUrl: String,
val isAvailable: Boolean,
) {
constructor() : this("","",false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.example.domain.repository

import com.example.domain.entity.notice.Banner
import com.example.domain.entity.notice.Notice
import com.example.domain.entity.notice.ProfileBanner

interface NoticeRepository {
suspend fun getNotice(): Result<Notice?>

suspend fun getBanner(): Result<Banner?>

suspend fun getProfileBanner(): Result<ProfileBanner?>

fun isDisabledNoticeUrl(url: String): Boolean

fun setDisabledNoticeUrl(url: String)
Expand Down
Loading