Skip to content

Commit

Permalink
Fix empty screen after screen off on on no internet error screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Drjacky committed Dec 27, 2023
1 parent 45575fd commit 0673aca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Depends {
const val materialVersion = "1.6.0-alpha03"
const val coreKtxVersion = "1.9.0"
const val navigationVersion = "2.5.2"
const val pagingVersion = "3.1.1"
const val pagingVersion = "3.2.1"
const val multidexVersion = "2.0.1"
const val fragmentExtVersion = "1.5.0-alpha03"
const val recyclerviewVersion = "1.3.0-rc01"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ open class BaseViewModel @Inject constructor() : ViewModel(),
is Failure.NoInternet -> {
Failure.NoInternet(resources.getString(R.string.error_no_internet))
}

is Failure.Api -> {
Failure.Api(throwable.msg)
}

is Failure.Timeout -> {
Failure.Timeout(resources.getString(R.string.error_timeout))
}

is Failure.Unknown -> {
Failure.Unknown(resources.getString(R.string.error_unknown))
}

else -> {
Failure.Unknown(resources.getString(R.string.error_unknown))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import app.web.drjackycv.presentation.R
import app.web.drjackycv.presentation.base.adapter.LoadingStateAdapter
import app.web.drjackycv.presentation.base.adapter.RecyclerItem
import app.web.drjackycv.presentation.databinding.FragmentProductListBinding
import app.web.drjackycv.presentation.extension.*
import app.web.drjackycv.presentation.extension.collectIn
import app.web.drjackycv.presentation.extension.gone
import app.web.drjackycv.presentation.extension.invisible
import app.web.drjackycv.presentation.extension.observe
import app.web.drjackycv.presentation.extension.viewBinding
import app.web.drjackycv.presentation.extension.visible
import app.web.drjackycv.presentation.products.choose.ChoosePathType
import app.web.drjackycv.presentation.products.entity.BeerUI
import com.google.android.material.transition.platform.Hold
Expand Down Expand Up @@ -72,6 +77,7 @@ class ProductsListFragment : Fragment(R.layout.fragment_product_list) {
ChoosePathType.RX -> {
setupView()
}

ChoosePathType.COROUTINE -> {
setupViewByCoroutine()
}
Expand Down Expand Up @@ -109,7 +115,6 @@ class ProductsListFragment : Fragment(R.layout.fragment_product_list) {
}

private fun loadingUI(isLoading: Boolean) {
binding.inclItemError.itemErrorContainer.gone()
if (isLoading) {
binding.inclItemLoading.itemLoadingContainer.visible()
} else {
Expand All @@ -124,9 +129,11 @@ class ProductsListFragment : Fragment(R.layout.fragment_product_list) {
is Failure.NoInternet, is Failure.Api, is Failure.Timeout -> {
setupErrorItem(failure)
}

is Failure.Unknown -> {
setupErrorItem(failure)
}

else -> {
binding.inclItemError.itemErrorMessage.text = failure.message
binding.inclItemError.itemErrorRetryBtn.invisible()
Expand All @@ -152,8 +159,10 @@ class ProductsListFragment : Fragment(R.layout.fragment_product_list) {

private fun adapterLoadingErrorHandling(combinedLoadStates: CombinedLoadStates) {
if (combinedLoadStates.refresh is LoadState.Loading) {
binding.inclItemError.itemErrorContainer.gone()
loadingUI(true)
} else {
binding.inclItemError.itemErrorContainer.gone()
loadingUI(false)
val error = when {
combinedLoadStates.prepend is LoadState.Error -> combinedLoadStates.prepend as LoadState.Error
Expand All @@ -164,12 +173,15 @@ class ProductsListFragment : Fragment(R.layout.fragment_product_list) {
else -> null
}
error?.run {
binding.inclItemError.itemErrorContainer.visible()
loadingUI(false)
productsListViewModel.handleFailure(this.error) { retryFetchData() }
}
}
}

private fun retryFetchData() {
binding.inclItemError.itemErrorContainer.gone()
loadingUI(false)
binding.productListRecyclerView.visible()
productsListAdapter.retry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ProductsListViewModel @Inject constructor(
ChoosePathType.RX -> {
getProductsByRxPath(ids)
}

ChoosePathType.COROUTINE -> {
viewModelScope.launch {
_productsListByCoroutine.value = getProductsByCoroutinePath(ids).first()
Expand Down

0 comments on commit 0673aca

Please sign in to comment.