3

i am updating paging to version 3.0 and since i am using clean architecture ( the important thing here is the seperation between the core where i have my repos and my usesCases and the app module where all android framework classes ..) however i am using two model classes (one for querying data from room for example :

 data class ExampleEntity(
    
        @Expose
        @ColumnInfo(name = INTERVENTION_ID_COLUMN_NAME)
        @SerializedName(INTERVENTION_ID_COLUMN_NAME)
        val interventionId: String?,
    
        @Expose
        @ColumnInfo(name = SITE_NAME_COLUMN_NAME)
        @SerializedName(SITE_NAME_COLUMN_NAME)
        val siteName: String?
    }

the other is to be used in the core module and useCase without implying the room database as dependency at all ...ex:

data class Example(

        @Expose
        @SerializedName(INTERVENTION_ID_COLUMN_NAME)
        val interventionId: String?,

        @Expose
        @SerializedName(SITE_NAME_COLUMN_NAME)
        val siteName: String?
    }

later in databseImplementation i map the Entity class to the core Class and it was possible in paging 2 as pagedlist can be mapped , now i can't seem to access the PagingData object of Entity and only can add to it (headers ,seperators...etc) how can i overcome this design puzzle ?

joghm
  • 569
  • 3
  • 20

1 Answers1

4

As you can see from the following documentation, it's possible to transform the items within PagingData before they reach your ViewModel.

In your Repository you should have something along the lines of this

val flow = Pager(PagingConfig(pageSize = 20)) {
  ExamplePagingSource(backend, query)
}.flow

The idea is to map the contents of flow like so

flow.mapLatest { pagingData ->
        pagingData.map { entity -> 
            // map to from ExampleEntity to Entity here
        }
    }
Scott Cooper
  • 2,779
  • 2
  • 23
  • 29