Skip to content

Instantly share code, notes, and snippets.

@dturner
Created December 13, 2022 11:09
Show Gist options
  • Save dturner/495cb676b4e02a2871f64521d3414223 to your computer and use it in GitHub Desktop.
Save dturner/495cb676b4e02a2871f64521d3414223 to your computer and use it in GitHub Desktop.
Adding GetSaveableNewsResourcesUseCase
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class GetSaveableNewsResourcesUseCase @Inject constructor(
private val newsRepository: NewsRepository,
userDataRepository: UserDataRepository
) {
private val bookmarks = userDataRepository.userDataStream.map { userData ->
userData.bookmarkedNewsResources
}
operator fun invoke(): Flow<List<SaveableNewsResource>> =
newsRepository.getNewsResources()
.combine(bookmarks) { newsResources, bookmarks ->
newsResources.map { newsResource ->
SaveableNewsResource(
newsResource = newsResource,
isSaved = bookmarks.contains(newsResource.id)
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment