Fix error message not showing in profile

This commit is contained in:
Matthieu 2022-03-19 14:00:24 +01:00
parent bbd1949af9
commit 721aa9372e
4 changed files with 36 additions and 36 deletions

View File

@ -1,6 +1,7 @@
package org.pixeldroid.app.posts.feeds
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
import androidx.constraintlayout.motion.widget.MotionLayout
@ -29,7 +30,8 @@ import retrofit2.HttpException
private fun showError(
errorText: String, show: Boolean = true,
motionLayout: MotionLayout,
errorLayout: ErrorLayoutBinding){
errorLayout: ErrorLayoutBinding,
progressBar: ProgressBar){
if(show) {
motionLayout.transitionToEnd()
@ -37,6 +39,7 @@ private fun showError(
} else if(motionLayout.progress == 1F) {
motionLayout.transitionToStart()
}
progressBar.visibility = View.GONE
}
/**
@ -79,7 +82,7 @@ internal fun <T: Any> initAdapter(
val error: String = (it.error as? HttpException)?.response()?.errorBody()?.string()?.ifEmpty { null }?.let { s ->
Gson().fromJson(s, org.pixeldroid.app.utils.api.objects.Error::class.java)?.error?.ifBlank { null }
} ?: it.error.localizedMessage.orEmpty()
showError(motionLayout = motionLayout, errorLayout = errorLayout, errorText = error)
showError(motionLayout = motionLayout, errorLayout = errorLayout, errorText = error, progressBar = progressBar)
}
// If the state is not an error, hide the error layout, or show message that the feed is empty
@ -91,10 +94,11 @@ internal fun <T: Any> initAdapter(
progressBar.isVisible = false
showError(
motionLayout = motionLayout, errorLayout = errorLayout,
errorText = errorLayout.root.context.getString(R.string.empty_feed)
errorText = errorLayout.root.context.getString(R.string.empty_feed),
progressBar = progressBar
)
} else {
showError(motionLayout = motionLayout, errorLayout = errorLayout, show = false, errorText = "")
showError(motionLayout = motionLayout, errorLayout = errorLayout, show = false, errorText = "", progressBar = progressBar)
}
}
}

View File

@ -9,6 +9,7 @@ import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
@ -38,6 +39,7 @@ import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
import org.pixeldroid.app.utils.openUrl
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.pixeldroid.app.databinding.ErrorLayoutBinding
import org.pixeldroid.app.utils.api.objects.Attachment
import retrofit2.HttpException
import java.io.IOException
@ -81,12 +83,13 @@ class ProfileActivity : BaseActivity() {
profileAdapter = ProfilePostsAdapter()
initAdapter(binding.profileProgressBar, binding.profileRefreshLayout,
binding.profilePostsRecyclerView, binding.motionLayout, binding.profileErrorLayout,
binding.profilePostsRecyclerView, binding.motionLayout, binding.errorLayout,
profileAdapter)
binding.profilePostsRecyclerView.layoutManager = GridLayoutManager(this, 3)
binding.profileRefreshLayout.setOnRefreshListener {
setContent(account)
profileAdapter.refresh()
}
@ -101,6 +104,7 @@ class ProfileActivity : BaseActivity() {
if(show){
binding.profileProgressBar.visibility = View.GONE
binding.motionLayout.transitionToEnd()
binding.errorLayout.errorText.text = errorText
} else if(binding.motionLayout.progress == 1F) {
binding.motionLayout.transitionToStart()
}

View File

@ -129,8 +129,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/profilePictureImageView"
app:layout_constraintTop_toTopOf="@+id/profilePictureImageView" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
@ -144,37 +142,36 @@
android:layout_gravity="center"
android:layout_marginTop="16dp" />
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:visibility="visible"
app:layoutDescription="@xml/error_layout_xml_error_scene"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/nbFollowersTextView">
<include
android:id="@+id/profileErrorLayout"
layout="@layout/error_layout"
tools:layout_editor_absoluteX="50dp" />
</androidx.constraintlayout.motion.widget.MotionLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/profileRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/profilePostsRecyclerView"
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layoutManager="LinearLayoutManager"
tools:listitem="@layout/fragment_profile_posts" />
android:layout_marginTop="8dp"
android:visibility="visible"
app:layoutDescription="@xml/error_layout_xml_error_scene">
<include
android:id="@+id/errorLayout"
layout="@layout/error_layout"
tools:layout_editor_absoluteX="50dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/profilePostsRecyclerView"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager"
app:layout_constraintTop_toBottomOf="@id/errorLayout"
tools:listitem="@layout/fragment_profile_posts" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -5,9 +5,6 @@
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:id="@+id/progressBar"
@ -30,7 +27,6 @@
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
android:layout_width="match_parent"
@ -40,8 +36,7 @@
app:layoutDescription="@xml/error_layout_xml_error_scene"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/followButton"
tools:visibility="visible">
app:layout_constraintTop_toBottomOf="@id/followButton">
<include
android:id="@id/errorLayout"