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