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

добавил события, когда от сервера приходит ошибка и прислали пустой с… #11

Open
wants to merge 1 commit into
base: #19_liks
Choose a base branch
from
Open
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,7 +22,7 @@ class MockApi : Api {
lastName = "bi",
userName = "biBob"
)
),
).flatMap { listOf(it, it, it, it, it, it) }.flatMap { listOf(it, it, it, it, it, it) },
code=200
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,25 @@ class UserListFragment : BaseFragment(R.layout.fragment_list_users) {
is UserListViewModel.ViewState.Loading -> {
viewBinding.recyclerView.isVisible = false
viewBinding.progressBar.isVisible = true
viewBinding.errorText.isVisible = false
}
is UserListViewModel.ViewState.Data -> {
viewBinding.recyclerView.isVisible = true
(viewBinding.recyclerView.adapter as UserAdapter).userList.value = viewState.userList
viewBinding.progressBar.isVisible = false
viewBinding.errorText.isVisible = false
}
is UserListViewModel.ViewState.EmptyList -> {
viewBinding.recyclerView.isVisible = false
viewBinding.progressBar.isVisible = false
viewBinding.errorText.isVisible = true
viewBinding.errorText.text="увы у вас пока нет друзей"
}
is UserListViewModel.ViewState.Error -> {
viewBinding.recyclerView.isVisible = false
viewBinding.progressBar.isVisible = false
viewBinding.errorText.isVisible = true
viewBinding.errorText.text="возникла какае-та ошибка"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class UserListViewModel @Inject constructor(

sealed class ViewState {
object Loading : ViewState()
object Error : ViewState()
object EmptyList : ViewState()
data class Data(val userList: List<User>) : ViewState()
}

Expand All @@ -48,9 +50,15 @@ class UserListViewModel @Inject constructor(
_viewState.emit(ViewState.Loading)
when (val response = usersInteractor.loadUsers()){
is NetworkResponse.Success -> {
_viewState.emit(ViewState.Data(response.body))
val userList = response.body
if (userList.isEmpty()){
_viewState.emit(ViewState.EmptyList)
}else {
_viewState.emit(ViewState.Data(userList))
}
}
else -> {
_viewState.emit(ViewState.Error)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/fragment_list_users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/error_text"
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="100dp"
android:text="техт ошибки"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout><!--</androidx.fragment.app.FragmentContainerView>-->