marker removing

This commit is contained in:
Adam Domagalski 2018-11-06 23:51:46 +01:00
parent 03235ce18b
commit 5f65d8e6fb

View File

@ -57,7 +57,10 @@ import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.mapUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -67,6 +70,7 @@ import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import timber.log.Timber;
import java.util.Locale;
import java.util.Set;
public class MapActivity extends BaseActivity
@ -90,6 +94,8 @@ public class MapActivity extends BaseActivity
private Marker droppedMarker;
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
private HashMap<String, Marker> markerHash = new HashMap<>();
private Set<String> previousCoordsIds = new HashSet<>();
private int zoomParam = 17;
private int bearingParam = 180;
@ -101,7 +107,6 @@ public class MapActivity extends BaseActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
final String authToken = sharedPref.getString("authToken", null);
@ -298,8 +303,30 @@ public class MapActivity extends BaseActivity
@Override
public void onSuccess(List<Coordinate> coordsList) {
ArrayList<String> currentCoordsIds = new ArrayList<>();
for (Coordinate coordinate : coordsList) {
currentCoordsIds.add(coordinate.getUserId());
}
// Set<String> currentCoordsIds = new HashSet<String>(tmp);
if (previousCoordsIds.isEmpty()){
previousCoordsIds.addAll(currentCoordsIds);
} else {
// here we clear + it returns bool if smthing was removed
if (previousCoordsIds.removeAll(currentCoordsIds)) {
for (String toRemoveId: previousCoordsIds) {
Log.e(tag+ "delete: " , "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
mapboxMap.removeMarker(markerHash.get(toRemoveId));
markerHash.remove(toRemoveId);
coordsMap.remove(toRemoveId);
}
} else {
Log.e(tag+ "delete: ","nothing to remove");
}
}
Log.e(tag, "");
for (Coordinate element : coordsList) {
String id = element.getUserId();
@ -348,19 +375,9 @@ public class MapActivity extends BaseActivity
}
}
/* for (Coordinate coordinate : coordsMap.values()) {
// 300000 = 5mins
if ((System.currentTimeMillis() - coordinate.getTimeStamp()) > (long) 300000) {
String id = coordinate.getUserId();
Marker markerToRemove = markerHash.get(id);
markerHash.remove(id);
coordsMap.remove(id);
mapboxMap.removeMarker(markerToRemove);
}
}*/
// For next fetch
previousCoordsIds.clear();
previousCoordsIds.addAll(currentCoordsIds);
}
@SuppressLint("LongLogTag")