Commit 2e1d0313 authored by Sajal Narang's avatar Sajal Narang

Add Associations tab to UserFragment

parent 68222b46
......@@ -25,6 +25,7 @@ public class Constants {
public static final int STATUS_NOT_GOING = 0;
public static final String BODY_JSON = "body_json";
public static final String BODY_LIST_JSON = "body_list_json";
public static final String ROLE_LIST_JSON = "role_list_json";
public static final String LOGIN_MESSAGE = "Please login to continue!";
......
......@@ -2,6 +2,7 @@ package app.insti.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
......@@ -14,6 +15,7 @@ import com.squareup.picasso.Picasso;
import java.util.List;
import app.insti.R;
import app.insti.Utils;
import app.insti.api.model.Body;
import app.insti.api.model.Role;
import app.insti.interfaces.ItemClickListener;
......@@ -22,12 +24,12 @@ import app.insti.interfaces.ItemClickListener;
public class RoleAdapter extends RecyclerView.Adapter<RoleAdapter.ViewHolder> {
private List<Role> roleList;
private ItemClickListener itemClickListener;
private Context context;
private Fragment fragment;
public RoleAdapter(List<Role> roleList, ItemClickListener itemClickListener) {
public RoleAdapter(List<Role> roleList, Fragment mFragment) {
this.roleList = roleList;
this.itemClickListener = itemClickListener;
this.fragment = mFragment;
}
@NonNull
......@@ -41,7 +43,7 @@ public class RoleAdapter extends RecyclerView.Adapter<RoleAdapter.ViewHolder> {
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
itemClickListener.onItemClick(view, postViewHolder.getAdapterPosition());
Utils.openBodyFragment(roleList.get(postViewHolder.getAdapterPosition()).getRoleBodyDetails(), fragment.getActivity());
}
});
......@@ -55,7 +57,9 @@ public class RoleAdapter extends RecyclerView.Adapter<RoleAdapter.ViewHolder> {
Body roleBody = role.getRoleBodyDetails();
holder.bodyName.setText(roleBody.getBodyName());
holder.role.setText(role.getRoleName());
Picasso.get().load(roleBody.getBodyImageURL()).into(holder.image);
Picasso.get().load(
Utils.resizeImageUrl(roleBody.getBodyImageURL())
).into(holder.image);
}
......
package app.insti.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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 app.insti.Constants;
import app.insti.R;
import app.insti.adapter.RoleAdapter;
import app.insti.api.model.Role;
/**
* A simple {@link Fragment} subclass..
* Use the {@link RoleRecyclerViewFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class RoleRecyclerViewFragment extends Fragment {
private static final String TAG = "RoleRecyclerViewFragment";
private RecyclerView recyclerView;
private RoleAdapter roleAdapter;
private List<Role> roleList;
public RoleRecyclerViewFragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static RoleRecyclerViewFragment newInstance(List<Role> roleList) {
RoleRecyclerViewFragment fragment = new RoleRecyclerViewFragment();
Bundle args = new Bundle();
args.putString(Constants.ROLE_LIST_JSON, new Gson().toJson(roleList));
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
roleList = new Gson().fromJson(getArguments().getString(Constants.ROLE_LIST_JSON), new TypeToken<List<Role>>() {
}.getType());
}
}
@Override
public void onStart() {
super.onStart();
recyclerView = (RecyclerView) getActivity().findViewById(R.id.role_recycler_view);
roleAdapter = new RoleAdapter(roleList, this);
recyclerView.setAdapter(roleAdapter);
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_role_recycler_view, container, false);
}
}
\ No newline at end of file
......@@ -134,25 +134,6 @@ public class UserFragment extends BackHandledFragment {
/* Show tabs */
getActivity().findViewById(R.id.tab_layout).setVisibility(VISIBLE);
final List<Role> roleList = user.getUserRoles();
List<Role> formerRoleList = user.getUserFormerRoles();
for (Role role : formerRoleList) {
role.setRoleName("Former " + role.getRoleName());
}
roleList.addAll(formerRoleList);
RecyclerView userRoleRecyclerView = getActivity().findViewById(R.id.role_recycler_view);
RoleAdapter roleAdapter = new RoleAdapter(roleList, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Role role = roleList.get(position);
Body roleBody = role.getRoleBodyDetails();
Utils.openBodyFragment(roleBody, getActivity());
}
});
userRoleRecyclerView.setAdapter(roleAdapter);
userRoleRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
Picasso.get()
.load(user.getUserProfilePictureUrl())
.resize(500, 0)
......@@ -167,16 +148,24 @@ public class UserFragment extends BackHandledFragment {
});
mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
final List<Role> roleList = user.getUserRoles();
final List<Body> bodyList = user.getUserFollowedBodies();
final List<Event> eventList = user.getUserGoingEvents();
final List<Event> eventInterestedList = user.getUserInterestedEvents();
List<Role> formerRoleList = user.getUserFormerRoles();
for (Role role : formerRoleList) {
role.setRoleName("Former " + role.getRoleName());
}
roleList.addAll(formerRoleList);
List<Event> eventInterestedList = user.getUserInterestedEvents();
eventList.removeAll(eventInterestedList);
eventList.addAll(eventInterestedList);
BodyRecyclerViewFragment frag1 = BodyRecyclerViewFragment.newInstance(bodyList);
EventRecyclerViewFragment frag2 = EventRecyclerViewFragment.newInstance(eventList);
RoleRecyclerViewFragment frag1 = RoleRecyclerViewFragment.newInstance(roleList);
BodyRecyclerViewFragment frag2 = BodyRecyclerViewFragment.newInstance(bodyList);
EventRecyclerViewFragment frag3 = EventRecyclerViewFragment.newInstance(eventList);
TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager());
tabAdapter.addFragment(frag1, "Following");
tabAdapter.addFragment(frag2, "Events");
tabAdapter.addFragment(frag1, "Associations");
tabAdapter.addFragment(frag2, "Following");
tabAdapter.addFragment(frag3, "Events");
// Set up the ViewPager with the sections adapter.
ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager);
viewPager.setAdapter(tabAdapter);
......
<?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.RoleRecyclerViewFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/role_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
......@@ -75,11 +75,6 @@
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/role_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
......
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