Add markers filter
This commit is contained in:
parent
892216cc0c
commit
b02ec917ed
@ -20,7 +20,6 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -38,9 +37,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.functions.Consumer;
|
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||||
@ -50,21 +47,17 @@ public abstract class BaseActivity
|
|||||||
extends AppCompatActivity
|
extends AppCompatActivity
|
||||||
implements BottomNavigationView.OnNavigationItemSelectedListener {
|
implements BottomNavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
String tag = getClass().getName();
|
|
||||||
|
|
||||||
protected static final int REQUEST_PERMISSIONS = 100;
|
protected static final int REQUEST_PERMISSIONS = 100;
|
||||||
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
|
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
|
||||||
|
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{
|
||||||
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[] {
|
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS};
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS };
|
|
||||||
|
|
||||||
public DrawerLayout drawerLayout;
|
public DrawerLayout drawerLayout;
|
||||||
protected BottomNavigationView navigationView;
|
protected BottomNavigationView navigationView;
|
||||||
protected NavigationView drawerNavigationView;
|
protected NavigationView drawerNavigationView;
|
||||||
protected DrawerLayout sideDrawer;
|
protected DrawerLayout sideDrawer;
|
||||||
protected Toolbar toolbar;
|
protected Toolbar toolbar;
|
||||||
protected boolean isTutor;
|
protected boolean isTutor;
|
||||||
|
String tag = getClass().getName();
|
||||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||||
private SharingFragment sharingFragment;
|
private SharingFragment sharingFragment;
|
||||||
|
|
||||||
@ -84,13 +77,13 @@ public abstract class BaseActivity
|
|||||||
item -> {
|
item -> {
|
||||||
String itemName = (String) item.getTitle();
|
String itemName = (String) item.getTitle();
|
||||||
Intent launchIntent;
|
Intent launchIntent;
|
||||||
if (itemName.equals(getResources().getString(R.string.navigation_item_whitelist))) {
|
if (itemName.equals(getResources().getString(R.string.navigation_item_whitelist))) {
|
||||||
/* launchIntent = new Intent(getApplicationContext(), WhitelistActivity.class);
|
/* launchIntent = new Intent(getApplicationContext(), WhitelistActivity.class);
|
||||||
startActivity(launchIntent);*/
|
startActivity(launchIntent);*/
|
||||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
|
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
|
||||||
/* launchIntent = new Intent(getApplicationContext(), BlacklistActivity.class);
|
/* launchIntent = new Intent(getApplicationContext(), BlacklistActivity.class);
|
||||||
startActivity(launchIntent);*/
|
startActivity(launchIntent);*/
|
||||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
|
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
|
||||||
/* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class);
|
/* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class);
|
||||||
startActivity(launchIntent);*/
|
startActivity(launchIntent);*/
|
||||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
|
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
|
||||||
@ -98,12 +91,12 @@ public abstract class BaseActivity
|
|||||||
startActivity(launchIntent);
|
startActivity(launchIntent);
|
||||||
|
|
||||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
|
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
|
||||||
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
|
if (PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
|
||||||
stopBackgroundLocalizationTask();
|
stopBackgroundLocalizationTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
storeBackgroundLocationStatus(getApplication(),false);
|
storeBackgroundLocationStatus(getApplication(), false);
|
||||||
PrefUtils.storeIsLoggedIn(getApplicationContext(),false);
|
PrefUtils.storeIsLoggedIn(getApplicationContext(), false);
|
||||||
|
|
||||||
Intent i = getBaseContext().getPackageManager()
|
Intent i = getBaseContext().getPackageManager()
|
||||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||||
@ -130,14 +123,8 @@ public abstract class BaseActivity
|
|||||||
if (!isTutor) {
|
if (!isTutor) {
|
||||||
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void checkPermissions() {
|
protected void checkPermissions() {
|
||||||
final List<String> missingPermissions = new ArrayList<String>();
|
final List<String> missingPermissions = new ArrayList<String>();
|
||||||
|
|
||||||
@ -201,9 +188,9 @@ public abstract class BaseActivity
|
|||||||
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext())
|
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext())
|
||||||
&& !PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext());
|
&& !PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext());
|
||||||
|
|
||||||
if (shouldServiceRun){
|
if (shouldServiceRun) {
|
||||||
startBackgroundLocalizationTask();
|
startBackgroundLocalizationTask();
|
||||||
} else if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext()) &&
|
} else if (PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext()) &&
|
||||||
!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
|
!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
|
||||||
stopBackgroundLocalizationTask();
|
stopBackgroundLocalizationTask();
|
||||||
}
|
}
|
||||||
@ -263,8 +250,16 @@ public abstract class BaseActivity
|
|||||||
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
||||||
searchView = (SearchView) myActionMenuItem.getActionView();
|
searchView = (SearchView) myActionMenuItem.getActionView();
|
||||||
|
|
||||||
|
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
|
||||||
|
if (!hasFocus && activeFragment.equals(ActiveFragment.NONE)) {
|
||||||
|
restoreMapMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
RxSearchObservable.fromView(searchView)
|
RxSearchObservable.fromView(searchView)
|
||||||
.map(String::toLowerCase)
|
.map(String::toLowerCase)
|
||||||
|
.filter(t -> !t.trim().isEmpty())
|
||||||
.debounce(300, TimeUnit.MILLISECONDS)
|
.debounce(300, TimeUnit.MILLISECONDS)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
@ -277,9 +272,16 @@ public abstract class BaseActivity
|
|||||||
private void executeSearch(String input) {
|
private void executeSearch(String input) {
|
||||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||||
((UsersListFragment) userListFragment).searchUser(input);
|
((UsersListFragment) userListFragment).searchUser(input);
|
||||||
|
} else if (activeFragment.equals(ActiveFragment.NONE)) {
|
||||||
|
searchUser(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void searchUser(String textToSearch) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restoreMapMarkers() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
@ -289,7 +291,6 @@ public abstract class BaseActivity
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@ -311,13 +312,13 @@ public abstract class BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||||
|
|
||||||
|
|
||||||
navigationView.postDelayed(() -> {
|
navigationView.postDelayed(() -> {
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
|
|
||||||
if (itemId == R.id.nav_map) {
|
if (itemId == R.id.nav_map) {
|
||||||
removeFragment(sharingFragment);
|
removeFragment(sharingFragment);
|
||||||
removeFragment(userListFragment);
|
removeFragment(userListFragment);
|
||||||
|
activeFragment = ActiveFragment.NONE;
|
||||||
} else if (itemId == R.id.nav_profile) {
|
} else if (itemId == R.id.nav_profile) {
|
||||||
loadUserSettingsFragment();
|
loadUserSettingsFragment();
|
||||||
} else if (itemId == R.id.nav_user_list) {
|
} else if (itemId == R.id.nav_user_list) {
|
||||||
|
@ -6,7 +6,6 @@ import android.animation.ValueAnimator;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -40,9 +39,6 @@ import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
|||||||
import com.mapbox.mapboxsdk.maps.MapView;
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
|
||||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
|
||||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
|
||||||
import com.uam.wmi.findmytutor.R;
|
import com.uam.wmi.findmytutor.R;
|
||||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||||
import com.uam.wmi.findmytutor.model.User;
|
import com.uam.wmi.findmytutor.model.User;
|
||||||
@ -51,32 +47,20 @@ import com.uam.wmi.findmytutor.service.CoordinateService;
|
|||||||
import com.uam.wmi.findmytutor.service.UserService;
|
import com.uam.wmi.findmytutor.service.UserService;
|
||||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
|
||||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.annotations.NonNull;
|
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.functions.Predicate;
|
|
||||||
import io.reactivex.observers.DisposableSingleObserver;
|
import io.reactivex.observers.DisposableSingleObserver;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
|
||||||
import static java.util.stream.Collectors.toList;
|
|
||||||
|
|
||||||
|
|
||||||
public class MapActivity extends BaseActivity
|
public class MapActivity extends BaseActivity
|
||||||
@ -105,6 +89,7 @@ public class MapActivity extends BaseActivity
|
|||||||
private int bearingParam = 180;
|
private int bearingParam = 180;
|
||||||
private int tiltParam = 30;
|
private int tiltParam = 30;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -137,7 +122,6 @@ public class MapActivity extends BaseActivity
|
|||||||
handleBackgroundTaskLifeCycle();
|
handleBackgroundTaskLifeCycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMapReady(MapboxMap mapboxMap) {
|
public void onMapReady(MapboxMap mapboxMap) {
|
||||||
MapActivity.this.mapboxMap = mapboxMap;
|
MapActivity.this.mapboxMap = mapboxMap;
|
||||||
@ -185,19 +169,17 @@ public class MapActivity extends BaseActivity
|
|||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void handleError(Throwable error) {
|
private void handleError(Throwable error) {
|
||||||
showError(error);
|
showError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void showError(Throwable e) {
|
private void showError(Throwable e) {
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
if (e instanceof HttpException) {
|
if (e instanceof HttpException) {
|
||||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||||
message = RestApiHelper.getErrorMessage(responseBody);
|
message = RestApiHelper.getErrorMessage(responseBody);
|
||||||
}else {
|
} else {
|
||||||
message = "Network Error!";
|
message = "Network Error!";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,37 +294,6 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStaticLayer() {
|
|
||||||
// Toggle layer button
|
|
||||||
final FloatingActionButton button = findViewById(R.id.toggleMarkerLayerButton);
|
|
||||||
button.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
button.setOnClickListener(view -> {
|
|
||||||
|
|
||||||
Layer layer = mapboxMap.getLayer("museums");
|
|
||||||
if (layer != null) {
|
|
||||||
if (VISIBLE.equals(layer.getVisibility().getValue())) {
|
|
||||||
layer.setProperties(visibility(NONE));
|
|
||||||
} else {
|
|
||||||
layer.setProperties(visibility(VISIBLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO here we create static layer, we are able to hide/show (but we cannot put markers inthere)
|
|
||||||
VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
|
|
||||||
mapboxMap.addSource(museums);
|
|
||||||
|
|
||||||
CircleLayer museumsLayer = new CircleLayer("museums", "museums_source");
|
|
||||||
museumsLayer.setSourceLayer("museum-cusco");
|
|
||||||
museumsLayer.setProperties(
|
|
||||||
visibility(VISIBLE),
|
|
||||||
circleRadius(8f),
|
|
||||||
circleColor(Color.argb(255, 55, 148, 179))
|
|
||||||
);
|
|
||||||
mapboxMap.addLayer(museumsLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fetchTopCoords() {
|
private void fetchTopCoords() {
|
||||||
|
|
||||||
disposable.add(
|
disposable.add(
|
||||||
@ -354,44 +305,37 @@ public class MapActivity extends BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<Coordinate> coordsList) {
|
public void onSuccess(List<Coordinate> coordsList) {
|
||||||
|
|
||||||
if(coordsList.isEmpty()) {
|
if (coordsList.isEmpty() && droppedMarker == null) {
|
||||||
Log.e(tag, "200 empty []");
|
Timber.e("200 empty []");
|
||||||
mapboxMap.clear();
|
mapboxMap.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> tmp = new ArrayList<>();
|
|
||||||
|
|
||||||
|
ArrayList<String> tmp = new ArrayList<>();
|
||||||
for (Coordinate coordinate : coordsList) {
|
for (Coordinate coordinate : coordsList) {
|
||||||
Log.e(tag, coordinate.toString());
|
tmp.add(coordinate.getUserId());
|
||||||
if (coordinate.getDisplayMode().equals(SharingLevel.PRESENCE.toString())) {
|
|
||||||
Log.e(tag, "presence user omitted");
|
|
||||||
} else {
|
|
||||||
tmp.add(coordinate.getUserId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Set<String> currentCoordsIds = new HashSet<>(tmp);
|
Set<String> currentCoordsIds = new HashSet<>(tmp);
|
||||||
if (previousCoordsIds.isEmpty()){
|
if (previousCoordsIds.isEmpty()) {
|
||||||
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));
|
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
||||||
mapboxMap.removeMarker(markerHash.get(toRemoveId));
|
mapboxMap.removeMarker(markerHash.get(toRemoveId));
|
||||||
markerHash.remove(toRemoveId);
|
markerHash.remove(toRemoveId);
|
||||||
coordsMap.remove(toRemoveId);
|
coordsMap.remove(toRemoveId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO double check when some markers api will change
|
// TODO double check when some markers api will change
|
||||||
Log.e(tag+ "delete: ","nothing to remove");
|
Log.e(tag + "delete: ", "nothing to remove");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (Coordinate element : coordsList) {
|
for (Coordinate element : coordsList) {
|
||||||
String id = element.getUserId();
|
String id = element.getUserId();
|
||||||
String newLabel = element.getLabel();
|
String newLabel = element.getLabel();
|
||||||
@ -430,13 +374,16 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Log.e(tag, "Marker Added: " + id);
|
Log.e(tag, "Marker Added: " + id);
|
||||||
|
|
||||||
coordsMap.put(id, element);
|
coordsMap.put(id, element);
|
||||||
Marker marker = mapboxMap.addMarker(new MarkerOptions()
|
|
||||||
|
MarkerOptions markerOptions = new MarkerOptions()
|
||||||
.title(id)
|
.title(id)
|
||||||
.position(new LatLng(element.getLatitude(), element.getLongitude())));
|
.position(new LatLng(element.getLatitude(), element.getLongitude()));
|
||||||
|
|
||||||
|
Marker marker = mapboxMap.addMarker(markerOptions);
|
||||||
|
|
||||||
markerHash.put(id, marker);
|
markerHash.put(id, marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,4 +550,51 @@ public class MapActivity extends BaseActivity
|
|||||||
// finish();
|
// finish();
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void searchUser(String textToSearch) {
|
||||||
|
getUserFromApi(textToSearch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getUserFromApi(String userNameToSearch) {
|
||||||
|
disposable.add(
|
||||||
|
userService.apiUsersGet()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.map(tutors -> Stream.of(tutors).filter(t ->
|
||||||
|
t.toSearchAbleUserName().toLowerCase().contains(userNameToSearch.toLowerCase())).toList())
|
||||||
|
.subscribeWith(new DisposableSingleObserver<List<User>>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(List<User> users) {
|
||||||
|
filterMarkers(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
showError(e);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
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())))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
for (Marker marker : markersToSet) {
|
||||||
|
marker.setIcon(icon1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restoreMapMarkers() {
|
||||||
|
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
|
||||||
|
|
||||||
|
for (Marker marker : mapboxMap.getMarkers()) {
|
||||||
|
marker.setIcon(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -712,6 +712,15 @@ public class User extends BaseResponse {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toSearchAbleUserName(){
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getFirstName());
|
||||||
|
sb.append(getLastName());
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.uam.wmi.findmytutor.utils;
|
package com.uam.wmi.findmytutor.utils;
|
||||||
|
|
||||||
public class Consts {
|
public class Consts {
|
||||||
public final static Double presenceLatitude = 52.467491;
|
public final static Double presenceLatitude = 65.600244;
|
||||||
public final static Double presencelongitude = 16.926782;
|
public final static Double presencelongitude = 480.032153;
|
||||||
public final static String presenceApproximatedName = "unknown";
|
public final static String presenceApproximatedName = "unknown";
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.uam.wmi.findmytutor.utils;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.mapbox.mapboxsdk.annotations.InfoWindow;
|
||||||
|
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||||
|
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
|
|
||||||
|
public class MapboxMarker extends Marker {
|
||||||
|
public MapboxMarker( MarkerOptions markerOptions ){
|
||||||
|
super(markerOptions);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
@NonNull
|
||||||
|
|
||||||
|
private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) {
|
||||||
|
iw.open(mapView, this, this.getPosition(), 0, 0);
|
||||||
|
this.infoWindowShown = true;
|
||||||
|
return iw;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
@ -29,8 +29,11 @@ public class RxSearchObservable {
|
|||||||
subject.onNext(text);
|
subject.onNext(text);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return subject;
|
return subject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 923 B After Width: | Height: | Size: 444 B |
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue
Block a user