Commit b273f42b authored by maitreya's avatar maitreya

solves #103 added refresh layout to body fragment

parent a706c93b
......@@ -19,4 +19,5 @@ public class Constants {
public static final int STATUS_GOING = 2;
public static final int STATUS_INTERESTED = 1;
public static final int STATUS_NOT_GOING = 0;
public static final String BODY_JSON= "body_json";
}
......@@ -3,6 +3,7 @@ package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -29,13 +30,14 @@ import retrofit2.Response;
public class BodyFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_BODY = "body";
private AppDatabase appDatabase;
String TAG = "BodyFragment";
// TODO: Rename and change types of parameters
private Body min_body;
private SwipeRefreshLayout bodySwipeRefreshLayout;
public BodyFragment() {
......@@ -53,7 +55,7 @@ public class BodyFragment extends Fragment {
public static BodyFragment newInstance(Body arg_body) {
BodyFragment fragment = new BodyFragment();
Bundle args = new Bundle();
args.putString(ARG_BODY, new Gson().toJson(arg_body));
args.putString(Constants.BODY_JSON, new Gson().toJson(arg_body));
fragment.setArguments(args);
return fragment;
}
......@@ -62,7 +64,7 @@ public class BodyFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
min_body = new Gson().fromJson(getArguments().getString(ARG_BODY), Body.class);
min_body = new Gson().fromJson(getArguments().getString(Constants.BODY_JSON), Body.class);
}
}
......@@ -79,6 +81,13 @@ public class BodyFragment extends Fragment {
} else {
updateBody();
}
bodySwipeRefreshLayout=getActivity().findViewById(R.id.body_swipe_refresh_layout);
bodySwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
updateBody();
}
});
}
private void updateBody() {
......@@ -92,11 +101,13 @@ public class BodyFragment extends Fragment {
appDatabase.dbDao().insertBody(body);
displayBody(body);
bodySwipeRefreshLayout.setRefreshing(false);
}
}
@Override
public void onFailure(Call<Body> call, Throwable t) {
bodySwipeRefreshLayout.setRefreshing(false);
// Network Error
}
});
......
......@@ -121,6 +121,8 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
public void onItemClick(View v, int position) {
Body body = bodyList.get(position);
BodyFragment bodyFragment = BodyFragment.newInstance(body);
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());
......
......@@ -4,26 +4,31 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.BodyFragment">
<ScrollView
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/body_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_height="wrap_content"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="wrap_content">
<TextView
android:id="@+id/body_name"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/body_description"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/body_name"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/body_description"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
\ 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