diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/news/NewsFragment.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/news/NewsFragment.kt
index b612294..5bbb985 100644
--- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/news/NewsFragment.kt
+++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/news/NewsFragment.kt
@@ -24,8 +24,8 @@ import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
import androidx.fragment.app.viewModels
-import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.observe
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
@@ -66,14 +66,15 @@ class NewsFragment : BaseFragmentView(), LayoutVisibilityChange {
whenStarted {
loading.visibility = View.VISIBLE
refreshLayout.isEnabled = false
- newsViewModel.newsData.observe(viewLifecycleOwner, Observer {
+ newsViewModel.newsData.observe(viewLifecycleOwner) {
if (::footerAdapter.isInitialized)
footerAdapter.clear()
- if (it.hasError) {
- if (newsAdapter.adapterItemCount == 0) {
-
- }
- }
+ if (it.hasError && newsAdapter.adapterItemCount == 0) {
+ errorScreen.visibility = View.VISIBLE
+ container.visibility = View.INVISIBLE
+ refreshLayout.isEnabled = true
+ return@observe
+ } else errorScreen.visibility = View.INVISIBLE
if (it.id !in activeItems) {
val newsObject = News(
title = it.title,
@@ -91,7 +92,7 @@ class NewsFragment : BaseFragmentView(), LayoutVisibilityChange {
refreshLayout.isEnabled = true
activeItems.add(it.id)
}
- })
+ }
}
}
}
@@ -143,6 +144,7 @@ class NewsFragment : BaseFragmentView(), LayoutVisibilityChange {
scrollListener.resetPageCount()
}
container.visibility = View.INVISIBLE
+ errorScreen.visibility = View.INVISIBLE
}
}
diff --git a/app/src/main/res/layout/loading_recycler_view.xml b/app/src/main/res/layout/loading_recycler_view.xml
index 82161bb..800d5f7 100644
--- a/app/src/main/res/layout/loading_recycler_view.xml
+++ b/app/src/main/res/layout/loading_recycler_view.xml
@@ -1,6 +1,7 @@
@@ -27,22 +28,30 @@
+ app:layout_constraintTop_toTopOf="parent"
+ app:lottie_autoPlay="true"
+ app:lottie_loop="true"
+ app:lottie_rawRes="@raw/error_state" />
+ app:layout_constraintTop_toBottomOf="@+id/errorAnimation"
+ tools:text="Error while obtaining new data" />
Actualmente, las animaciones están activadas.
Ten en cuenta que esto puede afectar tanto al rendimiento como a la batería
No se mostrará ninguna animación
+ Error al cargar información sobre las noticias
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e55dd41..f6df4e1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -318,4 +318,5 @@
Currently, the app will play some animations.
Keep in mind that it can affect both performance and battery life
No animations will be played
+ Error while loading news data