2

How to send search suggestions dynamically to data source's retrofit params and get updated pagedlist in Android jetpack paging library?

Here's my web function in retrofit web service that brings data.

@GET(version + "/get-bills")
  Call<ApiResponse<BillsModel>> getPartnerBillsSorted(@Query("page")int page, @Query("type")int  type,@Query("search")String search );

This api is being called in data source and it gives me listing of all data, which i am listing in reyclerview using pagedlist. But i am quite confused and dont know how do i give call to this api in Data source on runtime, and then get updated pagedlist based on what i am seaching in autocompleteTextview.

what should i do? should i make new instance of datasource and data source factory and pagelist everytime i tap something in autocomplete or how do i dynamically change same datasource call and get updated pagelist?

2 Answers 2

0

You do not need to to change anything in your web service. You may make a constant class(getter setter) etc and change your data source class like this.

compositeDisposable.add(
            networkService.getPartnerBillsSorted(Costant.PAGE,
            ,Costant.TYPE
            ,Costant.SEARCH
            .subscribe()

and then call this in your search complete listener in activity/fragment:

 Constants.setSearch("search result");
 viewModel.searchResultList.value.dataSource.invalidate();
0

create a field in your Datasource class(add getter, setters), pass this field to retrofit call. later if you want make another call just set the required search query to datasource instance and call .invalidate() after setting the query.

refer this article https://android.jlelse.eu/android-paging-library-make-your-lists-as-efficient-as-possible-literally-in-just-an-hour-5abf797585bd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.