Commit 8d98957b authored by Varun Patil's avatar Varun Patil

Cache events response in memory in feed fragment

parent 37369aef
...@@ -40,16 +40,15 @@ public class FeedFragment extends BaseFragment { ...@@ -40,16 +40,15 @@ public class FeedFragment extends BaseFragment {
private RecyclerView feedRecyclerView; private RecyclerView feedRecyclerView;
private SwipeRefreshLayout feedSwipeRefreshLayout; private SwipeRefreshLayout feedSwipeRefreshLayout;
private FloatingActionButton fab; private FloatingActionButton fab;
private boolean freshEventsDisplayed = false;
LinearLayoutManager mLayoutManager; LinearLayoutManager mLayoutManager;
public static int index = -1, top = -1; public static int index = -1, top = -1;
public static List<Event> eventList = null;
private FeedAdapter feedAdapter = null; private FeedAdapter feedAdapter = null;
public FeedFragment() { public FeedFragment() {
// Required empty public constructor // Required empty public constructor
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
...@@ -76,8 +75,14 @@ public class FeedFragment extends BaseFragment { ...@@ -76,8 +75,14 @@ public class FeedFragment extends BaseFragment {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
fab = (FloatingActionButton) getView().findViewById(R.id.fab); fab = getView().findViewById(R.id.fab);
// Initialize the feed
if (eventList == null) {
updateFeed(); updateFeed();
} else {
displayEvents(eventList);
}
} }
...@@ -94,8 +99,7 @@ public class FeedFragment extends BaseFragment { ...@@ -94,8 +99,7 @@ public class FeedFragment extends BaseFragment {
public void onResume() public void onResume()
{ {
super.onResume(); super.onResume();
if(index != -1) if(index != -1) {
{
mLayoutManager.scrollToPositionWithOffset( index, top); mLayoutManager.scrollToPositionWithOffset( index, top);
} }
} }
...@@ -107,10 +111,8 @@ public class FeedFragment extends BaseFragment { ...@@ -107,10 +111,8 @@ public class FeedFragment extends BaseFragment {
@Override @Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) { public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
NewsFeedResponse newsFeedResponse = response.body(); eventList = response.body().getEvents();
List<Event> events = newsFeedResponse.getEvents(); displayEvents(eventList);
freshEventsDisplayed = true;
displayEvents(events);
} }
//Server Error //Server Error
feedSwipeRefreshLayout.setRefreshing(false); feedSwipeRefreshLayout.setRefreshing(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment