android-paging

LiveData Paged List size is always 0

梦想的初衷 提交于 2020-05-27 06:15:10
问题 I implemented Paging using android paging library. The ViewModel returns a LiveData<PagedList<MyObject>> and I observe that in the fragment where I set the adapter and everything is working good, except that when I want to check the size of the list is always 0. viewModel.getSearchResults().observe(this, mList -> { adapter.submitList(mList); Log.e("Count", String.valueOf(mList.size())); }); Where mList is a PagedList<MyObject> 回答1: If you look at Loading Data from PagedList documentation you

How to remove an item from PagedListAdapter in Android Paging Component

情到浓时终转凉″ 提交于 2020-05-10 04:06:24
问题 I used Paging with Retrofit to loading list of Notifications data from REST API. When I press delete button of a notification item then I call delete API to remove it. What is the proper way to remove it from PagedListAdapter after delete API response success? PagedList or PagedListAdapter does not support remove the item by index or object. I tried to call DataSource.validate() but it reloads from begin, not from the current page. 回答1: According to the official doc: If you have more granular

How to remove an item from PagedListAdapter in Android Paging Component

半世苍凉 提交于 2020-05-10 04:06:20
问题 I used Paging with Retrofit to loading list of Notifications data from REST API. When I press delete button of a notification item then I call delete API to remove it. What is the proper way to remove it from PagedListAdapter after delete API response success? PagedList or PagedListAdapter does not support remove the item by index or object. I tried to call DataSource.validate() but it reloads from begin, not from the current page. 回答1: According to the official doc: If you have more granular

Invalidating custom PageKeyedDataSource makes recycler view jump

坚强是说给别人听的谎言 提交于 2020-04-18 05:35:30
问题 I am trying to implement an android paging library with custom PageKeyedDataSource, This data source will query the data from Database and insert Ads randomly on that page. I implemented the paging, but whenever I scroll past the second page and invalidate the data source, the recycler view jumps back to the end of the second page. What is the reason for this? DataSource: class ColorsDataSource( private val colorsRepository: ColorsRepository ) : PageKeyedDataSource<Int, ColorEntity>() {

Passing variable to paging library class

梦想的初衷 提交于 2020-01-24 17:07:49
问题 I am creating an app with Android Paging Library. I'm using retrofit with it. Retrofit code is in ItemDataSource and there i can't pass variable to it. I have some variable coming with intent. How can i set my variable in Retrofit Post method. ItemDataSource public class ItemDataSource extends PageKeyedDataSource<Integer, Item> { //we will start from the first page which is 1 private static final int PAGE_NUMBER = 1; //this will be called once to load the initial data String table

Searching a LiveData of PagedList in RecyclerView by Observing ViewModel

人盡茶涼 提交于 2020-01-24 03:40:06
问题 With android Paging library it is really easy to load data from Database in chunks and ViewModel provides automatic UI update and data survival. All these frameworks modules help us create a great app in android platform. A typical android app has to show a list of items and allows user to search that list. And this what I want to achieve with my app. So I have done an implementation by reading many documentations, tutorials and even stackoverflow answers. But I am not so sure whether I am

androidx.paging.PagedStorage.init is giving error when proguard is enabled

梦想的初衷 提交于 2020-01-23 19:01:25
问题 I'm using retrofit with okhttp and migrated to AndroidX, When I make a signed app that obfuscated with proguard it crashes and gives an error,but in debug mode when proguard is not enabled it's working good. and I disabled proguard just for testing and made a signed APK it's working this way too. so I'm sure the crash is caused by Proguard. And I did some search on google they all say that I have to add proguard rules for both OKHTTP and Retrofit I did add them too but it still crashes. The

Paging library returns empty list initially

﹥>﹥吖頭↗ 提交于 2020-01-21 04:05:29
问题 I'm using Paging library to paginate a list of items I'm retrieving from my server. Initially, when my fragment is loaded, it returns an empty list. But after changing fragments and going back to that fragment, I can see the list loaded. After debugging I saw that data was actually being fetched, but an empty list was passed to my fragment. ItemDataSource: @Override public void loadInitial(@NonNull LoadInitialParams<Integer> params, @NonNull LoadInitialCallback<Integer, Item> callback) {

Paging library DataSource.Factory for multiple data sources

放肆的年华 提交于 2020-01-13 02:45:14
问题 The new paging library allows us to specify a custom data source to use with data pagination. Paging library documentation and sample code on github show us how to create your custom data source instances by creating a subclass of DataSource.Factory like so: class ConcertTimeDataSourceFactory(private val concertStartTime: Date) : DataSource.Factory<Date, Concert>() { val sourceLiveData = MutableLiveData<ConcertTimeDataSource>() override fun create(): DataSource<Date, Concert> { val source =

How to use paging library with Room Dao without using any View classes

流过昼夜 提交于 2020-01-06 03:57:09
问题 I have an android service (no UI) with a class FooManager that needs to fetch all Foo objects (rows) in a database table foo using room and the androidx paging library. All examples I have found show how to do this using the PagedListAdapter and RecyclerView. Since I have no UI I cannot use view classes. Here is what I have tried: In my FooDao class I have the following method: @Query("SELECT * FROM foo") DataSource.Factory<Integer, Foo> getAllPaged(); In the constructor for my FooManager