Skip to content

Commit

Permalink
Fix/no internet connection on hub apps (#808)
Browse files Browse the repository at this point in the history
Background

On Hub/Apps screen displayed multiple error placeholders when categories
and list could not be loaded. There's should be either displayed
categories with list error or fullscreen error in case categories could
not be loaded

Changes

- Removed entirely error placeholder from ComposableCategories as it's
not required now
- Block list error display when categories error happened
- Add fullscreen LazyColumn error display

Test plan

- Get Charles or HTTP Toolkit to simultate url timeouts or just disable
internet on phone
- Open Hub>Apps
- Await categories loaded and simulate error for list below to see it's
error placeholder
- Restart app with no internet to see fullscreen error placeholder on
this screen when categories not loaded
  • Loading branch information
makeevrserg committed Apr 5, 2024
1 parent 13b4c74 commit 381b8d0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [Refactor] Basic implementation of new transport ble
- [FIX] Replace decompose push to move safety push
- [FIX] Add fallback for parse url from "Open in App" URI
- [FIX] Multiple internet connection placeholders on Hub Apps screen
- [Refactor] Use https://github.com/IlyaGulya/anvil-utils to automatically generate and contribute assisted factories.
- [Refactor] Add test for Progress Tracker logic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import com.flipperdevices.core.ui.res.R as DesignSystem

private const val DEFAULT_FAP_COUNT = 20

@Suppress("FunctionNaming")
@Suppress("FunctionNaming", "LongParameterList")
fun LazyListScope.ComposableFapsList(
faps: LazyPagingItems<FapItemShort>,
onOpenFapItem: (FapItemShort) -> Unit,
errorsRenderer: FapHubComposableErrorsRenderer,
defaultFapErrorSize: FapErrorSize,
installationButton: @Composable (FapItemShort?, Modifier) -> Unit
installationButton: @Composable (FapItemShort?, Modifier) -> Unit,
shouldDisplayError: Boolean = true
) {
val elementModifier = Modifier
.fillMaxWidth()
Expand All @@ -47,7 +48,7 @@ fun LazyListScope.ComposableFapsList(
)
}
return
} else if (faps.loadState.refresh is LoadState.Error) {
} else if (faps.loadState.refresh is LoadState.Error && shouldDisplayError) {
val loadState = faps.loadState.refresh as? LoadState.Error ?: return
with(errorsRenderer) {
ComposableThrowableErrorListItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.paging.LoadState
Expand All @@ -13,12 +14,17 @@ import com.flipperdevices.faphub.appcard.composable.paging.ComposableFapsList
import com.flipperdevices.faphub.appcard.composable.paging.ComposableSortChoice
import com.flipperdevices.faphub.catalogtab.impl.R
import com.flipperdevices.faphub.catalogtab.impl.composable.categories.ComposableCategories
import com.flipperdevices.faphub.catalogtab.impl.composable.categories.ComposableFullScreenError
import com.flipperdevices.faphub.catalogtab.impl.model.CategoriesLoadState
import com.flipperdevices.faphub.catalogtab.impl.viewmodel.CategoriesViewModel
import com.flipperdevices.faphub.catalogtab.impl.viewmodel.FapsListViewModel
import com.flipperdevices.faphub.dao.api.model.FapCategory
import com.flipperdevices.faphub.dao.api.model.FapItemShort
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.toFapHubError
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.map

@Composable
fun ComposableCatalogTabScreen(
Expand All @@ -33,20 +39,27 @@ fun ComposableCatalogTabScreen(
val fapsList = fapsListViewModel.getFapsFlow().collectAsLazyPagingItems()
val sortType by fapsListViewModel.getSortTypeFlow().collectAsState()
val categoriesLoadState by categoriesViewModel.getCategoriesLoadState().collectAsState()

val categoriesFapHubError by remember {
categoriesViewModel.getCategoriesLoadState()
.filterIsInstance<CategoriesLoadState.Error>()
.map { categoriesErrorLoadState -> categoriesErrorLoadState.throwable.toFapHubError() }
}.collectAsState(initial = null)

val refreshAll = {
fapsListViewModel.refreshManifest()
fapsList.refresh()
categoriesViewModel.onRefresh()
}

SwipeRefresh(
modifier = modifier,
onRefresh = {
fapsListViewModel.refreshManifest()
fapsList.refresh()
categoriesViewModel.onRefresh()
}
onRefresh = refreshAll
) {
LazyColumn {
ComposableCategories(
loadState = categoriesLoadState,
onCategoryClick = onCategoryClick,
onRetry = categoriesViewModel::onRefresh,
errorsRenderer = errorsRenderer
)
if (fapsList.loadState.refresh !is LoadState.Error) {
item {
Expand All @@ -62,8 +75,17 @@ fun ComposableCatalogTabScreen(
onOpenFapItem = onOpenFapItem,
errorsRenderer = errorsRenderer,
installationButton = installationButton,
defaultFapErrorSize = FapErrorSize.IN_LIST
defaultFapErrorSize = FapErrorSize.IN_LIST,
shouldDisplayError = categoriesFapHubError == null
)

categoriesFapHubError?.let { categoriesFapHubError ->
ComposableFullScreenError(
fapHubError = categoriesFapHubError,
errorsRenderer = errorsRenderer,
onRetry = refreshAll
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.flipperdevices.faphub.catalogtab.impl.composable.categories

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.flipperdevices.core.ui.ktx.clickableRipple
import com.flipperdevices.faphub.catalogtab.impl.model.CategoriesLoadState
import com.flipperdevices.faphub.dao.api.model.FapCategory
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.toFapHubError

private const val DEFAULT_CATEGORIES_SIZE = 12
private const val COLUMN_COUNT = 3
Expand All @@ -21,8 +16,6 @@ private const val COLUMN_COUNT = 3
fun LazyListScope.ComposableCategories(
loadState: CategoriesLoadState,
onCategoryClick: (FapCategory) -> Unit,
onRetry: () -> Unit,
errorsRenderer: FapHubComposableErrorsRenderer
) {
when (loadState) {
is CategoriesLoadState.Loaded -> ComposableCategoriesGridItems(
Expand All @@ -37,17 +30,7 @@ fun LazyListScope.ComposableCategories(
onClick = onCategoryClick
)

is CategoriesLoadState.Error -> with(errorsRenderer) {
ComposableThrowableErrorListItem(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 14.dp)
.height(height = 250.dp),
throwable = loadState.throwable.toFapHubError(),
onRetry = onRetry,
fapErrorSize = FapErrorSize.IN_LIST
)
}
is CategoriesLoadState.Error -> Unit
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.flipperdevices.faphub.catalogtab.impl.composable.categories

import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.ui.Modifier
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.FapHubError

@Suppress("FunctionNaming")
internal fun LazyListScope.ComposableFullScreenError(
fapHubError: FapHubError,
errorsRenderer: FapHubComposableErrorsRenderer,
onRetry: () -> Unit,
modifier: Modifier = Modifier
) {
with(errorsRenderer) {
ComposableThrowableErrorListItem(
modifier = modifier,
throwable = fapHubError,
onRetry = onRetry,
fapErrorSize = FapErrorSize.FULLSCREEN
)
}
}

0 comments on commit 381b8d0

Please sign in to comment.