Created
December 13, 2022 11:09
-
-
Save dturner/495cb676b4e02a2871f64521d3414223 to your computer and use it in GitHub Desktop.
Adding GetSaveableNewsResourcesUseCase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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