Removed redudant database call

This commit is contained in:
Bennet Brunsen committed 2015-06-29 16:37:53 +02:00
1 parent 39568664f5
commit fb67a72208
2 files changed
+19 -23

No files matched your search

@@ -279,23 +279,18 @@ public class BuoyFragment extends BaseFragment implements LocationListener {
int id = v.getId();
if (id == R.id.marker_set_position_button) {
PingHelper helper = new PingHelper();
try {
if (lastKnownLocation != null) {
MarkInfo mark = positioningActivity.getMarkInfo();
LeaderboardInfo leaderBoard = positioningActivity.getLeaderBoard();
helper.storePingInDatabase(getActivity(), lastKnownLocation, mark);
helper.sendPingToServer(getActivity(), lastKnownLocation, leaderBoard, mark, PingServerReplyCallback.class);
//Toast.makeText(getActivity(), getString(R.string.position_set), Toast.LENGTH_SHORT).show();
((PositioningActivity) getActivity()).updatePing();
savedPosition = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
pingListener.updatePing();
setUpTextUI(lastKnownLocation);
updateMap();
} else {
Toast.makeText(getActivity(), "Location is not available yet", Toast.LENGTH_LONG).show();
}
} catch (GeneralDatabaseHelperException e) {
e.printStackTrace();
if (lastKnownLocation != null) {
MarkInfo mark = positioningActivity.getMarkInfo();
LeaderboardInfo leaderBoard = positioningActivity.getLeaderBoard();
helper.storePingInDatabase(getActivity(), lastKnownLocation, mark);
helper.sendPingToServer(getActivity(), lastKnownLocation, leaderBoard, mark, PingServerReplyCallback.class);
((PositioningActivity) getActivity()).updatePing();
savedPosition = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
pingListener.updatePing();
setUpTextUI(lastKnownLocation);
updateMap();
} else {
Toast.makeText(getActivity(), "Location is not available yet", Toast.LENGTH_LONG).show();
}
} else if (id == R.id.marker_reset_position_button) {
// Reset position
@@ -26,7 +26,6 @@ public class PingHelper {
fixJson.put("timestamp", location.getTime());
fixJson.put("longitude", location.getLongitude());
fixJson.put("latitude", location.getLatitude());
storePingInDatabase(context, location, mark);
String postUrlStr = leaderBoard.serverUrl + prefs.getServerMarkPingPath(leaderBoard.name, mark.getId());
@@ -35,19 +34,21 @@ public class PingHelper {
} catch (JSONException ex) {
ExLog.i(context, TAG, "Error while building ping json " + ex.getMessage());
} catch (GeneralDatabaseHelperException e) {
e.printStackTrace();
}
}
public void storePingInDatabase(Context context, Location location, MarkInfo mark)
throws GeneralDatabaseHelperException {
public Boolean storePingInDatabase(Context context, Location location, MarkInfo mark) {
MarkPingInfo pingInfo = new MarkPingInfo();
pingInfo.setMarkId(mark.getId());
pingInfo.setLatitude("" + location.getLatitude());
pingInfo.setLongitude("" + location.getLongitude());
pingInfo.setAccuracy(location.getAccuracy());
pingInfo.setTimestamp((int) location.getTime());
DatabaseHelper.getInstance().storeMarkPing(context, pingInfo);
try {
DatabaseHelper.getInstance().storeMarkPing(context, pingInfo);
} catch (GeneralDatabaseHelperException e) {
return false;
}
return true;
}
}