Reputation: 9263
Currently, I'm trying to implement the paging library provided by android jetpack. But I having some troubles when getting the data from DAO. Actually, when I get the data, the PagedList
have the size of all the rows in the table!
Here my DAO:
@Dao
interface TableDao {
@Query("SELECT * FROM table")// I tried also with ORDER BY field DESC, as I saw in some examples.
fun getData(): DataSource.Factory<Int, MyEntity>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(songs: List<SongEntity>)
}
I trying to satisfy this test:
@Test
fun pageSize() {
val data = EntityFactory.makeList(50)
database.getTableDao().apply {
insertAll(data)
val pageSize = 5
RxPagedListBuilder(getData(), pageSize)
.buildObservable()
.map { it.size }
.test()
.assertValue(pageSize)
}
}
I don't know if I'm missing some context, but what I wanted to achieve was a progressive loading of the data. Any help/explanation will be very appreciated.
Upvotes: 0
Views: 678
Reputation: 9263
As pointed out by @pskink, there is no problem
The PageList
ensure the size of the table's count but finally just load items in the measure that they are loaded. In its initialization, it prefetches 3 times the page size. I adapted my test and is pass:
@Test
fun pageSize() {
val data = EntityFactory.makeList(500)
database.getTableDao().apply {
insertAll(data)
repeat(10) {
val pageSize: Int = DataFactory.randomInt(5..50)
RxPagedListBuilder(getData(), pageSize)
.buildObservable()
.map { it.filterNotNull() }
.map { it.size }
.test()
.assertValue(pageSize * 3)
}
}
}
Upvotes: 1