Commit ee8e224e authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge pull request #119 from yashkhem1/master

Added BodyRecyclerViewFragment and EventRecyclerViewFragment
parents 6a81f4a9 f7665cac
...@@ -7,6 +7,7 @@ public class Constants { ...@@ -7,6 +7,7 @@ public class Constants {
public static final int RESULT_LOAD_IMAGE = 11; public static final int RESULT_LOAD_IMAGE = 11;
public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json"; public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json";
public static final String EVENT_JSON = "event_json"; public static final String EVENT_JSON = "event_json";
public static final String EVENT_LIST_JSON = "event_list_json";
public static final String USER_ID = "user_id"; public static final String USER_ID = "user_id";
public static final String USER_HOSTEL = "user_hostel"; public static final String USER_HOSTEL = "user_hostel";
public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer"; public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer";
...@@ -19,5 +20,6 @@ public class Constants { ...@@ -19,5 +20,6 @@ public class Constants {
public static final int STATUS_GOING = 2; public static final int STATUS_GOING = 2;
public static final int STATUS_INTERESTED = 1; public static final int STATUS_INTERESTED = 1;
public static final int STATUS_NOT_GOING = 0; public static final int STATUS_NOT_GOING = 0;
public static final String BODY_JSON= "body_json"; public static final String BODY_JSON = "body_json";
public static final String BODY_LIST_JSON = "body_list_json";
} }
package in.ac.iitb.gymkhana.iitbapp.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class TabAdapter extends FragmentStatePagerAdapter {
private final List<Fragment> list_fragment = new ArrayList<>();
private final List<String> list_title = new ArrayList<>();
public void addFragment(Fragment fragment, String title) {
list_fragment.add(fragment);
list_title.add(title);
}
public TabAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return list_title.get(position);
}
@Override
public Fragment getItem(int position) {
return list_fragment.get(position);
}
@Override
public int getCount() {
return list_fragment.size();
}
}
\ 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.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 TAG = "BodyRecyclerViewFragment";
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> bodyList) {
BodyRecyclerViewFragment fragment = new BodyRecyclerViewFragment();
Bundle args = new Bundle();
args.putString(Constants.BODY_LIST_JSON, new Gson().toJson(bodyList));
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
bodyList = new Gson().fromJson(getArguments().getString(Constants.BODY_LIST_JSON
), 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 TAG = "EventRecyclerViewFragment";
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> eventList) {
EventRecyclerViewFragment fragment = new EventRecyclerViewFragment();
Bundle args = new Bundle();
args.putString(Constants.EVENT_LIST_JSON, new Gson().toJson(eventList));
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
eventList = new Gson().fromJson(getArguments().getString(Constants.EVENT_LIST_JSON), 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
...@@ -2,8 +2,10 @@ package in.ac.iitb.gymkhana.iitbapp.fragment; ...@@ -2,8 +2,10 @@ package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -21,10 +23,12 @@ import in.ac.iitb.gymkhana.iitbapp.Constants; ...@@ -21,10 +23,12 @@ import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener; import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.R; import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.adapter.RoleAdapter; import in.ac.iitb.gymkhana.iitbapp.adapter.RoleAdapter;
import in.ac.iitb.gymkhana.iitbapp.adapter.TabAdapter;
import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface; import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface;
import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator; import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator;
import in.ac.iitb.gymkhana.iitbapp.api.UnsafeOkHttpClient; import in.ac.iitb.gymkhana.iitbapp.api.UnsafeOkHttpClient;
import in.ac.iitb.gymkhana.iitbapp.data.Body; import in.ac.iitb.gymkhana.iitbapp.data.Body;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
import in.ac.iitb.gymkhana.iitbapp.data.Role; import in.ac.iitb.gymkhana.iitbapp.data.Role;
import in.ac.iitb.gymkhana.iitbapp.data.User; import in.ac.iitb.gymkhana.iitbapp.data.User;
import retrofit2.Call; import retrofit2.Call;
...@@ -97,6 +101,7 @@ public class ProfileFragment extends BaseFragment { ...@@ -97,6 +101,7 @@ public class ProfileFragment extends BaseFragment {
userRoleRecyclerView.setAdapter(roleAdapter); userRoleRecyclerView.setAdapter(roleAdapter);
userRoleRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); userRoleRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
Picasso.Builder picassoBuilder = new Picasso.Builder(getContext()); Picasso.Builder picassoBuilder = new Picasso.Builder(getContext());
picassoBuilder.downloader( picassoBuilder.downloader(
new OkHttp3Downloader(( new OkHttp3Downloader((
...@@ -106,9 +111,30 @@ public class ProfileFragment extends BaseFragment { ...@@ -106,9 +111,30 @@ public class ProfileFragment extends BaseFragment {
Picasso picasso = picassoBuilder.build(); Picasso picasso = picassoBuilder.build();
picasso.load(user.getUserProfilePictureUrl()).into(userProfilePictureImageView); picasso.load(user.getUserProfilePictureUrl()).into(userProfilePictureImageView);
final List<Body> bodyList = user.getUserFollowedBodies();
final List<Event> eventList = user.getUserGoingEvents();
final List<Event> eventInterestedList = user.getUserInterestedEvents();
eventList.removeAll(eventInterestedList);
eventList.addAll(eventInterestedList);
BodyRecyclerViewFragment frag1 = BodyRecyclerViewFragment.newInstance(bodyList);
EventRecyclerViewFragment frag2 = EventRecyclerViewFragment.newInstance(eventList);
TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager());
tabAdapter.addFragment(frag1,"Following");
tabAdapter.addFragment(frag2, "Events");
// Set up the ViewPager with the sections adapter.
ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager);
viewPager.setAdapter(tabAdapter);
viewPager.setOffscreenPageLimit(2);
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(viewPager);
userNameTextView.setText(user.getUserName()); userNameTextView.setText(user.getUserName());
userRollNumberTextView.setText(user.getUserRollNumber()); userRollNumberTextView.setText(user.getUserRollNumber());
userEmailIDTextView.setText(user.getUserEmail()); userEmailIDTextView.setText(user.getUserEmail());
userContactNumberTextView.setText(user.getUserContactNumber()); userContactNumberTextView.setText(user.getUserContactNumber());
} }
} }
<?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">
<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