Merge branch 'approximated-localizations' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-20 21:44:52 +00:00 committed by Gogs
commit 5e1e3b5bce
19 changed files with 759 additions and 131 deletions

View File

@ -0,0 +1,9 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="IgnoreResultOfCall" enabled="false" level="WARNING" enabled_by_default="false">
<option name="m_reportAllNonLibraryCalls" value="false" />
<option name="callCheckString" value="java.io.File,.*,java.io.InputStream,read|skip|available|markSupported,java.io.Reader,read|skip|ready|markSupported,java.lang.Boolean,.*,java.lang.Byte,.*,java.lang.Character,.*,java.lang.Double,.*,java.lang.Float,.*,java.lang.Integer,.*,java.lang.Long,.*,java.lang.Math,.*,java.lang.Object,equals|hashCode|toString,java.lang.Short,.*,java.lang.StrictMath,.*,java.lang.String,.*,java.lang.Thread,interrupted,java.math.BigInteger,.*,java.math.BigDecimal,.*,java.net.InetAddress,.*,java.net.URI,.*,java.util.Arrays,.*,java.util.List,of,java.util.Set,of,java.util.Map,of|ofEntries|entry,java.util.Collections,(?!addAll).*,java.util.UUID,.*,java.util.regex.Matcher,pattern|toMatchResult|start|end|group|groupCount|matches|find|lookingAt|quoteReplacement|replaceAll|replaceFirst|regionStart|regionEnd|hasTransparentBounds|hasAnchoringBounds|hitEnd|requireEnd,java.util.regex.Pattern,.*,java.util.stream.BaseStream,.*" />
</inspection_tool>
</profile>
</component>

View File

@ -58,7 +58,7 @@ 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'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.0.0'
// FloatingBarMenu
implementation 'com.getbase:floatingactionbutton:1.10.1'

View File

@ -0,0 +1,398 @@
{
"features": [
{
"type": "Feature",
"properties": {
"name": "Skrzydło B",
"longitude" : 52.466669,
"latitude" : 16.926624
},
"geometry": {
"coordinates": [
[
[
16.92618,
52.466248
],
[
16.926435,
52.466201
],
[
16.92646,
52.466255
],
[
16.926516,
52.466244
],
[
16.926999,
52.46711
],
[
16.926796,
52.467145
],
[
16.926782,
52.467117
],
[
16.926784,
52.467121
],
[
16.926691,
52.467139
],
[
16.926662,
52.46709
],
[
16.926757,
52.467072
],
[
16.926544,
52.466691
],
[
16.926434,
52.46671
],
[
16.926396,
52.466655
],
[
16.926519,
52.466628
],
[
16.926323,
52.466281
],
[
16.926213,
52.466307
],
[
16.92618,
52.466248
]
]
],
"type": "Polygon"
},
"id": "41798cf663bc55c10e6c51c3fe174eda"
},
{
"type": "Feature",
"properties": {
"name": "Biblioteka",
"longitude" : 52.467351,
"latitude" : 16.926900
},
"geometry": {
"coordinates": [
[
[
16.927048,
52.46721
],
[
16.926627,
52.467295
],
[
16.926732,
52.467482
],
[
16.926876,
52.467461
],
[
16.926967,
52.467428
],
[
16.927014,
52.467402
],
[
16.927171,
52.467359
],
[
16.9271,
52.467202
],
[
16.927048,
52.46721
]
]
],
"type": "Polygon"
},
"id": "7328c3c9dffd3e76be8d3dcef4f58ddc"
},
{
"type": "Feature",
"properties": {
"name": "Łącznik",
"longitude" : 52.466619,
"latitude" : 16.926860
},
"geometry": {
"coordinates": [
[
[
16.926759,
52.466683
],
[
16.927088,
52.46661
],
[
16.927019,
52.466502
],
[
16.9267,
52.466571
],
[
16.926759,
52.466683
]
]
],
"type": "Polygon"
},
"id": "8c19ee28e4c07ece9756fd21f290713b"
},
{
"type": "Feature",
"properties": {
"name": "Skrzydło A",
"longitude" : 52.466559,
"latitude" : 16.927163
},
"geometry": {
"coordinates": [
[
[
16.926771,
52.466106
],
[
16.926898,
52.466079
],
[
16.926926,
52.466126
],
[
16.927026,
52.466107
],
[
16.92723,
52.466473
],
[
16.927184,
52.466483
],
[
16.927243,
52.466586
],
[
16.927334,
52.46656
],
[
16.927602,
52.466889
],
[
16.927275,
52.466959
],
[
16.926771,
52.466106
]
]
],
"type": "Polygon"
},
"id": "c33bfba772c85cc38ae417843d31b1ff"
},
{
"type": "Feature",
"properties": {
"name": "Aule",
"longitude" : 52.467114,
"latitude" : 16.927621
},
"geometry": {
"coordinates": [
[
[
16.92731,
52.467158
],
[
16.927315,
52.46718
],
[
16.927348,
52.467199
],
[
16.927393,
52.467224
],
[
16.927426,
52.467239
],
[
16.927476,
52.467258
],
[
16.92755,
52.467264
],
[
16.927625,
52.467263
],
[
16.927699,
52.467246
],
[
16.92776,
52.467212
],
[
16.927821,
52.467158
],
[
16.927838,
52.467099
],
[
16.927827,
52.467059
],
[
16.927793,
52.467012
],
[
16.927738,
52.466976
],
[
16.927661,
52.466949
],
[
16.927581,
52.466939
],
[
16.927534,
52.466938
],
[
16.927467,
52.466949
],
[
16.927387,
52.467047
],
[
16.927315,
52.467153
],
[
16.92731,
52.467158
]
]
],
"type": "Polygon"
},
"id": "c779419e3fd7faef8555e1099547a82c"
},
{
"type": "Feature",
"properties": {
"name": "Hol",
"longitude" : 52.4671021,
"latitude" : 16.927122
},
"geometry": {
"coordinates": [
[
[
16.926625,
52.467294
],
[
16.926568,
52.46719
],
[
16.927008,
52.467108
],
[
16.926953,
52.467024
],
[
16.927463,
52.466919
],
[
16.927467,
52.466956
],
[
16.927316,
52.467153
],
[
16.926907,
52.467235
],
[
16.926625,
52.467294
]
]
],
"type": "Polygon"
},
"id": "facdd5349991758b9ad99d4e123c91cc"
}
],
"type": "FeatureCollection"
}

