|
|
@ -45,7 +45,6 @@ class TopicViewModel @Inject constructor(
|
|
|
|
stringDecoder: StringDecoder,
|
|
|
|
stringDecoder: StringDecoder,
|
|
|
|
private val userDataRepository: UserDataRepository,
|
|
|
|
private val userDataRepository: UserDataRepository,
|
|
|
|
topicsRepository: TopicsRepository,
|
|
|
|
topicsRepository: TopicsRepository,
|
|
|
|
// newsRepository: NewsRepository,
|
|
|
|
|
|
|
|
getSaveableNewsResources: GetSaveableNewsResourcesUseCase
|
|
|
|
getSaveableNewsResources: GetSaveableNewsResourcesUseCase
|
|
|
|
) : ViewModel() {
|
|
|
|
) : ViewModel() {
|
|
|
|
|
|
|
|
|
|
|
@ -97,13 +96,13 @@ private fun topicUiState(
|
|
|
|
.map { it.followedTopics }
|
|
|
|
.map { it.followedTopics }
|
|
|
|
|
|
|
|
|
|
|
|
// Observe topic information
|
|
|
|
// Observe topic information
|
|
|
|
val topic: Flow<Topic> = topicsRepository.getTopic(
|
|
|
|
val topicStream: Flow<Topic> = topicsRepository.getTopic(
|
|
|
|
id = topicId
|
|
|
|
id = topicId
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return combine(
|
|
|
|
return combine(
|
|
|
|
followedTopicIds,
|
|
|
|
followedTopicIds,
|
|
|
|
topic,
|
|
|
|
topicStream,
|
|
|
|
::Pair
|
|
|
|
::Pair
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.asResult()
|
|
|
|
.asResult()
|
|
|
@ -135,7 +134,7 @@ private fun newsUiState(
|
|
|
|
userDataRepository: UserDataRepository,
|
|
|
|
userDataRepository: UserDataRepository,
|
|
|
|
): Flow<NewsUiState> {
|
|
|
|
): Flow<NewsUiState> {
|
|
|
|
// Observe news
|
|
|
|
// Observe news
|
|
|
|
val news: Flow<List<SaveableNewsResource>> = getSaveableNewsResources(
|
|
|
|
val newsStream: Flow<List<SaveableNewsResource>> = getSaveableNewsResources(
|
|
|
|
filterTopicIds = setOf(element = topicId),
|
|
|
|
filterTopicIds = setOf(element = topicId),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -144,7 +143,7 @@ private fun newsUiState(
|
|
|
|
.map { it.bookmarkedNewsResources }
|
|
|
|
.map { it.bookmarkedNewsResources }
|
|
|
|
|
|
|
|
|
|
|
|
return combine(
|
|
|
|
return combine(
|
|
|
|
news,
|
|
|
|
newsStream,
|
|
|
|
bookmark,
|
|
|
|
bookmark,
|
|
|
|
::Pair
|
|
|
|
::Pair
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -152,7 +151,7 @@ private fun newsUiState(
|
|
|
|
.map { newsToBookmarksResult ->
|
|
|
|
.map { newsToBookmarksResult ->
|
|
|
|
when (newsToBookmarksResult) {
|
|
|
|
when (newsToBookmarksResult) {
|
|
|
|
is Result.Success -> {
|
|
|
|
is Result.Success -> {
|
|
|
|
val (news, bookmarks) = newsToBookmarksResult.data
|
|
|
|
val news = newsToBookmarksResult.data.first
|
|
|
|
NewsUiState.Success(news)
|
|
|
|
NewsUiState.Success(news)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is Result.Loading -> {
|
|
|
|
is Result.Loading -> {
|
|
|
|