Skip to content

Commit

Permalink
Fix Change the way data is created in flow ([android#1327])
Browse files Browse the repository at this point in the history
  • Loading branch information
squart300kg committed Apr 3, 2024
1 parent 7313f6c commit 0f711be
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -19,14 +19,16 @@ package com.google.samples.apps.nowinandroid.core.testing.repository
import com.google.samples.apps.nowinandroid.core.data.model.RecentSearchQuery
import com.google.samples.apps.nowinandroid.core.data.repository.RecentSearchRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flow

class TestRecentSearchRepository : RecentSearchRepository {

private val cachedRecentSearches: MutableList<RecentSearchQuery> = mutableListOf()

override fun getRecentSearchQueries(limit: Int): Flow<List<RecentSearchQuery>> =
flowOf(cachedRecentSearches.sortedByDescending { it.queriedDate }.take(limit))
flow {
emit(cachedRecentSearches.sortedByDescending { it.queriedDate }.take(limit))
}

override suspend fun insertOrReplaceRecentSearch(searchQuery: String) {
cachedRecentSearches.add(RecentSearchQuery(searchQuery))
Expand Down

0 comments on commit 0f711be

Please sign in to comment.