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 ab134d2..9880c1b 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 @@ -21,6 +21,7 @@ import android.widget.Button; import android.widget.TextView; import android.widget.Toast; +import com.annimon.stream.Stream; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.mapbox.android.core.permissions.PermissionsListener; import com.mapbox.android.core.permissions.PermissionsManager; @@ -50,15 +51,20 @@ import com.uam.wmi.findmytutor.service.CoordinateService; import com.uam.wmi.findmytutor.service.UserService; 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; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.annotations.NonNull; import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.functions.Predicate; import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; @@ -70,6 +76,7 @@ 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 @@ -339,10 +346,11 @@ public class MapActivity extends BaseActivity private void fetchTopCoords() { disposable.add( - // coordinateService.getTopCoordinates() coordinateService.getOnlineCoordinates() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) + .map(tutors -> Stream.of(tutors). + filterNot(t -> t.getDisplayMode().equals(SharingLevel.PRESENCE.toString())).toList()) .subscribeWith(new DisposableSingleObserver>() { @Override @@ -364,7 +372,7 @@ public class MapActivity extends BaseActivity if (previousCoordsIds.isEmpty()){ previousCoordsIds.addAll(currentCoordsIds); } else { - // here we clear + it returns bool if smthing was removed + // 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)); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java index 3a09b6f..331e703 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java @@ -31,6 +31,7 @@ import com.mapbox.geojson.Point; import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.utils.ApproximatedLocalization; +import com.uam.wmi.findmytutor.utils.Consts; import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.SharingLevel; @@ -46,6 +47,9 @@ import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; import timber.log.Timber; +import static com.uam.wmi.findmytutor.utils.Consts.presenceApproximatedName; +import static com.uam.wmi.findmytutor.utils.Consts.presenceLatitude; +import static com.uam.wmi.findmytutor.utils.Consts.presencelongitude; import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus; public class BackgroundLocalizationService extends Service { @@ -53,7 +57,6 @@ public class BackgroundLocalizationService extends Service { private static final String TAG = "MyLocationService"; private static final int LOCATION_INTERVAL = 1000; private static final float LOCATION_DISTANCE = 5f; - public static String str_receiver = "background.location.broadcast"; private static long notify_interval = 10000; Location mLastLocation; Boolean stopService = false; @@ -119,7 +122,6 @@ public class BackgroundLocalizationService extends Service { mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); - initializeLocationManager(); Integer providerIndex = 0; @@ -207,20 +209,12 @@ public class BackgroundLocalizationService extends Service { Log.e("Best localization:", String.valueOf(bestLocation)); - /* if (bestLocation != null) - fn_update(bestLocation); -*/ - mFusedLocationClient.getLastLocation().addOnSuccessListener( - new OnSuccessListener() { - @Override - public void onSuccess(Location location) { - if (location != null) { - mLastLocation = location; - fn_update(location); - } + location -> { + if (location != null) { + mLastLocation = location; + fn_update(location); } - }); } @@ -311,20 +305,16 @@ public class BackgroundLocalizationService extends Service { protected Object doInBackground(Object[] objects) { if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) { - longitude = 52.467491; - latitude = 16.926782; - Log.e(TAG,"PRESENCE"); + latitude = presenceLatitude; + longitude = presencelongitude; + approximatedBuildingPart = presenceApproximatedName; } else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())) { - List points = approximatedLocalization.getPointerBuildingPart(approximatedBuildingPart); + List points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart); latitude = points.get(0); longitude = points.get(1); - Log.e(TAG,"APPROXIMATED"); - }else { - Log.e(TAG,"EXACT"); } - try { Coordinate coordinate = new Coordinate( latitude, 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 39aca2a..4a42bf3 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,12 +1,8 @@ package com.uam.wmi.findmytutor.utils; import android.support.annotation.NonNull; -import android.util.Log; import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import com.mapbox.geojson.BoundingBox; import com.mapbox.geojson.Feature; import com.mapbox.geojson.FeatureCollection; @@ -19,7 +15,6 @@ import com.mapbox.geojson.gson.GeometryDeserializer; import com.mapbox.geojson.gson.PointDeserializer; import com.mapbox.turf.TurfJoins; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -56,7 +51,7 @@ public class ApproximatedLocalization { return null; } - public List getPointerBuildingPart(String buildingPart) { + public List getMiddlePointOfBuildingPart(String buildingPart) { for (Feature feature : Objects.requireNonNull(buildingSchema.features())) { String partName = feature.getStringProperty("name"); @@ -65,15 +60,10 @@ public class ApproximatedLocalization { Double longitude = feature.getNumberProperty("longitude").doubleValue(); Double latitude = feature.getNumberProperty("latitude").doubleValue(); - List list = Arrays.asList(longitude,latitude); - - Log.e("APPROX",partName + " " + buildingPart + list); - - return list; - + return Arrays.asList(longitude, latitude); } } - return Arrays.asList(0.0,0.0); + return Arrays.asList(0.0, 0.0); } } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/Consts.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/Consts.java new file mode 100644 index 0000000..eef58b5 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/Consts.java @@ -0,0 +1,7 @@ +package com.uam.wmi.findmytutor.utils; + +public class Consts { + public final static Double presenceLatitude = 52.467491; + public final static Double presencelongitude = 16.926782; + public final static String presenceApproximatedName = "unknown"; +}