|
|
@ -17,16 +17,13 @@
|
|
|
|
package com.google.samples.apps.nowinandroid.core.data.test.repository
|
|
|
|
package com.google.samples.apps.nowinandroid.core.data.test.repository
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.Synchronizer
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.Synchronizer
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.model.asEntity
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery
|
|
|
|
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.Dispatcher
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.Dispatcher
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.network.model.asExternalModel
|
|
|
|
import kotlinx.coroutines.CoroutineDispatcher
|
|
|
|
import kotlinx.coroutines.CoroutineDispatcher
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
import kotlinx.coroutines.flow.flow
|
|
|
|
import kotlinx.coroutines.flow.flow
|
|
|
@ -48,9 +45,11 @@ class FakeNewsRepository @Inject constructor(
|
|
|
|
query: NewsResourceQuery,
|
|
|
|
query: NewsResourceQuery,
|
|
|
|
): Flow<List<NewsResource>> =
|
|
|
|
): Flow<List<NewsResource>> =
|
|
|
|
flow {
|
|
|
|
flow {
|
|
|
|
|
|
|
|
val newsResources = datasource.getNewsResources()
|
|
|
|
|
|
|
|
val topics = datasource.getTopics()
|
|
|
|
|
|
|
|
|
|
|
|
emit(
|
|
|
|
emit(
|
|
|
|
datasource
|
|
|
|
newsResources
|
|
|
|
.getNewsResources()
|
|
|
|
|
|
|
|
.filter { networkNewsResource ->
|
|
|
|
.filter { networkNewsResource ->
|
|
|
|
// Filter out any news resources which don't match the current query.
|
|
|
|
// Filter out any news resources which don't match the current query.
|
|
|
|
// If no query parameters (filterTopicIds or filterNewsIds) are specified
|
|
|
|
// If no query parameters (filterTopicIds or filterNewsIds) are specified
|
|
|
@ -64,8 +63,7 @@ class FakeNewsRepository @Inject constructor(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.all(true::equals)
|
|
|
|
.all(true::equals)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.map(NetworkNewsResource::asEntity)
|
|
|
|
.map { it.asExternalModel(topics) },
|
|
|
|
.map(NewsResourceEntity::asExternalModel),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}.flowOn(ioDispatcher)
|
|
|
|
}.flowOn(ioDispatcher)
|
|
|
|
|
|
|
|
|
|
|
|