From cefb70d339eef2b6db0838aefe9cbcf5a8e0e896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D1=88=D0=BA=D0=BE=D0=B2=20=D0=94=D0=BC?= =?UTF-8?q?=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= <100100101104@mail.ru> Date: Sat, 15 Jan 2022 00:37:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D1=8F,=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B3=D0=B4=D0=B0=20=D0=BE=D1=82=20=D1=81=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=20=D0=BF=D1=80=D0=B8=D1=85=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D1=82=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D1=81=D0=BB=D0=B0=D0=BB=D0=B8=20=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B9=20=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20?= =?UTF-8?q?=D0=B4=D1=80=D1=83=D0=B7=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/android_curse/data/network/MockApi.kt | 2 +- .../android_curse/ui/userlist/UserListFragment.kt | 14 ++++++++++++++ .../android_curse/ui/userlist/UserListViewModel.kt | 10 +++++++++- app/src/main/res/layout/fragment_list_users.xml | 12 ++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/android_curse/data/network/MockApi.kt b/app/src/main/java/com/example/android_curse/data/network/MockApi.kt index 754deee..dfc13a8 100644 --- a/app/src/main/java/com/example/android_curse/data/network/MockApi.kt +++ b/app/src/main/java/com/example/android_curse/data/network/MockApi.kt @@ -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 ) } diff --git a/app/src/main/java/com/example/android_curse/ui/userlist/UserListFragment.kt b/app/src/main/java/com/example/android_curse/ui/userlist/UserListFragment.kt index 7de1a3a..127ff57 100644 --- a/app/src/main/java/com/example/android_curse/ui/userlist/UserListFragment.kt +++ b/app/src/main/java/com/example/android_curse/ui/userlist/UserListFragment.kt @@ -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="возникла какае-та ошибка" } } } diff --git a/app/src/main/java/com/example/android_curse/ui/userlist/UserListViewModel.kt b/app/src/main/java/com/example/android_curse/ui/userlist/UserListViewModel.kt index e3d8176..695add4 100644 --- a/app/src/main/java/com/example/android_curse/ui/userlist/UserListViewModel.kt +++ b/app/src/main/java/com/example/android_curse/ui/userlist/UserListViewModel.kt @@ -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) : ViewState() } @@ -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) } } } diff --git a/app/src/main/res/layout/fragment_list_users.xml b/app/src/main/res/layout/fragment_list_users.xml index 54ce416..812381f 100644 --- a/app/src/main/res/layout/fragment_list_users.xml +++ b/app/src/main/res/layout/fragment_list_users.xml @@ -29,4 +29,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + +