From 2d2fb396288be6721a64b5066d1b6fea1b05b7f6 Mon Sep 17 00:00:00 2001 From: crownjoe Date: Mon, 15 Jan 2024 06:15:49 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT/#114]=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=B7=B0=20=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../data/dto/interceptor/AuthInterceptor.kt | 3 ++ .../presentation/setting/SettingActivity.kt | 7 +++ .../tripdashboard/profile/ProfileActivity.kt | 44 ++++++++++++++++--- .../tripdashboard/profile/ProfileViewModel.kt | 35 ++++++++++++++- 5 files changed, 82 insertions(+), 9 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a68ae8e3..cd729c62 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -97,7 +97,7 @@ (R.layout.activity_setting) { + private val profileViewModel by viewModels() private var quitDialog: SettingQuitDialogFragment? = null private var logoutDialog: SettingLogoutDialogFragment? = null @@ -37,6 +41,9 @@ class SettingActivity : BaseActivity(R.layout.activity_s private fun initProfileClickListener() { binding.btnSettingProfile.setOnSingleClickListener { + Intent(this, ProfileActivity::class.java).apply { + startActivity(this) + } } } diff --git a/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileActivity.kt b/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileActivity.kt index b3a67bfd..b01db445 100644 --- a/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileActivity.kt +++ b/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileActivity.kt @@ -5,10 +5,18 @@ import android.text.SpannableString import android.text.Spanned import android.text.style.BulletSpan import androidx.activity.viewModels +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope import com.going.presentation.R import com.going.presentation.databinding.ActivityProfileBinding import com.going.ui.base.BaseActivity +import com.going.ui.extension.UiState +import com.going.ui.extension.toast +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +@AndroidEntryPoint class ProfileActivity : BaseActivity(R.layout.activity_profile) { private val profileViewModel by viewModels() @@ -16,18 +24,42 @@ class ProfileActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - bindProfileInfo() + getUserInfo() + observeUserInfoState() } - private fun bindProfileInfo() { + private fun getUserInfo() { + profileViewModel.getUserInfoState() + } + + private fun observeUserInfoState() { + profileViewModel.userInfoState.flowWithLifecycle(lifecycle).onEach { state -> + when (state) { + is UiState.Loading -> return@onEach + is UiState.Success -> bindProfileInfo( + state.data.name, + state.data.intro, + state.data.result + ) + + is UiState.Failure -> toast(state.msg) + is UiState.Empty -> return@onEach + } + }.launchIn(lifecycleScope) + } + + private fun bindProfileInfo(name: String, intro: String, number: Int) { with(binding) { - profileViewModel.mockProfileResult.apply { + tvProfileName.text = name + tvProfileOneLine.text = intro + profileViewModel.mockProfileResult[number].apply { + ivProfile.setImageResource(resultImage) tvProfileType.text = profileTitle tvProfileSubType.text = profileSubTitle - tvProfileTag1.text = tags[0] - tvProfileTag2.text = tags[1] - tvProfileTag3.text = tags[2] + tvProfileTag1.text = getString(R.string.tag, tags[0]) + tvProfileTag2.text = getString(R.string.tag, tags[1]) + tvProfileTag3.text = getString(R.string.tag, tags[2]) tvFirstDescriptionTitle.text = profileBoxInfo[0].title tvFirstDescriptionFirstText.text = diff --git a/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileViewModel.kt b/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileViewModel.kt index 42ce38a2..a5a7820f 100644 --- a/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/tripdashboard/profile/ProfileViewModel.kt @@ -1,11 +1,42 @@ package com.going.presentation.tripdashboard.profile +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.going.domain.entity.ProfileMock +import com.going.domain.entity.request.UserProfileRequestModel +import com.going.domain.repository.ProfileRepository import com.going.presentation.R +import com.going.ui.extension.UiState +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject -class ProfileViewModel : ViewModel() { - val mockTendencyResult: List = listOf( +@HiltViewModel +class ProfileViewModel @Inject constructor( + private val profileRepository: ProfileRepository, +) : ViewModel() { + + private val _userInfoState = MutableStateFlow>(UiState.Empty) + val userInfoState: StateFlow> = _userInfoState + + val profileId = MutableLiveData(0) + + fun getUserInfoState() { + viewModelScope.launch { + _userInfoState.value = UiState.Loading + profileRepository.getUserProfile().onSuccess { + profileId.value = it.result + _userInfoState.value = UiState.Success(it) + }.onFailure { + _userInfoState.value = UiState.Failure(it.message.toString()) + } + } + } + + val mockProfileResult: List = listOf( ProfileMock( resultImage = R.drawable.img_tendency_result_srp, profileTitle = "배려심 넘치는 든든잉",