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

[hotfix] 마이페이지 / 로딩 프로그레스바 추가 #290

Merged
merged 2 commits into from
May 10, 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
Expand Up @@ -22,6 +22,7 @@ import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -269,11 +270,23 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

private fun showLoadingProgressBar() {
binding.pbMypageLoading.isVisible = true
binding.svMypage.isVisible = false
}

private fun dismissLoadingProgressBar() {
binding.pbMypageLoading.isVisible = false
binding.svMypage.isVisible = true
}

private fun setupGetUserStateObserver() {
mainViewModel.getUserState.flowWithLifecycle(lifecycle).onEach { state ->
mainViewModel.getUserState.flowWithLifecycle(lifecycle).onEach launch@{ state ->
when (state) {
is UiState.Success -> {
val data = dataStoreRepository.getUserInfo().first() ?: return@onEach
dismissLoadingProgressBar()
delay(100)
val data = dataStoreRepository.getUserInfo().first() ?: return@launch
updateUserInfo(data)
setUpUserGoalByLevel(data)
setUpUserDataByGoal(data)
Expand All @@ -285,6 +298,10 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
snackBar(binding.root) { state.msg }
}

is UiState.Loading -> {
showLoadingProgressBar()
}

else -> {}
Copy link
Member

@leeeha leeeha May 6, 2024

Choose a reason for hiding this comment

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

애니메이션 쪽 코드를 완전히 이해하지는 못했지만 ,, 😂
현재는 스크롤에 따라 애니메이션을 실행시키는 함수가 getUserState Success 블록에 종속되어 있는 거 같더라구요!
이 둘의 의존성을 끊어내고 애니메이션을 구현하는 방법은 없을까 라는 생각이 들었습니다!

getUser 서버 통신의 응답값은 데이터 스토어에 저장되니까 이를 이용해서
getUserState 결과와 별개로 스크롤 리스너를 정의해두면 어떤 결과가 나올지 궁금했어요..!

애니메이션 코드가 getUserState에 종속되지 않으면, 데이터 로딩 상태와 무관하게 애니메이션은 잘 실행되지 않을까 싶은?!
대신에 getUser 서버 통신에 실패하면 최신 유저 데이터가 아닌 데이터스토어에 저장된 예전 데이터를 불러온다는 것은 단점인 거 같아요. 서버통신 실패 시 어떻게 처리할지 고민이 필요할 거 같습니다!

}
}.launchIn(lifecycleScope)
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_my_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<ProgressBar
android:id="@+id/pb_mypage_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<TextView
android:id="@+id/tv_mypage_title"
android:layout_width="wrap_content"
Expand Down
Loading