Add default icon for each type of localization
This commit is contained in:
parent
fca6cd936c
commit
73fc5f9b0b
@ -153,9 +153,10 @@ public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private void loginProcess(String email, String password) {
|
||||
ValidateUser user = new ValidateUser(email, password);
|
||||
/*ValidateUser user = new ValidateUser(email, password);*/
|
||||
LdapUser user = new LdapUser("Mieszko","asdasdsa","admin","tutor","Mieszko", "Wrzeszczyński", "email@op.pl");
|
||||
|
||||
disposable.add(ldapService.validate(user)
|
||||
disposable.add(ldapService.fakeValidate(user)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
|
@ -41,8 +41,10 @@ import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.MapMarker;
|
||||
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;
|
||||
@ -61,8 +63,7 @@ import timber.log.Timber;
|
||||
|
||||
public class MapActivity extends BaseActivity
|
||||
implements PermissionsListener, OnMapReadyCallback {
|
||||
|
||||
|
||||
|
||||
private String tag = getClass().getName();
|
||||
private PermissionsManager permissionsManager;
|
||||
private LocationComponent locationComponent;
|
||||
@ -82,7 +83,7 @@ public class MapActivity extends BaseActivity
|
||||
private Marker tmpLocalMarker;
|
||||
private Coordinate droppedMarkercoordinate;
|
||||
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
|
||||
private HashMap<String, Marker> markerHash = new HashMap<>();
|
||||
private HashMap<String, MapMarker> markerHash = new HashMap<>();
|
||||
private Set<String> previousCoordsIds = new HashSet<>();
|
||||
|
||||
// Camera Animation params
|
||||
@ -112,9 +113,6 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
|
||||
selectLocationButton = findViewById(R.id.select_location_button);
|
||||
removeLocationButton = findViewById(R.id.remove_location_button);
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
@ -157,7 +155,6 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
setToggleMapBoundsArea();
|
||||
setOnMapLongClickListener();
|
||||
// addStaticLayer();
|
||||
}
|
||||
|
||||
private void setToggleMapBoundsArea() {
|
||||
@ -333,7 +330,6 @@ public class MapActivity extends BaseActivity
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
|
||||
if (coordsList.isEmpty() && tmpLocalMarker != null) {
|
||||
Timber.e("200 empty []");
|
||||
mapboxMap.clear();
|
||||
@ -346,6 +342,7 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
|
||||
Set<String> currentCoordsIds = new HashSet<>(tmp);
|
||||
|
||||
if (previousCoordsIds.isEmpty()) {
|
||||
previousCoordsIds.addAll(currentCoordsIds);
|
||||
} else {
|
||||
@ -353,7 +350,7 @@ public class MapActivity extends BaseActivity
|
||||
if (previousCoordsIds.removeAll(currentCoordsIds)) {
|
||||
for (String toRemoveId : previousCoordsIds) {
|
||||
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
||||
mapboxMap.removeMarker(markerHash.get(toRemoveId));
|
||||
mapboxMap.removeMarker(markerHash.get(toRemoveId).getMarker());
|
||||
markerHash.remove(toRemoveId);
|
||||
coordsMap.remove(toRemoveId);
|
||||
}
|
||||
@ -367,6 +364,7 @@ public class MapActivity extends BaseActivity
|
||||
for (Coordinate element : coordsList) {
|
||||
String id = element.getUserId();
|
||||
String newLabel = element.getLabel();
|
||||
String newSharingLevel = element.getDisplayMode();
|
||||
|
||||
Coordinate coordinate = coordsMap.get(id);
|
||||
Log.e(tag, "hashMapSize: " + coordsMap.size());
|
||||
@ -375,11 +373,13 @@ public class MapActivity extends BaseActivity
|
||||
if (coordinate != null) {
|
||||
Log.e(tag, "Coordin: " + coordinate.getLatitude() + " | " + coordinate.getLongitude());
|
||||
|
||||
boolean statement = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
|
||||
Log.e(tag, "diff || diff: " + !statement);
|
||||
if (!statement) {
|
||||
|
||||
boolean isTheSameLocalisation = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
|
||||
Log.e(tag, "diff || diff: " + !isTheSameLocalisation);
|
||||
|
||||
if (!isTheSameLocalisation) {
|
||||
Log.e(tag, "replace and animate");
|
||||
Marker marker = markerHash.get(id);
|
||||
Marker marker = markerHash.get(id).getMarker();
|
||||
|
||||
LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude());
|
||||
// TODO fix flickiering markers
|
||||
@ -398,25 +398,72 @@ public class MapActivity extends BaseActivity
|
||||
marker.setPosition(toDestination);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
Log.e(tag, "Marker Added: " + id);
|
||||
|
||||
coordsMap.put(id, element);
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.title(id)
|
||||
.position(new LatLng(element.getLatitude(), element.getLongitude()));
|
||||
/*
|
||||
// Check if this is me
|
||||
if (id.equals(myID)) {
|
||||
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker);
|
||||
markerOptions.setIcon(icon);
|
||||
} */
|
||||
|
||||
String sharingLevel = coordsMap.get(id).getDisplayMode();
|
||||
Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
|
||||
|
||||
if(sharingLevel.equals(SharingLevel.APPROXIMATED.toString())){
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker);
|
||||
}else if(sharingLevel.equals(SharingLevel.MANUAL.toString())){
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
|
||||
}else if(id.equals(myID)){
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
|
||||
}
|
||||
Marker marker = mapboxMap.addMarker(markerOptions);
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.title(id)
|
||||
.setIcon(defaultIcon)
|
||||
.position(new LatLng(element.getLatitude(), element.getLongitude()));
|
||||
|
||||
Marker markerMapbox = mapboxMap.addMarker(markerOptions);
|
||||
MapMarker marker = new MapMarker(markerMapbox, markerOptions, defaultIcon, sharingLevel);
|
||||
|
||||
markerHash.put(id, marker);
|
||||
}
|
||||
|
||||
coordsMap.get(id).setLabel(newLabel);
|
||||
|
||||
|
||||
boolean newLocalizationMode = coordsMap.get(id).getDisplayMode().equals(newSharingLevel);
|
||||
|
||||
if(newLocalizationMode){
|
||||
Log.e("LOC","Nowy tryb" + coordsMap.get(id).getDisplayMode().toString() + " " + newSharingLevel );
|
||||
coordsMap.get(id).setDisplayMode(newSharingLevel);
|
||||
|
||||
MapMarker marker = markerHash.get(id);
|
||||
|
||||
Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
|
||||
|
||||
if(newSharingLevel.equals(SharingLevel.APPROXIMATED.toString())){
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker);
|
||||
}else if(newSharingLevel.equals(SharingLevel.MANUAL.toString())){
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
|
||||
}else if(id.equals(myID)){
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
|
||||
}
|
||||
|
||||
marker.setDefaultIcon(defaultIcon);
|
||||
marker.restoreDefaultIcon();
|
||||
|
||||
// chba niepotrzbene
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// For next fetch
|
||||
@ -562,7 +609,6 @@ public class MapActivity extends BaseActivity
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
// permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -609,23 +655,25 @@ public class MapActivity extends BaseActivity
|
||||
private void filterMarkers(List<User> users) {
|
||||
restoreMapMarkers();
|
||||
|
||||
Icon icon1 = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
|
||||
Icon markedMarker = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
|
||||
|
||||
List<Marker> markersToSet = Stream.of(mapboxMap.getMarkers())
|
||||
.filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(m.getTitle())))
|
||||
List<MapMarker> markersToSet = Stream.of(markerHash.values())
|
||||
.filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(m.getMarker().getTitle())))
|
||||
.toList();
|
||||
|
||||
for (Marker marker : markersToSet) {
|
||||
marker.setIcon(icon1);
|
||||
for (MapMarker marker : markersToSet) {
|
||||
marker.getMarker().setIcon(markedMarker);
|
||||
}
|
||||
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
public void restoreMapMarkers() {
|
||||
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
|
||||
|
||||
for (Marker marker : mapboxMap.getMarkers()) {
|
||||
marker.setIcon(icon);
|
||||
for (MapMarker marker : markerHash.values()) {
|
||||
marker.restoreDefaultIcon();
|
||||
}
|
||||
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
|
||||
public class MapMarker {
|
||||
|
||||
private MarkerOptions markerOptions;
|
||||
private Marker marker;
|
||||
private String markerType;
|
||||
private Icon defaultIcon;
|
||||
private Icon markerIcon;
|
||||
|
||||
|
||||
public MapMarker(Marker marker, MarkerOptions markerOptions, Icon icon, String markerType) {
|
||||
this.setMarker(marker);
|
||||
this.setMarkerOptions(markerOptions);
|
||||
this.defaultIcon = icon;
|
||||
this.markerType = markerType;
|
||||
}
|
||||
|
||||
public void restoreDefaultIcon() {
|
||||
this.marker.setIcon(this.defaultIcon);
|
||||
}
|
||||
|
||||
public void setDefaultIcon(Icon icon) {
|
||||
this.defaultIcon = icon;
|
||||
}
|
||||
|
||||
private void changeMarkerType(String markerType) {
|
||||
this.markerType = markerType;
|
||||
}
|
||||
|
||||
public MarkerOptions getMarkerOptions() {
|
||||
return markerOptions;
|
||||
}
|
||||
|
||||
private void setMarkerOptions(MarkerOptions marker) {
|
||||
this.markerOptions = marker;
|
||||
}
|
||||
|
||||
public Marker getMarker() {
|
||||
return marker;
|
||||
}
|
||||
|
||||
public void setMarker(Marker marker) {
|
||||
this.marker = marker;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user