View File

@ -1,6 +1,7 @@
package com.uam.wmi.findmytutor.activity;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
@ -29,9 +30,16 @@ import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.utils.ActiveFragment;
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RxSearchObservable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
@ -41,27 +49,29 @@ public abstract class BaseActivity
extends AppCompatActivity
implements BottomNavigationView.OnNavigationItemSelectedListener {
String tag = getClass().getName();
protected static final int REQUEST_PERMISSIONS = 100;
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
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 };
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};
public DrawerLayout drawerLayout;
protected BottomNavigationView navigationView;
protected NavigationView drawerNavigationView;
protected DrawerLayout sideDrawer;
protected Toolbar toolbar;
protected boolean isTutor;
String tag = getClass().getName();
protected FeedbackUtils feedbackUtils;
private ActionBarDrawerToggle actionBarDrawerToggle;
private SharingFragment sharingFragment;
private Fragment userListFragment;
private ActiveFragment activeFragment = ActiveFragment.NONE;
private SearchView searchView;
@SuppressLint("CheckResult")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -73,13 +83,15 @@ public abstract class BaseActivity
item -> {
String itemName = (String) item.getTitle();
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);
startActivity(launchIntent);*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
/* launchIntent = new Intent(getApplicationContext(), BlacklistActivity.class);
startActivity(launchIntent);*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
/* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class);
startActivity(launchIntent);*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
@ -88,11 +100,12 @@ public abstract class BaseActivity
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask();
}
storeBackgroundLocationStatus(getApplication(),false);
PrefUtils.storeIsLoggedIn(getApplicationContext(),false);
storeBackgroundLocationStatus(getApplication(), false);
PrefUtils.storeIsLoggedIn(getApplicationContext(), false);
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
@ -125,11 +138,8 @@ public abstract class BaseActivity
if (!isTutor) {
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
}
}
protected void checkPermissions() {
final List<String> missingPermissions = new ArrayList<String>();
@ -193,9 +203,9 @@ public abstract class BaseActivity
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext())
&& !PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext());
if (shouldServiceRun){
if (shouldServiceRun) {
startBackgroundLocalizationTask();
} else if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext()) &&
} else if (PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext()) &&
!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
stopBackgroundLocalizationTask();
}
@ -247,38 +257,46 @@ public abstract class BaseActivity
actionBarDrawerToggle.onConfigurationChanged(newConfig);
}
@SuppressLint("CheckResult")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
final SearchView searchView = (SearchView) myActionMenuItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String input) {
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
executeUserListSearch(input);
}
searchView = (SearchView) myActionMenuItem.getActionView();
return false;
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
if (!hasFocus && activeFragment.equals(ActiveFragment.NONE)) {
restoreMapMarkers();
}
@Override
public boolean onQueryTextChange(String input) {
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
executeUserListSearch(input);
}
return true;
}
});
RxSearchObservable.fromView(searchView)
.map(String::toLowerCase)
.filter(t -> !t.trim().isEmpty())
.debounce(300, TimeUnit.MILLISECONDS)
.distinctUntilChanged()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::executeSearch);
return true;
}
private void executeUserListSearch(String input) {
((UsersListFragment) userListFragment).searchUser(input);
private void executeSearch(String input) {
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
((UsersListFragment) userListFragment).searchUser(input);
} else if (activeFragment.equals(ActiveFragment.NONE)) {
searchUser(input);
}
}
public void searchUser(String textToSearch) {
}
public void restoreMapMarkers() {
}
@Override
@ -289,7 +307,6 @@ public abstract class BaseActivity
return super.onOptionsItemSelected(item);
}
@Override
protected void onStart() {
super.onStart();
@ -311,13 +328,13 @@ public abstract class BaseActivity
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
navigationView.postDelayed(() -> {
int itemId = item.getItemId();
if (itemId == R.id.nav_map) {
removeFragment(sharingFragment);
removeFragment(userListFragment);
activeFragment = ActiveFragment.NONE;
} else if (itemId == R.id.nav_profile) {
loadUserSettingsFragment();
} else if (itemId == R.id.nav_user_list) {

View File

@ -6,13 +6,9 @@ import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import com.getbase.floatingactionbutton.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
@ -23,6 +19,8 @@ import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.annimon.stream.Stream;
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;
@ -39,9 +37,6 @@ 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.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.model.Coordinate;
import com.uam.wmi.findmytutor.model.User;
@ -56,6 +51,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -64,14 +60,6 @@ import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
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;
public class MapActivity extends BaseActivity
implements PermissionsListener, OnMapReadyCallback {
@ -99,6 +87,7 @@ public class MapActivity extends BaseActivity
private int bearingParam = 180;
private int tiltParam = 30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -132,7 +121,6 @@ public class MapActivity extends BaseActivity
handleBackgroundTaskLifeCycle();
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
MapActivity.this.mapboxMap = mapboxMap;
@ -198,7 +186,25 @@ public class MapActivity extends BaseActivity
}
// Manual loc selection on long tap
private void handleError(Throwable error) {
showError(error);
}
private void showError(Throwable e) {
String message;
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
} else {
message = "Network Error!";
}
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
}
private void setOnMapLongClickListener() {
final boolean[] cancel = {false};
@ -236,6 +242,7 @@ public class MapActivity extends BaseActivity
latLng.getLatitude(),
latLng.getLongitude(),
latLng.getAltitude(),
"approx",
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
PrefUtils.getUserId(getApplicationContext()),
PrefUtils.getLocationLevel(getApplicationContext())
@ -305,41 +312,9 @@ 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() {
disposable.add(
// coordinateService.getTopCoordinates()
coordinateService.getOnlineCoordinates()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -348,9 +323,16 @@ public class MapActivity extends BaseActivity
@Override
public void onSuccess(List<Coordinate> coordsList) {
if (coordsList.isEmpty() && droppedMarker == null) {
Timber.e("200 empty []");
mapboxMap.clear();
}
if (coordsList.isEmpty()) {
Log.e(tag, "200 empty []");
//mapboxMap.clear();
return;
}
@ -364,7 +346,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));
@ -417,13 +399,16 @@ public class MapActivity extends BaseActivity
}
} else {
Log.e(tag, "Marker Added: " + id);
coordsMap.put(id, element);
Marker marker = mapboxMap.addMarker(new MarkerOptions()
MarkerOptions markerOptions = new MarkerOptions()
.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);
}
@ -589,20 +574,52 @@ public class MapActivity extends BaseActivity
// }
}
private void handleError(Throwable error) {
showError(error);
@Override
public void searchUser(String textToSearch) {
getUserFromApi(textToSearch);
}
private void showError(Throwable e) {
String message;
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);
}
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
} else {
message = "Network Error!";
@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);
}
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
}
public void restoreMapMarkers() {
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
for (Marker marker : mapboxMap.getMarkers()) {
marker.setIcon(icon);
}
}
}

View File

@ -19,6 +19,7 @@ import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.SharingLevel;
import java.util.Arrays;
import java.util.HashMap;
@ -40,9 +41,10 @@ public class SharingFragment extends PreferenceFragment {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationLevelMapping = new HashMap<Integer, String>();
locationLevelMapping.put(0,"presence");
locationLevelMapping.put(1,"approximated");
locationLevelMapping.put(2,"exact");
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
locationLevelMapping.put(2, SharingLevel.EXACT.toString());
addPreferencesFromResource(R.layout.pref_sharing);
Preference manualStatus = findPreference("key_manual_status");
@ -60,8 +62,8 @@ public class SharingFragment extends PreferenceFragment {
});
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference;
PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue)));
return true;
});

View File

@ -9,6 +9,7 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@ -44,15 +44,17 @@ public class Coordinate extends BaseResponse {
@SerializedName("label")
private String label;
public Coordinate (Double latitude, Double longitude, Double altitude, String label, String userId, String displayMode) {
public Coordinate (Double latitude, Double longitude, Double altitude, String approximatedLocation, String label, String userId, String displayMode) {
//if (!latitudeRange.contains(latitude)) throw new IllegalArgumentException("Inappropriate latitude value" + latitude);
//if (!longtitudeRange.contains(longitude)) throw new IllegalArgumentException("Inappropriate longitude value" + longitude);
//if (approximatedLocation == null) throw new IllegalArgumentException("Inappropriate approximatedLocation");
this.latitude = latitude;
this.longitude = longitude;
this.altitude = altitude;
this.label = label;
this.userId = userId;
this.approximatedLocation = approximatedLocation;
this.displayMode = displayMode;
}

View File

@ -712,6 +712,15 @@ public class User extends BaseResponse {
return sb.toString();
}
public String toSearchAbleUserName(){
StringBuilder sb = new StringBuilder();
sb.append(getFirstName());
sb.append(getLastName());
return sb.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@ -27,14 +27,18 @@ import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
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;
import com.uam.wmi.findmytutor.utils.mapUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -43,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 {
@ -50,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;
@ -64,6 +70,7 @@ public class BackgroundLocalizationService extends Service {
private Runnable mStatusChecker;
private FusedLocationProviderClient mFusedLocationClient;
public BackgroundLocalizationService() {
providers.add(LocationManager.GPS_PROVIDER);
providers.add(LocationManager.NETWORK_PROVIDER);
@ -74,6 +81,7 @@ public class BackgroundLocalizationService extends Service {
new LocationListener(LocationManager.NETWORK_PROVIDER),
new LocationListener(LocationManager.PASSIVE_PROVIDER)
};
}
@Override
@ -90,7 +98,7 @@ public class BackgroundLocalizationService extends Service {
stopService = intent.getBooleanExtra("request_stop", false);
}
if (stopService) {
storeBackgroundLocationStatus(getApplication(),false);
storeBackgroundLocationStatus(getApplication(), false);
stopForeground(true);
stopSelf();
return START_STICKY;
@ -102,7 +110,7 @@ public class BackgroundLocalizationService extends Service {
@Override
public void onCreate() {
Log.e(TAG, "onCreate");
storeBackgroundLocationStatus(getApplication(),true);
storeBackgroundLocationStatus(getApplication(), true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startMyOwnForeground();
@ -114,7 +122,6 @@ public class BackgroundLocalizationService extends Service {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
initializeLocationManager();
Integer providerIndex = 0;
@ -137,7 +144,7 @@ public class BackgroundLocalizationService extends Service {
providerIndex++;
}
if(!stopService){
if (!stopService) {
mStatusChecker = () -> {
try {
fn_getlocation();
@ -202,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<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
mLastLocation = location;
fn_update(location);
}
location -> {
if (location != null) {
mLastLocation = location;
fn_update(location);
}
});
}
@ -283,11 +282,13 @@ public class BackgroundLocalizationService extends Service {
}
}
@SuppressLint("StaticFieldLeak")
private class Task extends AsyncTask {
ApproximatedLocalization approximatedLocalization;
private Double latitude;
private Double longitude;
private Double altitude;
private String approximatedBuildingPart = null;
private CompositeDisposable disposable = new CompositeDisposable();
private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class);
@ -296,16 +297,30 @@ public class BackgroundLocalizationService extends Service {
latitude = location.getLatitude();
longitude = location.getLongitude();
altitude = location.getAltitude();
approximatedLocalization = new ApproximatedLocalization(mapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
}
@Override
protected Object doInBackground(Object[] objects) {
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
latitude = presenceLatitude;
longitude = presencelongitude;
approximatedBuildingPart = presenceApproximatedName;
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())) {
List<Double> points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart);
latitude = points.get(0);
longitude = points.get(1);
}
try {
Coordinate coordinate = new Coordinate(
latitude,
longitude,
altitude,
approximatedBuildingPart,
PrefUtils.getUserStatus(getApplicationContext()),
PrefUtils.getUserId(getApplicationContext()),
PrefUtils.getLocationLevel(getApplicationContext())

View File

@ -0,0 +1,69 @@
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);
}
public String getNameOfBuildingPart(Point point) {
for (Feature feature : Objects.requireNonNull(buildingSchema.features())) {
boolean isInside = TurfJoins.inside(point, (Polygon) Objects.requireNonNull(feature.geometry()));
if (isInside)
return Objects.requireNonNull(Objects.requireNonNull(feature.getStringProperty("name")));
}
return null;
}
public List<Double> getMiddlePointOfBuildingPart(String buildingPart) {
for (Feature feature : Objects.requireNonNull(buildingSchema.features())) {
String partName = feature.getStringProperty("name");
if (buildingPart != null && buildingPart.equals(partName)) {
Double longitude = feature.getNumberProperty("longitude").doubleValue();
Double latitude = feature.getNumberProperty("latitude").doubleValue();
return Arrays.asList(longitude, latitude);
}
}
return Arrays.asList(0.0, 0.0);
}
}

View File

@ -0,0 +1,7 @@
package com.uam.wmi.findmytutor.utils;
public class Consts {
public final static Double presenceLatitude = 65.600244;
public final static Double presencelongitude = 480.032153;
public final static String presenceApproximatedName = "unknown";
}

View File

@ -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;
}*/
}

