I have data that was insert PostKey and Rating by cloud function. Following this picture newfeed, post
and I use FirebaseIndexRecyclerAdapter to get data
FirebaseIndexRecyclerAdapter<Post, FeedFragment.PostViewHolder> firebaseIndexRecyclerAdapter = new FirebaseIndexRecyclerAdapter<Post, FeedFragment.PostViewHolder>(
Post.class,
R.layout.post_row,
FeedFragment.PostViewHolder.class,
FirebaseRef.mNewfeedRef.child(UID),
FirebaseRef.mPostRef
) {
Solution that I was thinks is
First one is orderByValue() and load StartAt(0) to EndAt(5) when scrolled to bottom it called StartAt(0) to EndAt(10) and so on but each time will load old data that could wasted traffic.
Second one is create new reference suppose is "newfeed-post" that have only top 5 items ordered by rating that get from "newfeed" and when I scroll down to load more I request to cloud function to let cloud function insert more 5 items from "newfeed" to "newfeed-post" that lower rating (eg. position 6-10).
Please help and let me know how to do this. Thanks :D
Pagination is not supported by FirebaseUI-Android components. They currently require you to provide a single query that yields all the results to display. There is no way to progressively supply more queries as a list is scrolled. Also see the discussion in this issue on the Github repo for FirebaseUI-Android.
Related
I will take an example to explain my problem : in a search screen, I need to search for a big list of movies.
I can bookmark each movie, so I need to notify my item in my recycler, here is my problem.
Do I need to put every movies searched in room database and it will be simple after for the notify with MVVM & DiffUtils?
Because, when I used MVP, I created a small database with MovieId and a boolean for bookmark, and when the user bookmark a movie, I run through in my items in adapter and notify the concerned item. But this solution is very ugly now with MVVM.
Thanks in advance
Just for the search screen you don't need to save data to local database. Instead of that you can just bind one list to RecyclerView and update it with another list from API using DiffUtils.
I need help with listview in kotlin.
I have a timer function that fetches the updated listview data every 1 minutes from the server (firebase in this case). After the firebase is done fetching the data, i apply:
listview.adapter = CustomAdapter(applicationContext)
But the problem with this is that the listview refreshes and goes up to row 1 when I may be scrolling down to row 50. This is super annoying since I have about a hundred rows.
Any body has a solution to this?
This is not relevant to Kotlin but how you use the Android APIs. You should not set a new adapter everytime the list is updated. You are just starting over from the beginning. I would recommend using RecyclerView with DiffUtil. Look at this blog for a quick example in Kotlin: https://antonioleiva.com/recyclerview-diffutil-kotlin/
I have a backend API endpoint which returns JSON in some sets. Each set contain 10 lines of Json.
For example:
curl http://www.something.com?getData=0 will give first 10 elements and curl http://www.something.com?getData=1 will return next set and so on.
I am using RecyclerView and StaggeredGridView to load data from given endpoints. Right now I am only fetching first set and it's working perfectly fine.
What I am looking for?
How can I load data in RecyclerView as per screen sizes in Android. FOr example:
Let's say device hdpi can able to load 25 staggeredGridViewin RecyclerView. So , here the endpoints request in sequence:
http://www.something.com?getData=0 // will fetch 0-10
http://www.something.com?getData=10 // will fetch 11-20
http://www.something.com?getData=10&skip=5 // will fetch 21-25
How can I make above process dynamically. So that it will work for all screen sizes?
BTW this is how I am loading the data into StaggeredGridView adapter:
mRecyclerView = (RecyclerView) mActivity.findViewById(R.id.staggering_grid);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
mAdapter = new StaggeredGridAdapter(mContext);
mAdapter.addItems(response);
mRecyclerView.setAdapter(mAdapter);
Possible Solution
If I got to know that How much Grid I need to fill according to device then I can simply make a request till I get the data to fill expected number.
I can also use Event Bus to send notification to Retrofit to make another call till device screen filled.
Is it good approach? If yes then How can I achieve it?
what you can do is load data in excess say 50 at a time instead of 10, that way you have enough data to populate the whole display, if your api only lets you get 10 items per request, then you fire multiple requests from different threads and add them to your adapter, and refresh the view once all the requests were done successfully. So this way you wont be needed to request for all the items and have enough items for display in any device screen setting
Currently, I'm using AsyncTask to handle Http connection and retrieve data as JSON format.
Loading all data is trivial but it consumes too much time, so I decided to switch to load 10 items at a time using LIMIT OFFSET (mysql).
Next I set up the event onScroll for my list view to create a new AsyncTask each time user scroll. However, from what I read, AsyncTask is stored in a thread pool which is limited 5 threads at a time, so I'm not sure this is a right approach. I'm newbie to client/server app, so could I anyone give me an advice on this issue? Any related article, documentation would be greatly appreciated.
Here are few useful links for it,
Android: Implementing progressbar and "loading..." for Endless List like Android Market
Endless Listview with current Async Task
Android Endless List
http://www.androidguys.com/2009/10/21/tutorial-autogrowing-listview/
http://mylifewithandroid.blogspot.com/2010/03/progressively-loading-listviews.html
In simple steps,
As user scrolls – detect the end of the list 1)Display a progress
notification 2)Ask for update 3)Receive update (asynchronously) and
extend list
A typical approach would be e.g. to load 25 initially and then have a footer in the list that displays e.g. the current count and the total count and upon pressing loads another 25 and so on. That would be a paged sort of loading.
When you do that you have to keep the current position and notify the adapter that the list has changed.
If you are using a ListView, I believe I can safely assume that you must be using some sort of ListAdapter. Instead of starting a new AsyncTask in the onScroll event, you should maintain just one single AsyncTask to retrieve data from the server, add that data to the ListAdapter dataset and then call notifyDatasetChanged on the ListAdapter.
The ListAdapter and ListView will take care of the rest.
I have implmented pagination and it display 5 records per page. Now suppose I am on page 3 and click 3'rd element then 3'rd element of page-1 is selected.
I am not able to figure out problem as I always create new list object while setting data.
I used below code
temp = new ArrayList();
this.someListAdapter = new SomeListAdapter(this, R.layout.row_facet,temp);
setListAdapter(this.someListAdapter );
Below is signature of SomeListAdapter class.
public class SomeListAdapter extends ArrayAdapter<VoNeighborhood> {
}
Please help....
There really aren't enough details here about how you do pagination with your ListView.
So I might guess you're overriding onListItemClick and using the position variable it sends you, but you then don't take into account the page you're on?
Alternatively, just don't use pagination as you have an infinite canvas to scroll your list within — I don't think I've recall seeing an Android app so far that uses pagination!