Android Repository Pattern convert room to domain model

Viewed 1775

I am desperately looking for a possability to convert a room model to a domain model to enable offline functionality to my app. I have successfully implemented this pattern as described in this codelab: https://codelabs.developers.google.com/codelabs/kotlin-android-training-repository/#0

But I use in my domain model the Paging library -> PagedList<com.trashmaster.muellmister.network.Place> and I need it to convert to PagedList<com.trashmaster.muellmister.data.Place> to insert data. enter image description here

In my ViewModel on the other side I need (convert room model to network model.

var properties: LiveData<PagedList<com.trashmaster.muellmister.network.Place>> (ViewModel)

Is there some kind best practices? Is it possible to merge network data model with room data model?

Online functionality works flawlessly but implementing offline functionality with Paging datasource in combination is hard.

Here is the path to my source

https://gist.github.com/DoomMortal/fa2c243d13d72a37988d12096cf8312a

Any help would be appreciated.

Thanks in advance

1 Answers

Look at this link. As you can see in the link they used a mapper:

fun List<DatabaseVideo>.asDomainModel(): List<DevByteVideo> {
   return map {
       DevByteVideo(
               url = it.url,
               title = it.title,
               description = it.description,
               updated = it.updated,
               thumbnail = it.thumbnail)
   }
}

They are creating a domain model from a database model with this extension function and that's what you're missing

Related