Solution 1 :
Here is how i have done done it
Data Source
fun getDataSource(): DataSource.Factory<Int, DBModel> {
return database.dao.getAllData()
}
variable at view model
val scannedCompleteList=App.getRepository().getDataSource().toLiveData(
Config(
pageSize = 60,
enablePlaceholders = true,
maxSize = 200
)
)
Now i have a binding adapter where i convert the data from db model to domain model
@BindingAdapter("setData")
fun setImageScanned(recyclerView: RecyclerView, data: List<DBModel>?) {
val adapter = recyclerView.adapter as MyAdapter
adapter.submitList(it.asDomainModel())
}
}
So you are observing data at fragment so you can convert the data to presenter inside observer.
asDomainModel is an extension function which do the conversion
Problem :
I use two models in my app:
- Database
- Presenter (UI)
Android Paging gives me a DataSource.Factory<*, DatabaseModel>
@Dao
interface ProjectDao {
@Query("SELECT * FROM project")
fun getAllProjects(): DataSource.Factory<Int, DatabaseModel>
...
}
When I want to make the LiveData
using LivePagedListBuilder(dataSourceFactory, config)
I need to map:
DataSource.Factory<*, DatabaseModel>
-|—-> DataSource.Factory<*, PresenterModel>
Is there any way possible to achieve this. I’m also open to here any approach done using RxKotlin (RxJava).
Comments
Comment posted by Abdul
how you have bind the data to recycle view ? Are you using binding adapter for it ?
Comment posted by Arrowsome
@Abdul I use
Comment posted by Arrowsome
Thanks, I really appreciate this. I will mark you as the correct answer if nothing better comes up.
Comment posted by Abdul
that will be great.
Comment posted by DennisVA
this is a bad solution. The UI should never even get a DBModel