From 381373b4b7050464eedbe222de16649768217bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Wed, 5 Dec 2018 23:38:13 +0100 Subject: [PATCH] Fetch markers only when screen is on --- .../wmi/findmytutor/activity/MapActivity.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index 8e89d40..5a783ec 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -49,10 +49,10 @@ import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.utils.ApproximatedLocalization; import com.uam.wmi.findmytutor.utils.ManualLocationUtils; import com.uam.wmi.findmytutor.utils.MapMarker; +import com.uam.wmi.findmytutor.utils.MapUtils; import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.SharingLevel; -import com.uam.wmi.findmytutor.utils.MapUtils; import java.util.ArrayList; import java.util.HashMap; @@ -100,6 +100,7 @@ public class MapActivity extends BaseActivity private String myId; private boolean isTutor; private ApproximatedLocalization approximatedLocalization; + private boolean shouldFetchNewCoords = true; @Override protected void onCreate(Bundle savedInstanceState) { @@ -115,7 +116,9 @@ public class MapActivity extends BaseActivity mStatusChecker = () -> { try { - fetchTopCoords(); + if (shouldFetchNewCoords) { + fetchTopCoords(); + } } finally { mHandler.postDelayed(mStatusChecker, mInterval); } @@ -226,7 +229,7 @@ public class MapActivity extends BaseActivity private void showError(Throwable e) { String message; - Log.e("ERR",e.toString()); + Log.e("ERR", e.toString()); if (e instanceof HttpException) { ResponseBody responseBody = ((HttpException) e).response().errorBody(); @@ -372,7 +375,7 @@ public class MapActivity extends BaseActivity private void SaveCurrentManualLocation(PredefinedCoordViewModel resp) { Toast.makeText(getApplicationContext(), R.string.location_saved, Toast.LENGTH_SHORT).show(); - PrefUtils.putCurrentManualLocation(getApplicationContext(),resp.getPredefinedCoordinateId()); + PrefUtils.putCurrentManualLocation(getApplicationContext(), resp.getPredefinedCoordinateId()); } private void fetchTopCoords() { @@ -389,7 +392,7 @@ public class MapActivity extends BaseActivity public void onSuccess(List coordsList) { if (tmpLocalMarker != null && coordsList.isEmpty()) { - Timber.e("200 empty []"); + Log.e("MapActivity", "200 empty []"); mapboxMap.clear(); } @@ -592,6 +595,7 @@ public class MapActivity extends BaseActivity public void onResume() { super.onResume(); mapView.onResume(); + shouldFetchNewCoords = true; } @Override @@ -604,12 +608,15 @@ public class MapActivity extends BaseActivity protected void onStop() { super.onStop(); mapView.onStop(); + shouldFetchNewCoords = false; + } @Override public void onPause() { super.onPause(); mapView.onPause(); + shouldFetchNewCoords = false; } @Override @@ -723,6 +730,6 @@ public class MapActivity extends BaseActivity } public void adjustMapToSearch(Integer zoom) { - MapUtils.setZoom(mapboxMap,zoom); + MapUtils.setZoom(mapboxMap, zoom); } }