Skip to content

Commit

Permalink
fix(home): handle a potential NPE on home screen after deep sleep/bac…
Browse files Browse the repository at this point in the history
…kground

Addresses a NullPointerException that could occur on the home screen when loading items after the device has been in a deep sleep state or the app is resumed from the background.

Fixes #107
  • Loading branch information
rhenwinch committed Jul 9, 2024
1 parent afb2972 commit 1d65c3e
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,27 @@ class HomeItemsProviderUseCase @Inject constructor(
initializeJob = scope.launch {
_initializationStatus.value = Resource.Loading

val allCategories = getHomeRecommendations()

_categories.value = allCategories
rowItemsPaginationJobs.clear()
rowItemsPaginationJobs.addAll(List(allCategories.size) { null })
_rowItems.value = List(allCategories.size) { emptyList() }
_rowItemsPagingState.value = _categories.value.map { item ->
PaginationStateInfo(
canPaginate = item.canPaginate,
pagingState = if (!item.canPaginate) PagingState.PAGINATING_EXHAUST else PagingState.IDLE,
currentPage = 1
)
}
try {
val allCategories = getHomeRecommendations()

_categories.value = allCategories
rowItemsPaginationJobs.clear()
rowItemsPaginationJobs.addAll(List(allCategories.size) { null })
_rowItems.value = List(allCategories.size) { emptyList() }
_rowItemsPagingState.value = _categories.value.map { item ->
PaginationStateInfo(
canPaginate = item.canPaginate,
pagingState = if (!item.canPaginate) PagingState.PAGINATING_EXHAUST else PagingState.IDLE,
currentPage = 1
)
}

_initializationStatus.value = getHeaderItem()
_initializationStatus.value = getHeaderItem()
} catch (e: NullPointerException) {
configurationProvider.initialize()
} catch (e: Exception) {
_initializationStatus.value = Resource.Failure(e)
}
}
}

Expand Down

0 comments on commit 1d65c3e

Please sign in to comment.