Add new markers

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-24 00:11:06 +01:00
parent 422b1079da
commit aef7174d90
5 changed files with 40 additions and 52 deletions

View File

@ -178,11 +178,12 @@ public class MapActivity extends BaseActivity
disposable.add(userService.getUserById(userId) disposable.add(userService.getUserById(userId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::createMarkerModal, this::handleError)); .subscribe(this::createMarkerModalView, this::handleError));
} }
private void createMarkerModal(User user) { private void createMarkerModalView(User user) {
String cordStatus = coordsMap.get(user.getId()).getLabel(); String cordStatus = coordsMap.get(user.getId()).getLabel();
String sharingLevel = coordsMap.get(user.getId()).getDisplayMode();
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.marker_modal, null); @SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.marker_modal, null);
@ -196,12 +197,13 @@ public class MapActivity extends BaseActivity
TextView userName = view.findViewById(R.id.userName); TextView userName = view.findViewById(R.id.userName);
TextView status = view.findViewById(R.id.label); TextView status = view.findViewById(R.id.label);
TextView sharingLevelView = view.findViewById(R.id.sharing_level);
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName())); userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
status.setText(String.format("%s ", cordStatus)); status.setText(String.format("%s: %s", getResources().getString(R.string.status_switch_title), cordStatus));
sharingLevelView.setText(String.format("%s: %s", getResources().getString(R.string.settings_location_level), sharingLevel));
final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
alertDialog.show(); alertDialog.show();
} }
@ -348,9 +350,9 @@ public class MapActivity extends BaseActivity
previousCoordsIds.addAll(currentCoordsIds); previousCoordsIds.addAll(currentCoordsIds);
} else { } else {
// here we clear + it returns bool if sth was removed // here we clear + it returns bool if sth was removed
if (previousCoordsIds.removeAll(currentCoordsIds)) { if (previousCoordsIds.removeAll(currentCoordsIds)) {
for (String toRemoveId : previousCoordsIds) { for (String toRemoveId : previousCoordsIds) {
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
mapboxMap.removeMarker(markerHash.get(toRemoveId).getMarker()); mapboxMap.removeMarker(markerHash.get(toRemoveId).getMarker());
markerHash.remove(toRemoveId); markerHash.remove(toRemoveId);
coordsMap.remove(toRemoveId); coordsMap.remove(toRemoveId);
@ -361,24 +363,19 @@ public class MapActivity extends BaseActivity
} }
} }
for (Coordinate element : coordsList) { for (Coordinate element : coordsList) {
String id = element.getUserId(); String id = element.getUserId();
String newLabel = element.getLabel(); String newLabel = element.getLabel();
String newSharingLevel = element.getDisplayMode(); String newSharingLevel = element.getDisplayMode();
Coordinate coordinate = coordsMap.get(id); Coordinate coordinate = coordsMap.get(id);
/* Log.e(tag, "hashMapSize: " + coordsMap.size());
Log.e(tag, "markerMapSize: " + coordsMap.size());*/
if (coordinate != null) { if (coordinate != null) {
Log.e(tag, "Coordin: " + coordinate.getLatitude() + " | " + coordinate.getLongitude());
boolean isTheSameLocalization = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude()); boolean isTheSameLocalization = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
Log.e(tag, "diff || diff: " + !isTheSameLocalization);
if (!isTheSameLocalization) { if (!isTheSameLocalization) {
Log.e(tag, "replace and animate"); //Replace prev marker and animate
Marker marker = markerHash.get(id).getMarker(); Marker marker = markerHash.get(id).getMarker();
LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude()); LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude());
@ -398,25 +395,18 @@ public class MapActivity extends BaseActivity
} }
} else { } else {
Log.e(tag, "Marker Added: " + id); //Add new marker
coordsMap.put(id, element); coordsMap.put(id, element);
/*
// 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(); String sharingLevel = coordsMap.get(id).getDisplayMode();
Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker); Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
if(sharingLevel.equals(SharingLevel.APPROXIMATED.toString())){ if (sharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker); defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker);
}else if(sharingLevel.equals(SharingLevel.MANUAL.toString())){ } else if (sharingLevel.equals(SharingLevel.MANUAL.toString())) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker); defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
}else if(id.equals(myID)){ } else if (id.equals(myID)) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker); defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
} }
@ -431,34 +421,30 @@ public class MapActivity extends BaseActivity
markerHash.put(id, marker); markerHash.put(id, marker);
} }
coordsMap.get(id).setLabel(newLabel);
//Change marker if sharing mode has been changed
Boolean newLocalizationMode = markerHash.get(id).getMarkerType().equals(newSharingLevel); Boolean newLocalizationMode = markerHash.get(id).getMarkerType().equals(newSharingLevel);
markerHash.get(id).setMarkerType(newSharingLevel);
if(!newLocalizationMode){ if (!newLocalizationMode) {
Log.e("LOC","1" + coordsMap.get(id).getDisplayMode().trim() + " " + newSharingLevel); Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
MapMarker marker = markerHash.get(id);
coordsMap.get(id).setDisplayMode(newSharingLevel); coordsMap.get(id).setDisplayMode(newSharingLevel);
MapMarker marker = markerHash.get(id); if (newSharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
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); defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker);
}else if(newSharingLevel.equals(SharingLevel.MANUAL.toString())){ } else if (newSharingLevel.equals(SharingLevel.MANUAL.toString())) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker); defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
}else if(id.equals(myID)){ } else if (id.equals(myID)) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker); defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
} }
marker.setDefaultIcon(defaultIcon); marker.setDefaultIcon(defaultIcon);
marker.restoreDefaultIcon(); marker.restoreDefaultIcon();
markerHash.get(id).setMarkerType(newSharingLevel);
mapboxMap.getMarkerViewManager().update(); mapboxMap.getMarkerViewManager().update();
} }
coordsMap.get(id).setLabel(newLabel);
} }
// For next fetch // For next fetch
@ -469,13 +455,8 @@ public class MapActivity extends BaseActivity
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.e("MapActivity onError", e.getMessage());
if (e instanceof HttpException) { if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody(); ResponseBody responseBody = ((HttpException) e).response().errorBody();
Log.e("MapActivity onError", RestApiHelper.getErrorMessage(responseBody));
} }
} }
}) })
@ -650,7 +631,7 @@ public class MapActivity extends BaseActivity
private void filterMarkers(List<User> users) { private void filterMarkers(List<User> users) {
restoreMapMarkers(); restoreMapMarkers();
Icon markedMarker = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker); Icon markedMarker = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.search_marker);
List<MapMarker> markersToSet = Stream.of(markerHash.values()) List<MapMarker> markersToSet = Stream.of(markerHash.values())
.filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(m.getMarker().getTitle()))) .filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(m.getMarker().getTitle())))

View File

@ -121,7 +121,7 @@ public class SharingFragment extends PreferenceFragment {
/** Sharing level list **/ /** Sharing level list **/
locationMode.setOnPreferenceChangeListener((preference, newValue) -> { locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue))); PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue)));
if(PrefUtils.getLocationLevel(getApplicationContext()) == "manual"){ if(PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")){
preferenceCategory.addPreference(manualLocationList); preferenceCategory.addPreference(manualLocationList);
preferenceCategory.addPreference(manualLocationButton); preferenceCategory.addPreference(manualLocationButton);
@ -145,15 +145,12 @@ public class SharingFragment extends PreferenceFragment {
return true; return true;
}); });
/** Button 'choose from map' button listener **/ /** Button 'choose from map' button listener **/
manualLocationButton.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
@Override //ToDO wywołanie wybierania lokalizacji z mapy
public boolean onPreferenceChange(Preference preference, Object o) { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
//ToDO wywołanie wybierania lokalizacji z mapy fragmentTransaction.hide(SharingFragment.this);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.commit();
fragmentTransaction.hide(SharingFragment.this); return true;
fragmentTransaction.commit();
return true;
}
}); });
/** Status list change listener **/ /** Status list change listener **/

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

View File

@ -27,4 +27,14 @@
android:textColor="@color/note_list_text" android:textColor="@color/note_list_text"
/> />
<TextView
android:id="@+id/sharing_level"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text"
/>
</LinearLayout> </LinearLayout>