Merge branch 'markers-types' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-26 23:17:43 +00:00 committed by Gogs
commit db3ac7378c
21 changed files with 216 additions and 79 deletions

View File

@ -154,11 +154,8 @@ public class LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) {
ValidateUser user = new ValidateUser(email, password);
LdapUser fuser = new LdapUser(email,password,"wmi","tutor","henryk","zdzblo",email);
// disposable.add(ldapService.validate(user)
disposable.add(ldapService.fakeValidate(fuser)
disposable.add(ldapService.validate(user)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError));
@ -220,6 +217,5 @@ public class LoginActivity extends AppCompatActivity {
PrefUtils.storeUserLastName(getApplicationContext(), user.getLastName());
PrefUtils.storeUserName(getApplicationContext(), user.getUserName());
}
}

View File

@ -4,6 +4,7 @@ import android.Manifest;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
@ -41,8 +42,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;
@ -58,11 +61,9 @@ import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import timber.log.Timber;
public class MapActivity extends BaseActivity
implements PermissionsListener, OnMapReadyCallback {
private String tag = getClass().getName();
private PermissionsManager permissionsManager;
private LocationComponent locationComponent;
@ -82,21 +83,22 @@ 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 HashMap<Long, String> markerUserHash = new HashMap<>();
private Set<String> previousCoordsIds = new HashSet<>();
// Camera Animation params
private int zoomParam = 17;
private int bearingParam = 180;
private int tiltParam = 30;
private String myID;
private String myId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myID = PrefUtils.getUserId(getApplicationContext());
// fetching coords service
myId = PrefUtils.getUserId(getApplicationContext());
coordinateService = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class);
@ -111,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));
@ -132,8 +131,9 @@ public class MapActivity extends BaseActivity
enableLocationPlugin();
mapboxMap.setOnMarkerClickListener(marker -> {
String id = marker.getTitle();
if (id.equals(myID)) {
String id = markerUserHash.get(marker.getId());
if (id.equals(myId)) {
selectLocationButton.setVisibility(View.GONE);
removeLocationButton.setVisibility(View.VISIBLE);
@ -141,9 +141,6 @@ public class MapActivity extends BaseActivity
Log.e(tag + "Manual", "manual coords sending stopped");
stopBackgroundLocalizationTask();
// TODO to remove after BGserv
// manualLocHandler.removeCallbacks(manualLocStatusChecker);
removeLocationButton.setVisibility(View.GONE);
Toast.makeText(MapActivity.this, "Your marker will disappear in next couple minutes", Toast.LENGTH_SHORT).show();
@ -155,12 +152,11 @@ public class MapActivity extends BaseActivity
return true;
});
setToggleMapBoundsArea();
if (PrefUtils.getIsTutor(this)) {
setOnMapLongClickListener();
}
// addStaticLayer();
}
private void setToggleMapBoundsArea() {
@ -180,15 +176,28 @@ public class MapActivity extends BaseActivity
});
}
private void updateUserHashMap(String userId, Long markerId) {
disposable.add(userService.getUserById(userId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(t -> saveUserToHashMap(t, markerId), this::handleError));
}
private void saveUserToHashMap(User user, Long markerId) {
markerUserHash.put(markerId, user.getId());
markerHash.get(user.getId()).getMarker().setTitle(user.getFirstName() + " " + user.getLastName());
}
private void createMarkerModal(String userId) {
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);
@ -202,12 +211,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();
}
@ -226,7 +236,6 @@ public class MapActivity extends BaseActivity
message = "Network Error!";
}
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
}
@ -236,7 +245,7 @@ public class MapActivity extends BaseActivity
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
selectLocationButton.setVisibility(View.VISIBLE);
removeLocationButton.setVisibility(View.GONE);
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.my_marker);
if (tmpLocalMarker == null) {
@ -304,7 +313,7 @@ public class MapActivity extends BaseActivity
if (tmpLocalMarker != null && coordsList.isEmpty()) {
Timber.e("200 empty []");
mapboxMap.clear();
return;
}
ArrayList<String> tmp = new ArrayList<>();
@ -317,33 +326,39 @@ public class MapActivity extends BaseActivity
previousCoordsIds.addAll(currentCoordsIds);
} else {
// here we clear + it returns bool if sth was removed
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);
}
}
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 statement = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
Log.e(tag, "diff || diff: " + !statement);
if (!statement) {
Log.e(tag, "replace and animate");
Marker marker = markerHash.get(id);
boolean isTheSameLocalization = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
if (!isTheSameLocalization) {
//Replace prev marker and animate
Marker marker = markerHash.get(id).getMarker();
Boolean showModalAfterAnimation = false;
if(marker.isInfoWindowShown()){
marker.hideInfoWindow();
showModalAfterAnimation = true;
}
LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude());
// TODO fix flickiering markers
@ -355,29 +370,54 @@ public class MapActivity extends BaseActivity
markerAnimator.setInterpolator(new LinearInterpolator());
markerAnimator.start();
// chba niepotrzbene
mapboxMap.getMarkerViewManager().update();
coordsMap.put(id, element);
marker.setPosition(toDestination);
if(showModalAfterAnimation){
mapboxMap.selectMarker(marker);
}
mapboxMap.getMarkerViewManager().update();
}
} else {
Log.e(tag, "Marker Added: " + id);
//Add new marker
coordsMap.put(id, element);
String sharingLevel = coordsMap.get(id).getDisplayMode();
Icon defaultIcon = getMapIcon(sharingLevel, id);
MarkerOptions markerOptions = new MarkerOptions()
.title(id)
.setIcon(defaultIcon)
.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);
}
Marker marker = mapboxMap.addMarker(markerOptions);
Marker markerMapbox = mapboxMap.addMarker(markerOptions);
MapMarker marker = new MapMarker(markerMapbox, markerOptions, defaultIcon, sharingLevel);
markerHash.put(id, marker);
updateUserHashMap(id, marker.getMarker().getId());
}
//Change marker if sharing mode has been changed
Boolean newLocalizationMode = markerHash.get(id).getMarkerType().equals(newSharingLevel);
if (!newLocalizationMode) {
Icon defaultIcon = getMapIcon(newSharingLevel, id);
MapMarker marker = markerHash.get(id);
coordsMap.get(id).setDisplayMode(newSharingLevel);
marker.setDefaultIcon(defaultIcon);
marker.restoreDefaultIcon();
markerHash.get(id).setMarkerType(newSharingLevel);
mapboxMap.getMarkerViewManager().update();
}
coordsMap.get(id).setLabel(newLabel);
@ -386,24 +426,42 @@ public class MapActivity extends BaseActivity
// For next fetch
previousCoordsIds.clear();
previousCoordsIds.addAll(currentCoordsIds);
for (Coordinate coordinate : coordsMap.values()) {
// 300000 = 5mins
if ((System.currentTimeMillis() - coordinate.getTimeStamp()) > (long) 300000) {
String id = coordinate.getUserId();
Marker markerToRemove = markerHash.get(id).getMarker();
markerHash.remove(id);
coordsMap.remove(id);
mapboxMap.removeMarker(markerToRemove);
}
}
}
@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));
}
showError(e);
}
})
);
}
private Icon getMapIcon(String sharingLevel, String id) {
Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.exact_localization_marker);
if (sharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.approximate_localization_marker);
} else if (sharingLevel.equals(SharingLevel.MANUAL.toString()) ||
sharingLevel.equals(SharingLevel.PREDEFINED.toString()) ) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.manual_localization_marker);
} else if (id.equals(myId)) {
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.my_marker);
}
return defaultIcon;
}
@SuppressWarnings({"MissingPermission"})
private void enableLocationPlugin() {
@ -526,7 +584,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
@ -573,23 +630,32 @@ public class MapActivity extends BaseActivity
private void filterMarkers(List<User> users) {
restoreMapMarkers();
Icon icon1 = 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())))
Icon markedMarker = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.search_marker);
List<MapMarker> markersToSet = Stream.of(mapboxMap.getMarkers())
.filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(markerUserHash.get(m.getId()))))
.map(m -> markerUserHash.get(m.getId()))
.map(m -> markerHash.get(m))
.toList();
for (Marker marker : markersToSet) {
marker.setIcon(icon1);
for (MapMarker marker : markersToSet) {
marker.getMarker().setIcon(markedMarker);
if(markersToSet.size() == 1)
mapboxMap.selectMarker(marker.getMarker());
}
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);
}
}
MapMarker markerMap = markerHash.get(markerUserHash.get(marker.getId()));
markerMap.restoreDefaultIcon();
mapboxMap.deselectMarker(marker);
}
mapboxMap.getMarkerViewManager().update();
}
}

View File

@ -124,8 +124,10 @@ public class SharingFragment extends PreferenceFragment {
/** Sharing level list **/
// locationMode.setSummary(PrefUtils.getLocationLevel(getApplicationContext()));
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) {
preferenceCategory.addPreference(manualLocationList);
preferenceCategory.addPreference(manualLocationButton);
@ -149,15 +151,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 **/

View File

@ -0,0 +1,65 @@
package com.uam.wmi.findmytutor.utils;
import android.support.annotation.NonNull;
import android.view.View;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.InfoWindow;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
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;
}
public String getMarkerType() {
return markerType;
}
public void setMarkerType(String markerType) {
this.markerType = markerType;
}
}

View File

@ -4,6 +4,7 @@ public enum SharingLevel {
PRESENCE("presence"),
APPROXIMATED("approximated"),
EXACT("exact"),
PREDEFINED("predefined"),
MANUAL("manual");
private final String text;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -16,7 +16,7 @@
mapbox:mapbox_cameraTargetLat="52.466799"
mapbox:mapbox_cameraTargetLng="16.927002"
mapbox:mapbox_cameraZoom="17"
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjo8yjhfj0ih02rld5rft5nv7">
</com.mapbox.mapboxsdk.maps.MapView>

View File

@ -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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB