Skip to content

Commit f3506ee

Browse files
committed
🐛 빌드 오류 수정 및 데이터 바인딩 오류 수정
1 parent f709038 commit f3506ee

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

presentation/src/main/java/com/whyranoid/presentation/myrun/MyRunFragment.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import androidx.navigation.fragment.findNavController
99
import com.whyranoid.presentation.R
1010
import com.whyranoid.presentation.base.BaseFragment
1111
import com.whyranoid.presentation.databinding.FragmentMyRunBinding
12+
import com.whyranoid.presentation.model.RunningHistoryUiModel
13+
import com.whyranoid.presentation.model.UiState
1214
import com.whyranoid.presentation.util.loadImage
1315
import com.whyranoid.presentation.util.repeatWhenUiStarted
1416
import dagger.hilt.android.AndroidEntryPoint
@@ -83,12 +85,27 @@ internal class MyRunFragment : BaseFragment<FragmentMyRunBinding>(R.layout.fragm
8385
}
8486

8587
viewLifecycleOwner.repeatWhenUiStarted {
86-
viewModel.runningHistoryList.collect { runningHistoryList ->
87-
runningHistoryAdapter.submitList(runningHistoryList)
88+
viewModel.runningHistoryListState.collect { runningHistoryListState ->
89+
when (runningHistoryListState) {
90+
is UiState.UnInitialized -> {
91+
}
92+
is UiState.Loading -> {
93+
}
94+
is UiState.Success<List<RunningHistoryUiModel>> -> initRecyclerView(
95+
runningHistoryListState.value
96+
)
97+
98+
is UiState.Failure -> {
99+
}
100+
}
88101
}
89102
}
90103
}
91104

105+
private fun initRecyclerView(runningHistoryList: List<RunningHistoryUiModel>) {
106+
runningHistoryAdapter.submitList(runningHistoryList)
107+
}
108+
92109
private fun popUpEditNickNameDialog() {
93110
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_nick_name, null)
94111

presentation/src/main/java/com/whyranoid/presentation/myrun/MyRunViewModel.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.whyranoid.domain.usecase.GetRunningHistoryUseCase
88
import com.whyranoid.domain.usecase.GetUidUseCase
99
import com.whyranoid.domain.usecase.UpdateNicknameUseCase
1010
import com.whyranoid.presentation.model.RunningHistoryUiModel
11+
import com.whyranoid.presentation.model.UiState
1112
import com.whyranoid.presentation.model.toRunningHistoryUiModel
1213
import dagger.hilt.android.lifecycle.HiltViewModel
1314
import kotlinx.coroutines.flow.MutableStateFlow
@@ -43,9 +44,10 @@ class MyRunViewModel @Inject constructor(
4344
val profileImgUri: StateFlow<String>
4445
get() = _profileImgUri.asStateFlow()
4546

46-
private val _runningHistoryList = MutableStateFlow<List<RunningHistoryUiModel>>(emptyList())
47-
val runningHistoryList: StateFlow<List<RunningHistoryUiModel>>
48-
get() = _runningHistoryList.asStateFlow()
47+
private val _runningHistoryListState =
48+
MutableStateFlow<UiState<List<RunningHistoryUiModel>>>(UiState.UnInitialized)
49+
val runningHistoryListState: StateFlow<UiState<List<RunningHistoryUiModel>>>
50+
get() = _runningHistoryListState.asStateFlow()
4951

5052
private fun getUid() {
5153
viewModelScope.launch {
@@ -83,9 +85,14 @@ class MyRunViewModel @Inject constructor(
8385

8486
private fun getRunningHistoryList() {
8587
viewModelScope.launch {
86-
getRunningHistoryUseCase().collect { runningHistoryList ->
87-
_runningHistoryList.value = runningHistoryList.map { runningHistory ->
88-
runningHistory.toRunningHistoryUiModel()
88+
_runningHistoryListState.value = UiState.Loading
89+
90+
getRunningHistoryUseCase().collect { runningHistoryListResult ->
91+
runningHistoryListResult.onSuccess { runningHistoryList ->
92+
_runningHistoryListState.value =
93+
UiState.Success(runningHistoryList.map { runningHistory -> runningHistory.toRunningHistoryUiModel() })
94+
}.onFailure { throwable ->
95+
_runningHistoryListState.value = UiState.Failure(throwable)
8996
}
9097
}
9198
}

presentation/src/main/res/layout/fragment_create_running_post.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<layout
3+
android:id="@+id/layout_root"
4+
xmlns:android="http://schemas.android.com/apk/res/android"
35
xmlns:app="http://schemas.android.com/apk/res-auto">
46

57
<data>

presentation/src/main/res/layout/fragment_select_running_history.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
23
<layout xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools">
@@ -38,6 +39,7 @@
3839

3940
<androidx.recyclerview.widget.RecyclerView
4041
android:id="@+id/rv_select_running_history"
42+
tools:listitem="@layout/item_running_history"
4143
android:layout_width="0dp"
4244
android:layout_height="0dp"
4345
android:layout_marginHorizontal="12dp"
@@ -47,8 +49,7 @@
4749
app:layout_constraintBottom_toBottomOf="parent"
4850
app:layout_constraintEnd_toEndOf="parent"
4951
app:layout_constraintStart_toStartOf="parent"
50-
app:layout_constraintTop_toBottomOf="@id/tv_select_running_history_helper"
51-
tools:listitem="@layout/item_running_history" />
52+
app:layout_constraintTop_toBottomOf="@id/tv_select_running_history_helper" />
5253

5354
</androidx.constraintlayout.widget.ConstraintLayout>
5455
</layout>

0 commit comments

Comments
 (0)