Make load spinner exist again

This commit is contained in:
Matthieu 2022-10-31 01:37:44 +01:00
parent 1fa4b80fe7
commit 147046b7b4

View File

@ -31,8 +31,7 @@ import retrofit2.HttpException
private fun showError( private fun showError(
errorText: String, show: Boolean = true, errorText: String, show: Boolean = true,
motionLayout: MotionLayout, motionLayout: MotionLayout,
errorLayout: ErrorLayoutBinding, errorLayout: ErrorLayoutBinding){
progressBar: ProgressBar){
if(show) { if(show) {
motionLayout.transitionToEnd() motionLayout.transitionToEnd()
@ -40,7 +39,6 @@ private fun showError(
} else if(motionLayout.progress == 1F) { } else if(motionLayout.progress == 1F) {
motionLayout.transitionToStart() motionLayout.transitionToStart()
} }
progressBar.visibility = View.GONE
} }
/** /**
@ -87,7 +85,7 @@ internal fun <T: Any> initAdapter(
val error: String = (it.error as? HttpException)?.response()?.errorBody()?.string()?.ifEmpty { null }?.let { s -> 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 } Gson().fromJson(s, org.pixeldroid.app.utils.api.objects.Error::class.java)?.error?.ifBlank { null }
} ?: it.error.localizedMessage.orEmpty() } ?: it.error.localizedMessage.orEmpty()
showError(motionLayout = motionLayout, errorLayout = errorLayout, errorText = error, progressBar = progressBar) showError(motionLayout = motionLayout, errorLayout = errorLayout, errorText = error)
} }
// If the state is not an error, hide the error layout, or show message that the feed is empty // If the state is not an error, hide the error layout, or show message that the feed is empty
@ -100,10 +98,9 @@ internal fun <T: Any> initAdapter(
showError( showError(
motionLayout = motionLayout, errorLayout = errorLayout, 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 { } else {
showError(motionLayout = motionLayout, errorLayout = errorLayout, show = false, errorText = "", progressBar = progressBar) showError(motionLayout = motionLayout, errorLayout = errorLayout, show = false, errorText = "")
} }
} }
} }