The first activity is a News Feed screen, where RecyclerView + Firestore is used. I have the Settings Offlline option enabled.
Problem:
Because it is an application home page and a newscast, I would like the application to display the cached data while internally scanning and retrieving the Firestore data. Like Instagram, Twitter, etc ...
Because currently when opening this activity, it is already called Firestore Query and mounted the data with RecyclerView.
It would have some way of showing the cached data of the last update of Recyclerview while the new data of the Firestore is loaded.
Because when the internet connection is mobile, the quality is very poor in our country. And if I leave calling Recyclerview initially, I'd have a loading Progressbar for a long time, until the connection stabilizes.
My code is: Adapter Firestore + RecyclerView
EDIT CODE:
/*Firebase*/
mDb = FirebaseFirestore.getInstance();
mDb.collection("IndexTimeline_User").document(mCurrentUser.getUid()).collection("Posts").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot documentSnapshots) {
mQuery = documentSnapshots.getQuery();
mCardFeedList.setAdapter(mAdapter);
}
});
mDb.setFirestoreSettings(settings);
/* Recycler */
mCardFeedList = (RecyclerView) view.findViewById(R.id.explore_tab1_list);
mCardFeedList.setHasFixedSize(true);
mCardFeedList.setItemViewCacheSize(20);
mCardFeedList.setDrawingCacheEnabled(true);
mAdapter = new PostsExploreTab1Adapter(mQuery, this){
@Override
protected void onDataChanged() {
if (getItemCount() == 0) {
mCardFeedList.setVisibility(View.GONE);
mProgressBar.setVisibility(View.GONE);
//mTxtVazio.setVisibility(View.VISIBLE);
} else {
mCardFeedList.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
//mTxtVazio.setVisibility(View.GONE);
}
}
};
llmanager = new LinearLayoutManager(getActivity());
mCardFeedList.setLayoutManager(llmanager);
/*INICIADO O RECYCLERVIEW E ADAPTER*/
if (mAdapter != null) {
mAdapter.startListening();
}
Thanks.