Commit 34882f0e authored by Sajal Narang's avatar Sajal Narang
parents 2ce39c9f c8c8b0b3
......@@ -45,7 +45,8 @@ public class FeedFragment extends BaseFragment {
private AppDatabase appDatabase;
private FloatingActionButton fab;
private boolean freshEventsDisplayed = false;
LinearLayoutManager mLayoutManager;
public static int index = -1, top = -1;
public FeedFragment() {
// Required empty public constructor
}
......@@ -60,7 +61,9 @@ public class FeedFragment extends BaseFragment {
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Feed");
feedRecyclerView = view.findViewById(R.id.feed_recycler_view);
mLayoutManager = new LinearLayoutManager(getContext());
feedRecyclerView.setLayoutManager(mLayoutManager);
feedSwipeRefreshLayout = view.findViewById(R.id.feed_swipe_refresh_layout);
feedSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
......@@ -77,13 +80,31 @@ public class FeedFragment extends BaseFragment {
super.onStart();
appDatabase = AppDatabase.getAppDatabase(getContext());
new showEventsFromDB().execute();
fab = (FloatingActionButton) getView().findViewById(R.id.fab);
feedRecyclerView = getView().findViewById(R.id.feed_recycler_view);
updateFeed();
}
@Override
public void onPause()
{
super.onPause();
index = mLayoutManager.findFirstVisibleItemPosition();
View v = feedRecyclerView.getChildAt(0);
top = (v == null) ? 0 : (v.getTop() - feedRecyclerView.getPaddingTop());
}
@Override
public void onResume()
{
super.onResume();
if(index != -1)
{
mLayoutManager.scrollToPositionWithOffset( index, top);
}
}
private void updateFeed() {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNewsFeed("sessionid=" + getArguments().getString(Constants.SESSION_ID)).enqueue(new Callback<NewsFeedResponse>() {
......@@ -160,7 +181,7 @@ public class FeedFragment extends BaseFragment {
public void run(Activity pActivity) {
try {
feedRecyclerView.setAdapter(feedAdapter);
feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
//feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
} catch (NullPointerException e) {
e.printStackTrace();
......
......@@ -43,7 +43,7 @@ public class MessMenuFragment extends BaseFragment {
private SwipeRefreshLayout messMenuSwipeRefreshLayout;
private AppDatabase appDatabase;
private Spinner hostelSpinner;
private String hostel;
public MessMenuFragment() {
// Required empty public constructor
......@@ -64,7 +64,7 @@ public class MessMenuFragment extends BaseFragment {
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Mess Menu");
final String hostel = (String) getArguments().get(Constants.USER_HOSTEL);
hostel = (String) getArguments().get(Constants.USER_HOSTEL);
displayMenu(hostel);
messMenuSwipeRefreshLayout = getActivity().findViewById(R.id.mess_menu_swipe_refresh_layout);
......@@ -83,11 +83,12 @@ public class MessMenuFragment extends BaseFragment {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if (i == 16)
displayMenu("tansa");
hostel = "tansa";
else if (i == 17)
displayMenu("qip");
hostel = "qip";
else
displayMenu(Integer.toString(i + 1));
hostel = Integer.toString(i + 1);
displayMenu(hostel);
}
@Override
......@@ -119,7 +120,8 @@ public class MessMenuFragment extends BaseFragment {
if (response.isSuccessful()) {
List<HostelMessMenu> instituteMessMenu = response.body();
HostelMessMenu hostelMessMenu = findMessMenu(instituteMessMenu, hostel);
displayMessMenu(hostelMessMenu);
if(hostelMessMenu != null)
displayMessMenu(hostelMessMenu);
new updateDatabase().execute(instituteMessMenu);
}
......
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