0

I have model in domain called ItemEntity and ItemRepositoy which have method to return PagingSource<Int, ItemEntity> from database. I also have ItemRoomEntity in data layer. In ItemDao for this Room entity I have method which is returning PagingSource<Int, ItemRoomEntity> from this table. How can I map PagingSource<Int, ItemRoomEntity> to PagingSource<Int, ItemEntity>?

Domain

data class ItemEntity(val id: Int, val name: String)

interface ItemRepository {
   fun getItemsPaged(): PagingSource<Int, ItemEntity>
}

Data

@Entity(tableName = "items")
data class ItemRoomEntity(
    @PrimaryKey val id: Int, 
    @ColumnInfo val name: String
)

interface ItemDao {
    @Query("SELECT * FROM items")
    fun getPaging(): PagingSource<Int, ItemRoomEntity>
}


class ItemRepositoryImpl(
    private val itemDao: ItemDao
) : ItemRepository {
    fun getItemsPaged(): PagingSource<Int, ItemEntity> = 
        itemDao.getPaging()   //How can I map this
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • How are you exposing the paging data to the UI? Android suggests exposing a flow from a Pager instance in the repository layer to the UI layer. Then you can map the flow to your domain entity. – woxiangqiu May 09 '23 at 07:08
  • Any luck figuring this out? Thanks – Ana Sep 01 '23 at 04:30

0 Answers0