View File

@ -0,0 +1,39 @@
package com.uam.wmi.findmytutor.utils;
import android.support.v7.widget.SearchView;
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;
public class RxSearchObservable {
private RxSearchObservable() {
// no instance
}
public static Observable<String> fromView(SearchView searchView) {
final PublishSubject<String> subject = PublishSubject.create();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
subject.onNext(s);
return false;
}
@Override
public boolean onQueryTextChange(String text) {
subject.onNext(text);
return false;
}
});
return subject;
}
}

View File

@ -0,0 +1,18 @@
package com.uam.wmi.findmytutor.utils;
public enum SharingLevel {
PRESENCE("presence"),
APPROXIMATED("approximated"),
EXACT("exact");
private final String text;
SharingLevel(final String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}

View File

@ -2,11 +2,15 @@ package com.uam.wmi.findmytutor.utils;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;

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

View File

@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">@color/mapboxGray</color>
<color name="colorPrimaryDark">@color/mapboxGrayDark10</color>
<color name="colorAccent">@color/mapboxPink</color>
<color name="msg_no_notes">#cf5e5e</color>
<color name="colorPrimary">#476483</color>
<color name="colorPrimaryDark">#3A3553</color>
<color name="colorAccent">#CF0E0F</color>
<color name="msg_no_notes">#89c3c3c3</color>
<color name="hint_enter_note">#89c3c3c3</color>
<color name="timestamp">#858585</color>
<color name="note_list_text">#232323</color>
<color name="colorWhite">#d1e200f6</color>
<color name="white">#ffffff</color>
<color name="colorWhiteTransparent">#80ffffff</color>
<color name="materialGrey">#F5F5F5</color>
<color name="materialDarkGrey">#dfdfdf</color>