I am using clean architecture with paging 3 and trying to populate a lazyColumn.
I have the following class in my data layer module and I don't want to pass the PagingData to the domain layer as I want to keep the domain free of any Android SDK.
class RepositoryImp @Inject constructor(
private val foodService: FoodService,
private val foodDatabase: FoodDatabase) : Repository {
@OptIn(ExperimentalPagingApi::class)
override fun fetchAllComplexSearch(): Flow<ResponseState<List<ComplexSearchEntity>>> {
val pagingSourceFactory = { foodDatabase.foodDao().fetchAllComplexSearchPaging() }
val pagingDataResult = Pager(
config = PagingConfig(pageSize = ITEMS_PER_PAGE_DEFAULT),
remoteMediator = ComplexSearchRemoteMediator(
foodDatabase = foodDatabase, foodService = foodService
),
pagingSourceFactory = pagingSourceFactory
).flow
val data = pagingDataResult.map { pagingData ->
pagingData.map { complexSearchModel ->
ResponseState.Success(
listOf(
ComplexSearchEntity(
complexSearchModel.id,
complexSearchModel.title,
complexSearchModel.image,
complexSearchModel.imageType
)
)
)
}
}
return data
}
I want to return this Flow<ResponseState<List<ComplexSearchEntity>>>
But I get the following error:
Type mismatch.
Required:
Flow<ResponseState<List<ComplexSearchEntity>>>
Found:
Flow<PagingData<ResponseState.Success<List<ComplexSearchEntity>>>>
It seems like I am wrapping the ResponseState.Success(...) inside the PagingData
Then the presentation layer module will map the Response.Success in a PagingData to be used as a LazyPagingItems<ComplexSearchEntity>
in a LazyColumn.