From 7e4b4642daf5480321a5f352e7bff84f26338997 Mon Sep 17 00:00:00 2001 From: sangwook Date: Thu, 7 Nov 2024 00:57:05 +0900 Subject: [PATCH] [mod] #187 setting view --- .../sopt/mypage/settings/SettingsFragment.kt | 26 +++ .../sopt/mypage/settings/SettingsViewModel.kt | 13 ++ .../src/main/res/layout/fragment_settings.xml | 190 ++++++++++++++---- 3 files changed, 192 insertions(+), 37 deletions(-) diff --git a/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt b/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt index bf0ccaf9..7bcb2606 100644 --- a/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt +++ b/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsFragment.kt @@ -12,6 +12,8 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.lifecycle.flowWithLifecycle import androidx.navigation.fragment.findNavController +import coil.load +import coil.transform.CircleCropTransformation import dagger.hilt.android.AndroidEntryPoint import designsystem.components.dialog.LinkMindDialog import kotlinx.coroutines.flow.launchIn @@ -19,6 +21,7 @@ import kotlinx.coroutines.flow.onEach import org.sopt.common.intentprovider.IntentProvider import org.sopt.common.intentprovider.LOGIN import org.sopt.datastore.datastore.SecurityDataStore +import org.sopt.model.user.MyPageData import org.sopt.model.user.SettingPageData import org.sopt.mypage.R import org.sopt.mypage.databinding.FragmentSettingsBinding @@ -122,6 +125,16 @@ class SettingsFragment : Fragment() { } }.launchIn(viewLifeCycleScope) + viewModel.getUserMyPage() + viewModel.myPageState.flowWithLifecycle(viewLifeCycle).onEach { state -> + when (state) { + is UiState.Success -> { + initMyPageData(state.data) + } + else -> {} + } + }.launchIn(viewLifeCycleScope) + onClickToggle() onClickLogoutBtn() onClickCloseBtn() @@ -201,6 +214,19 @@ class SettingsFragment : Fragment() { } } + private fun initMyPageData(data: MyPageData) { + val myPage = data + if (myPage != null) { + with(binding) { + tvUserName.text = myPage.nickname + tvMyTotalLinkNum.text = myPage.allReadToast.toString() + tvReadLinkThisWeekNum.text = myPage.thisWeekendRead.toString() + tvSaveLinkThisWeekNum.text = myPage.thisWeekendSaved.toString() + ivProfile.load(data.profile) { transformations(CircleCropTransformation()) } + } + } + } + companion object { const val URL_1ON1 = "https://open.kakao.com/o/sfN9Fr4f" const val URL_RULE = "https://www.notion.so/db429c114629431f8301a969ed028e37" diff --git a/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsViewModel.kt b/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsViewModel.kt index 849acdd9..18a3b834 100644 --- a/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsViewModel.kt +++ b/feature/mypage/src/main/java/org/sopt/mypage/settings/SettingsViewModel.kt @@ -9,8 +9,10 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import org.sopt.auth.repository.AuthRepository +import org.sopt.model.user.MyPageData import org.sopt.model.user.SettingPageData import org.sopt.ui.view.UiState +import org.sopt.user.usecase.GetUserMyPageUseCase import org.sopt.user.usecase.GetUserSettingUseCase import org.sopt.user.usecase.PatchPushUseCase import javax.inject.Inject @@ -19,6 +21,7 @@ import javax.inject.Inject class SettingsViewModel @Inject constructor( private val getUserSettingUseCase: GetUserSettingUseCase, private val patchPushUseCase: PatchPushUseCase, + private val getUserMyPageUseCase: GetUserMyPageUseCase, private val authRepository: AuthRepository, ) : ViewModel() { private val _logoutState = MutableStateFlow>(UiState.Empty) @@ -30,6 +33,16 @@ class SettingsViewModel @Inject constructor( private val _settingState = MutableStateFlow>(UiState.Empty) val settingState: StateFlow> = _settingState.asStateFlow() + private val _myPageState = MutableStateFlow>(UiState.Empty) + val myPageState: StateFlow> = _myPageState.asStateFlow() + fun getUserMyPage() = viewModelScope.launch { + getUserMyPageUseCase.invoke().onSuccess { data -> + _myPageState.emit(UiState.Success(data)) + }.onFailure { error -> + _myPageState.emit(UiState.Failure(error.toString())) + } + } + val pushIsAllowed = MutableStateFlow(true) fun getUserInfo() = viewModelScope.launch { diff --git a/feature/mypage/src/main/res/layout/fragment_settings.xml b/feature/mypage/src/main/res/layout/fragment_settings.xml index 6318008a..93276181 100644 --- a/feature/mypage/src/main/res/layout/fragment_settings.xml +++ b/feature/mypage/src/main/res/layout/fragment_settings.xml @@ -53,77 +53,193 @@ app:layout_constraintTop_toTopOf="parent" /> - - - - - - + + app:layout_constraintBottom_toTopOf="@id/tv_now_link" + app:layout_constraintStart_toEndOf="@id/iv_profile" + tools:text="@string/mypage_name_ex" /> + + + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/v_mypage_line" /> + + + + + + app:layout_constraintTop_toBottomOf="@id/fl_settings_alert_off">