diff --git a/app/build.gradle b/app/build.gradle index 06927b9..7b0e6bf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -67,7 +67,6 @@ dependencies { implementation 'com.auth0.android:jwtdecode:1.1.1' implementation 'com.annimon:stream:1.2.1' implementation 'com.google.android.gms:play-services-location:16.0.0' - // FloatingBarMenu implementation 'com.getbase:floatingactionbutton:1.10.1' implementation 'org.apache.commons:commons-collections4:4.0' } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java index 189f28a..965f73f 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java @@ -148,10 +148,10 @@ public class LoginActivity extends AppCompatActivity { } private void loginProcess(String email, String password) { - ValidateUser user = new ValidateUser(email, password); - //LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email); - disposable.add(ldapService.validate(user) - //disposable.add(ldapService.fakeValidate(fakeUser) + //ValidateUser user = new ValidateUser(email, password); + LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email); + // disposable.add(ldapService.validate(user) + disposable.add(ldapService.fakeValidate(fakeUser) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::handleResponse, this::handleError)); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index 0d8b299..a6e41b8 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -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; @@ -24,6 +25,8 @@ import com.getbase.floatingactionbutton.FloatingActionButton; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.mapbox.android.core.permissions.PermissionsListener; import com.mapbox.android.core.permissions.PermissionsManager; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.LineString; import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.annotations.Icon; @@ -38,6 +41,10 @@ import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.CircleLayer; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel; @@ -67,6 +74,32 @@ import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; import timber.log.Timber; +import com.mapbox.geojson.Feature; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.all; +import static com.mapbox.mapboxsdk.style.expressions.Expression.division; +import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.expressions.Expression.gt; +import static com.mapbox.mapboxsdk.style.expressions.Expression.gte; +import static com.mapbox.mapboxsdk.style.expressions.Expression.has; +import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; +import static com.mapbox.mapboxsdk.style.expressions.Expression.lt; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; +import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber; +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.iconColor; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAllowOverlap; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize; + public class MapActivity extends BaseActivity implements PermissionsListener, OnMapReadyCallback { @@ -99,6 +132,7 @@ public class MapActivity extends BaseActivity private boolean isTutor; private ApproximatedLocalization approximatedLocalization; private boolean shouldFetchNewCoords = true; + private GeoJsonSource geoJsonSource = null; @Override protected void onCreate(Bundle savedInstanceState) { @@ -171,6 +205,8 @@ public class MapActivity extends BaseActivity setOnMapClickListener(); MapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true); + convertMarkersToGeoJson(); + addClusteredGeoJsonSource(); } private void updateUserHashMap(String userId, Long markerId) { @@ -219,6 +255,32 @@ public class MapActivity extends BaseActivity } + + private void convertMarkersToGeoJson(){ + List coordinates = Stream.of(coordsMap.values()) + .map(c -> Point.fromLngLat(c.getLongitude(), c.getLatitude())) + .toList(); + + LineString lineString = LineString.fromLngLats(coordinates); + FeatureCollection featureCollection = FeatureCollection.fromFeatures( + new Feature[]{Feature.fromGeometry(lineString)}); + + geoJsonSource = new GeoJsonSource("markers", featureCollection); + mapboxMap.addSource(geoJsonSource); + } + + private void updateGeoJsonSource(){ + List coordinates = Stream.of(coordsMap.values()) + .map(c -> Point.fromLngLat(c.getLongitude(), c.getLatitude())) + .toList(); + + LineString lineString = LineString.fromLngLats(coordinates); + FeatureCollection featureCollection = FeatureCollection.fromFeatures( + new Feature[]{Feature.fromGeometry(lineString)}); + + geoJsonSource = new GeoJsonSource("markers", featureCollection); + } + private void handleError(Throwable error) { showError(error); } @@ -307,6 +369,73 @@ public class MapActivity extends BaseActivity } + + private void addClusteredGeoJsonSource() { + + // Use the earthquakes GeoJSON source to create three layers: One layer for each cluster category. + // Each point range gets a different fill color. + int[][] layers = new int[][] { + new int[] {150, ContextCompat.getColor(this, R.color.mapboxRed)}, + new int[] {20, ContextCompat.getColor(this, R.color.mapboxGreen)}, + new int[] {0, ContextCompat.getColor(this, R.color.mapbox_blue)} + }; + + //Creating a marker layer for single data points + SymbolLayer unclustered = new SymbolLayer("unclustered-points", "markers"); + + unclustered.setProperties( + iconImage("cross-icon-id"), + iconSize( + division( + get("mag"), literal(4.0f) + ) + ), + iconColor( + interpolate(exponential(1), get("mag"), + stop(2.0, rgb(0, 255, 0)), + stop(4.5, rgb(0, 0, 255)), + stop(7.0, rgb(255, 0, 0)) + ) + ) + ); + mapboxMap.addLayer(unclustered); + + for (int i = 0; i < layers.length; i++) { + //Add clusters' circles + CircleLayer circles = new CircleLayer("cluster-" + i, "markers"); + circles.setProperties( + circleColor(layers[i][1]), + circleRadius(18f) + ); + + Expression pointCount = toNumber(get("point_count")); + + // Add a filter to the cluster layer that hides the circles based on "point_count" + circles.setFilter( + i == 0 + ? all(has("point_count"), + gte(pointCount, literal(layers[i][0])) + ) : all(has("point_count"), + gt(pointCount, literal(layers[i][0])), + lt(pointCount, literal(layers[i - 1][0])) + ) + ); + mapboxMap.addLayer(circles); + } + + //Add the count labels + SymbolLayer count = new SymbolLayer("count", "markers"); + count.setProperties( + textField(Expression.toString(get("point_count"))), + textSize(12f), + textColor(Color.WHITE), + textIgnorePlacement(true), + textAllowOverlap(true) + ); + mapboxMap.addLayer(count); + + } + public void showLocationDialog(LatLng latLng) { LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); @@ -501,6 +630,7 @@ public class MapActivity extends BaseActivity // For next fetch previousCoordsIds.clear(); previousCoordsIds.addAll(currentCoordsIds); + updateGeoJsonSource(); } @Override diff --git a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java index 1835496..ad2003d 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java @@ -26,7 +26,7 @@ public class ApiClient { private static Retrofit retrofit = null; private static int REQUEST_TIMEOUT = 60; private static OkHttpClient okHttpClient; - private static final String BASE_URL = "https://s416084.projektstudencki.pl/master/"; + private static final String BASE_URL = "https://s416084.projektstudencki.pl/develop/"; public static Retrofit getClient(Context context) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/ApproximatedLocalization.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/ApproximatedLocalization.java index 83f26fc..2d290f8 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/ApproximatedLocalization.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/ApproximatedLocalization.java @@ -1,42 +1,23 @@ package com.uam.wmi.findmytutor.utils; -import android.support.annotation.NonNull; -import com.google.gson.GsonBuilder; -import com.mapbox.geojson.BoundingBox; import com.mapbox.geojson.Feature; import com.mapbox.geojson.FeatureCollection; -import com.mapbox.geojson.Geometry; import com.mapbox.geojson.Point; import com.mapbox.geojson.Polygon; -import com.mapbox.geojson.gson.BoundingBoxDeserializer; -import com.mapbox.geojson.gson.GeoJsonAdapterFactory; -import com.mapbox.geojson.gson.GeometryDeserializer; -import com.mapbox.geojson.gson.PointDeserializer; import com.mapbox.turf.TurfJoins; import java.util.Arrays; import java.util.List; import java.util.Objects; -; + public class ApproximatedLocalization { private FeatureCollection buildingSchema = null; public ApproximatedLocalization(String buildingObject) { - buildingSchema = fromJson(buildingObject); - } - - private FeatureCollection fromJson(@NonNull String json) { - GsonBuilder gson = new GsonBuilder(); - - gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create()); - gson.registerTypeAdapter(Point.class, new PointDeserializer()); - gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer()); - gson.registerTypeAdapter(BoundingBox.class, new BoundingBoxDeserializer()); - - return gson.create().fromJson(json, FeatureCollection.class); + buildingSchema = FeatureCollection.fromJson(buildingObject); } public String getNameOfBuildingPart(Point point) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java index 6a4282a..f880a87 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java @@ -9,7 +9,7 @@ public class Const { public final static Integer onlineBackgroundLocationInterval = 15000; public final static Integer offlineBackgroundLocationInterval = 36000; public final static Integer defaultMapZoom = 17; - public final static Integer searchMapZoom = 13; + public final static Integer searchMapZoom = 4; public final static Double presenceLatitude = 52.466365; public final static Double presenceLongitude = 16.926792; public final static String presenceApproximatedName = "Unknown"; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java index 3164e2b..fe65c83 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java @@ -42,7 +42,7 @@ public class MapUtils { // Map Bounds Area public static void setZoom(MapboxMap mapboxMap, Integer zoom) { makeNewCamera(mapboxMap, 52.466799, 16.927002, zoom, 0, 0, 1000); - mapboxMap.setMinZoomPreference(16); // TODO export to map config + mapboxMap.setMinZoomPreference(5); // TODO export to map config } public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration) {