Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,17 @@ fun MapFragmentComposeView(
}
}

// MainState
// MainState - 로컬 SharedPreferences를 fallback으로 사용
val localDepartmentName = remember { MySharedPreferences.getUserDepartmentName(context) }
Copy link
Member

Choose a reason for hiding this comment

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

P1

요거 뷰모델로 옮기는게 좋을 것 같아욤
제가 로깅 때문에 뷰에서 바로 SharedPreferences 호출한 적이 있는 것 같은데, 이것두 같이 바꿔줄 수 있을까욤?

Copy link
Member Author

Choose a reason for hiding this comment

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

그러네용 수정하겠습니다!

val (departmentName, showUserDepartmentBottomSheet) = when (val state = mainUiState) {
is UiState.Success -> {
when (val data = state.data) {
is MainState.DepartmentState -> data.departmentName to data.showUserDepartmentBottomSheet
else -> "" to false
else -> localDepartmentName to false
}
}
else -> "" to false

else -> localDepartmentName to false
}

LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.eatssu.android.presentation.mypage

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.eatssu.android.BuildConfig
import com.eatssu.android.data.MySharedPreferences
import com.eatssu.android.data.repository.PreferencesRepository
import com.eatssu.android.domain.usecase.alarm.AlarmUseCase
import com.eatssu.android.domain.usecase.alarm.SetDailyNotificationStatusUseCase
import com.eatssu.android.domain.usecase.user.GetUserNickNameUseCase
import com.eatssu.android.presentation.UiEvent
import com.eatssu.android.presentation.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -30,13 +33,20 @@ class MyPageViewModel @Inject constructor(
private val getUserNickNameUseCase: GetUserNickNameUseCase,
private val setNotificationStatusUseCase: SetDailyNotificationStatusUseCase,
private val alarmUseCase: AlarmUseCase,
private val preferencesRepository: PreferencesRepository
private val preferencesRepository: PreferencesRepository,
@ApplicationContext private val context: Context
) : ViewModel() {

// 내부는 항상 "값 그 자체"만 들고 있고,
// 화면엔 UiState로 감싸서 노출
// 로컬 저장소에서 닉네임을 먼저 읽어서 초기 상태 설정
private val _state = MutableStateFlow(
MyPageState(appVersion = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})")
MyPageState(
appVersion = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})",
nickname = MySharedPreferences.getUserName(context).takeIf {
it.isNotBlank()
}
Comment on lines +44 to +46
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

ViewModel이 초기화될 때 SharedPreferences에서 닉네임을 가져와 초기 상태를 설정하는 로직이 추가되었네요. 좋은 접근입니다.

다만, 현재 로직은 isNotBlank만 확인하고 있습니다. fetchMyInfo 메소드나 MyPageStatehasNickname 로직을 보면, user-로 시작하는 닉네임은 유효하지 않은 것으로 처리하고 있습니다.

일관성을 유지하고, 'user-xxxx'와 같은 닉네임이 잠시 보였다가 사라지는 UI 깜빡임 현상을 방지하기 위해, 초기화 시점에도 startsWith("user-") 체크를 추가하는 것이 좋겠습니다.

Suggested change
nickname = MySharedPreferences.getUserName(context).takeIf {
it.isNotBlank()
}
nickname = MySharedPreferences.getUserName(context).takeIf {
it.isNotBlank() && !it.startsWith("user-")
}

)
)
val uiState: StateFlow<UiState<MyPageState>> =
_state
Expand Down