Commit f54afa7d authored by Varun Patil's avatar Varun Patil

Use network first strategy for BodyFragment

parent fe4b5615
......@@ -87,7 +87,7 @@ public class BodyFragment extends BackHandledFragment {
private float startScaleFinal;
private ImageView bodyPicture;
private Body body;
private boolean bodyDisplayed = false;
public BodyFragment() {
// Required empty public constructor
......@@ -136,6 +136,9 @@ public class BodyFragment extends BackHandledFragment {
body = min_body;
displayBody();
new getDbBody().execute(min_body.getBodyID());
updateBody();
bodySwipeRefreshLayout = getActivity().findViewById(R.id.body_swipe_refresh_layout);
bodySwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
......@@ -158,8 +161,11 @@ public class BodyFragment extends BackHandledFragment {
new updateDbBody().execute(bodyResponse);
if (!bodyDisplayed) {
body = bodyResponse;
displayBody();
}
if (bodySwipeRefreshLayout.isRefreshing())
bodySwipeRefreshLayout.setRefreshing(false);
}
}
......@@ -182,7 +188,8 @@ public class BodyFragment extends BackHandledFragment {
private void displayBody() {
/* Skip if we're already destroyed */
if (getView() == null) return;
if (getActivity() == null || getView() == null) return;
if(!body.equals(min_body)) bodyDisplayed = true;
TextView bodyName = (TextView) getView().findViewById(R.id.body_name);
TextView bodyDescription = (TextView) getView().findViewById(R.id.body_description);
......@@ -416,11 +423,9 @@ public class BodyFragment extends BackHandledFragment {
@Override
protected void onPostExecute(Body[] result) {
if (result.length > 0) {
if (result.length > 0 && !bodyDisplayed) {
body = result[0];
displayBody();
} else {
updateBody();
}
}
}
......
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