Commit ac2917bb authored by Yash Khemchandani's avatar Yash Khemchandani

Added BodyRecyclerViewFragment and EventRecyclerViewFragment

parent b5c1aa9d
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.adapter.BodyAdapter;
import in.ac.iitb.gymkhana.iitbapp.data.Body;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* to handle interaction events.
* Use the {@link BodyRecyclerViewFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BodyRecyclerViewFragment extends Fragment {
private static final String ARG_BODY = "bodies";
private RecyclerView recyclerView;
private BodyAdapter bodyAdapter;
private List<Body> bodyList;
public BodyRecyclerViewFragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static BodyRecyclerViewFragment newInstance(List<Body> arg_bodyList) {
BodyRecyclerViewFragment fragment = new BodyRecyclerViewFragment();
Bundle args = new Bundle();
args.putString(ARG_BODY, new Gson().toJson(arg_bodyList));
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
bodyList = new Gson().fromJson(getArguments().getString(ARG_BODY), new TypeToken<List<Body>>(){}.getType());
}
}
@Override
public void onStart() {
super.onStart();
recyclerView = (RecyclerView) getActivity().findViewById(R.id.body_recycler_view);
bodyAdapter = new BodyAdapter(bodyList, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Body body = bodyList.get(position);
BodyFragment bodyFragment = new BodyFragment();
Bundle arguments=getArguments();
arguments.putString(Constants.BODY_JSON,new Gson().toJson(body));
bodyFragment.setArguments(getArguments());
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
ft.addToBackStack(bodyFragment.getTag());
ft.commit();
}
});
recyclerView.setAdapter(bodyAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_body_recycler_view, container, false);
}
}
\ No newline at end of file
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.adapter.FeedAdapter;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* to handle interaction events.
* Use the {@link EventRecyclerViewFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class EventRecyclerViewFragment extends Fragment {
private static final String ARG_EVENT= "events";
private RecyclerView recyclerView;
private FeedAdapter feedAdapter;
private List<Event> eventList;
public EventRecyclerViewFragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static EventRecyclerViewFragment newInstance(List<Event> arg_eventList) {
EventRecyclerViewFragment fragment = new EventRecyclerViewFragment();
Bundle args = new Bundle();
args.putString(ARG_EVENT, new Gson().toJson(arg_eventList));
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
eventList = new Gson().fromJson(getArguments().getString(ARG_EVENT), new TypeToken<List<Event>>(){}.getType());
}
}
@Override
public void onStart() {
super.onStart();
recyclerView = (RecyclerView) getActivity().findViewById(R.id.event_recycler_view);
feedAdapter = new FeedAdapter(eventList, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Event event = eventList.get(position);
EventFragment eventFragment = new EventFragment();
Bundle arguments=getArguments();
arguments.putString(Constants.EVENT_JSON,new Gson().toJson(event));
eventFragment.setArguments(getArguments());
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
ft.addToBackStack(eventFragment.getTag());
ft.commit();
}
});
recyclerView.setAdapter(feedAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_event_recycler_view, container, false);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragment.BodyRecyclerViewFragment">
<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
android:id="@+id/body_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/event_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
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