Commit 5cdfecd7 authored by Varun Patil's avatar Varun Patil

Get a minimal Body Fragment working

parent f5dd48aa
...@@ -68,9 +68,9 @@ public class BodyCardFragment extends Fragment { ...@@ -68,9 +68,9 @@ public class BodyCardFragment extends Fragment {
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
LinearLayout linearLayout = (LinearLayout) getView().findViewById(R.id.body_card_layout); LinearLayout linearLayout = (LinearLayout) getView().findViewById(R.id.body_card_layout);
ImageView bodyAvatar = (ImageView) getView().findViewById(R.id.body_avatar); ImageView bodyAvatar = (ImageView) getView().findViewById(R.id.body_card_avatar);
TextView bodyName = (TextView) getView().findViewById(R.id.body_name); TextView bodyName = (TextView) getView().findViewById(R.id.body_card_name);
TextView bodyDescription = (TextView) getView().findViewById(R.id.body_description); TextView bodyDescription = (TextView) getView().findViewById(R.id.body_card_description);
bodyName.setText(body.getBodyName()); bodyName.setText(body.getBodyName());
bodyDescription.setText(body.getBodyShortDescription()); bodyDescription.setText(body.getBodyShortDescription());
...@@ -80,7 +80,7 @@ public class BodyCardFragment extends Fragment { ...@@ -80,7 +80,7 @@ public class BodyCardFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
/* Show the next fragment and destroy the page */ /* Show the next fragment and destroy the page */
BodyFragment bodyFragment = BodyFragment.newInstance("Dummy", "Dummy"); BodyFragment bodyFragment = BodyFragment.newInstance(body);
bodyFragment.setArguments(getArguments()); bodyFragment.setArguments(getArguments());
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag()); ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
......
...@@ -6,8 +6,12 @@ import android.support.v4.app.Fragment; ...@@ -6,8 +6,12 @@ import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import com.google.gson.Gson;
import in.ac.iitb.gymkhana.iitbapp.R; import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.data.Body;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
...@@ -17,14 +21,12 @@ import in.ac.iitb.gymkhana.iitbapp.R; ...@@ -17,14 +21,12 @@ import in.ac.iitb.gymkhana.iitbapp.R;
public class BodyFragment extends Fragment { public class BodyFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1"; private static final String ARG_BODY = "body";
private static final String ARG_PARAM2 = "param2";
String TAG = "BodyFragment"; String TAG = "BodyFragment";
// TODO: Rename and change types of parameters // TODO: Rename and change types of parameters
private String mParam1; private Body body;
private String mParam2;
public BodyFragment() { public BodyFragment() {
...@@ -35,16 +37,14 @@ public class BodyFragment extends Fragment { ...@@ -35,16 +37,14 @@ public class BodyFragment extends Fragment {
* Use this factory method to create a new instance of * Use this factory method to create a new instance of
* this fragment using the provided parameters. * this fragment using the provided parameters.
* *
* @param param1 Parameter 1. * @param arg_body Body for details
* @param param2 Parameter 2.
* @return A new instance of fragment BodyFragment. * @return A new instance of fragment BodyFragment.
*/ */
// TODO: Rename and change types and number of parameters // TODO: Rename and change types and number of parameters
public static BodyFragment newInstance(String param1, String param2) { public static BodyFragment newInstance(Body arg_body) {
BodyFragment fragment = new BodyFragment(); BodyFragment fragment = new BodyFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1); args.putString(ARG_BODY, new Gson().toJson(arg_body));
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
} }
...@@ -53,11 +53,19 @@ public class BodyFragment extends Fragment { ...@@ -53,11 +53,19 @@ public class BodyFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (getArguments() != null) { if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1); body = new Gson().fromJson(getArguments().getString(ARG_BODY), Body.class);
mParam2 = getArguments().getString(ARG_PARAM2);
} }
} }
@Override
public void onStart() {
super.onStart();
TextView bodyName = (TextView) getView().findViewById(R.id.body_name);
bodyName.setText(body.getBodyName());
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<!-- TODO: Update blank fragment layout --> <!-- TODO: Update blank fragment layout -->
<TextView <TextView
android:id="@+id/body_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" /> android:text="@string/hello_blank_fragment" />
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:id="@+id/body_avatar" android:id="@+id/body_card_avatar"
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="80dp" android:layout_height="80dp"
android:layout_gravity="center" android:layout_gravity="center"
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/body_name" android:id="@+id/body_card_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Organization" android:text="Organization"
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
android:textSize="18sp" /> android:textSize="18sp" />
<TextView <TextView
android:id="@+id/body_description" android:id="@+id/body_card_description"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Description" /> android:text="Description" />
......
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