Add new markers
This commit is contained in:
parent
422b1079da
commit
aef7174d90
@ -63,7 +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;
|
||||
@ -178,11 +178,12 @@ public class MapActivity extends BaseActivity
|
||||
disposable.add(userService.getUserById(userId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.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 sharingLevel = coordsMap.get(user.getId()).getDisplayMode();
|
||||
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||
@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 status = view.findViewById(R.id.label);
|
||||
TextView sharingLevelView = view.findViewById(R.id.sharing_level);
|
||||
|
||||
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();
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
@ -348,9 +350,9 @@ public class MapActivity extends BaseActivity
|
||||
previousCoordsIds.addAll(currentCoordsIds);
|
||||
} else {
|
||||
// here we clear + it returns bool if sth was removed
|
||||
|
||||
if (previousCoordsIds.removeAll(currentCoordsIds)) {
|
||||
for (String toRemoveId : previousCoordsIds) {
|
||||
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
||||
mapboxMap.removeMarker(markerHash.get(toRemoveId).getMarker());
|
||||
markerHash.remove(toRemoveId);
|
||||
coordsMap.remove(toRemoveId);
|
||||
@ -361,24 +363,19 @@ 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());
|
||||
Log.e(tag, "markerMapSize: " + coordsMap.size());*/
|
||||
|
||||
if (coordinate != null) {
|
||||
Log.e(tag, "Coordin: " + coordinate.getLatitude() + " | " + coordinate.getLongitude());
|
||||
|
||||
boolean isTheSameLocalization = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
|
||||
Log.e(tag, "diff || diff: " + !isTheSameLocalization);
|
||||
|
||||
if (!isTheSameLocalization) {
|
||||
Log.e(tag, "replace and animate");
|
||||
//Replace prev marker and animate
|
||||
Marker marker = markerHash.get(id).getMarker();
|
||||
|
||||
LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude());
|
||||
@ -398,25 +395,18 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.e(tag, "Marker Added: " + id);
|
||||
//Add new marker
|
||||
|
||||
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();
|
||||
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);
|
||||
}else if(sharingLevel.equals(SharingLevel.MANUAL.toString())){
|
||||
} else if (sharingLevel.equals(SharingLevel.MANUAL.toString())) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -431,34 +421,30 @@ public class MapActivity extends BaseActivity
|
||||
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);
|
||||
markerHash.get(id).setMarkerType(newSharingLevel);
|
||||
|
||||
if(!newLocalizationMode){
|
||||
Log.e("LOC","1" + coordsMap.get(id).getDisplayMode().trim() + " " + newSharingLevel);
|
||||
if (!newLocalizationMode) {
|
||||
Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
|
||||
MapMarker marker = markerHash.get(id);
|
||||
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())){
|
||||
if (newSharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
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);
|
||||
}else if(id.equals(myID)){
|
||||
} else if (id.equals(myID)) {
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
|
||||
}
|
||||
|
||||
marker.setDefaultIcon(defaultIcon);
|
||||
marker.restoreDefaultIcon();
|
||||
|
||||
markerHash.get(id).setMarkerType(newSharingLevel);
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
coordsMap.get(id).setLabel(newLabel);
|
||||
}
|
||||
|
||||
// For next fetch
|
||||
@ -469,13 +455,8 @@ public class MapActivity extends BaseActivity
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
Log.e("MapActivity onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
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) {
|
||||
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())
|
||||
.filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(m.getMarker().getTitle())))
|
||||
|
@ -121,7 +121,7 @@ public class SharingFragment extends PreferenceFragment {
|
||||
/** Sharing level list **/
|
||||
locationMode.setOnPreferenceChangeListener((preference, 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(manualLocationButton);
|
||||
|
||||
@ -145,15 +145,12 @@ public class SharingFragment extends PreferenceFragment {
|
||||
return true;
|
||||
});
|
||||
/** Button 'choose from map' button listener **/
|
||||
manualLocationButton.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
//ToDO wywołanie wybierania lokalizacji z mapy
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(SharingFragment.this);
|
||||
fragmentTransaction.commit();
|
||||
return true;
|
||||
}
|
||||
manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
|
||||
//ToDO wywołanie wybierania lokalizacji z mapy
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(SharingFragment.this);
|
||||
fragmentTransaction.commit();
|
||||
return true;
|
||||
});
|
||||
|
||||
/** Status list change listener **/
|
||||
|
BIN
app/src/main/res/drawable/manual_marker.png
Normal file
BIN
app/src/main/res/drawable/manual_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 389 B |
BIN
app/src/main/res/drawable/search_marker.png
Normal file
BIN
app/src/main/res/drawable/search_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 399 B |
@ -27,4 +27,14 @@
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user