This commit is contained in:
marcin.jedynski 2018-11-21 04:38:36 +01:00
commit f2357c846e
25 changed files with 877 additions and 251 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

@ -59,7 +59,7 @@ dependencies {
implementation 'com.auth0.android:jwtdecode:1.1.1' implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.annimon:stream:1.2.1' implementation 'com.annimon:stream:1.2.1'
implementation 'com.google.android.gms:play-services-location:16.0.0' implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.0.0'
// FloatingBarMenu // FloatingBarMenu
implementation 'com.getbase:floatingactionbutton:1.10.1' 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; package com.uam.wmi.findmytutor.activity;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Intent; 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.ActiveFragment;
import com.uam.wmi.findmytutor.utils.FeedbackUtils; import com.uam.wmi.findmytutor.utils.FeedbackUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RxSearchObservable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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; import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
@ -41,27 +49,29 @@ 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();
protected FeedbackUtils feedbackUtils; protected FeedbackUtils feedbackUtils;
private ActionBarDrawerToggle actionBarDrawerToggle; private ActionBarDrawerToggle actionBarDrawerToggle;
private SharingFragment sharingFragment; private SharingFragment sharingFragment;
private Fragment userListFragment; private Fragment userListFragment;
private ActiveFragment activeFragment = ActiveFragment.NONE; private ActiveFragment activeFragment = ActiveFragment.NONE;
private SearchView searchView;
@SuppressLint("CheckResult")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -73,13 +83,15 @@ 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))) {
@ -88,11 +100,12 @@ public abstract class BaseActivity
} 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());
@ -122,14 +135,12 @@ public abstract class BaseActivity
userListFragment = new UsersListFragment(); userListFragment = new UsersListFragment();
isTutor = PrefUtils.getIsTutor(getApplicationContext()); isTutor = PrefUtils.getIsTutor(getApplicationContext());
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>();
@ -193,9 +204,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();
} }
@ -247,38 +258,46 @@ public abstract class BaseActivity
actionBarDrawerToggle.onConfigurationChanged(newConfig); actionBarDrawerToggle.onConfigurationChanged(newConfig);
} }
@SuppressLint("CheckResult")
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu); getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem myActionMenuItem = menu.findItem(R.id.action_search); MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
final SearchView searchView = (SearchView) myActionMenuItem.getActionView(); searchView = (SearchView) myActionMenuItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String input) {
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
executeUserListSearch(input);
}
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; return true;
} }
private void executeUserListSearch(String input) { private void executeSearch(String input) {
((UsersListFragment) userListFragment).searchUser(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 @Override
@ -289,7 +308,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 +329,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) {

View File

@ -33,6 +33,7 @@ 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 java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -72,12 +73,6 @@ public class LoginActivity extends AppCompatActivity {
return false; return false;
}); });
Switch tutorLogin = findViewById(R.id.tutor_login_switch);
tutorLogin.setOnCheckedChangeListener((buttonView, isChecked) -> {
PrefUtils.storeIsTutor(getApplicationContext(), isChecked);
});
Button mEmailSignInButton = findViewById(R.id.email_sign_in_button); Button mEmailSignInButton = findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(view -> attemptLogin()); mEmailSignInButton.setOnClickListener(view -> attemptLogin());
@ -158,17 +153,9 @@ public class LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) { private void loginProcess(String email, String password) {
Log.e("LOGIN", String.valueOf(PrefUtils.getIsTutor(getApplicationContext()))); ValidateUser user = new ValidateUser(email, password);
//Fake validate disposable.add(ldapService.validate(user)
LdapUser user = new LdapUser(email, password, "admin", (PrefUtils.getIsTutor(getApplicationContext())) ? "Tutor" : "Student", "Imię", "Nazwisko", email);
// ValidateUser user = new ValidateUser(email, password);
// LDAP logging
// disposable.add(ldapService.validate(user)
disposable.add(ldapService.fakeValidate(user)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));
@ -192,13 +179,20 @@ public class LoginActivity extends AppCompatActivity {
String token = jwtToken.getToken(); String token = jwtToken.getToken();
JWT jwt = new JWT(token); JWT jwt = new JWT(token);
Claim role = jwt.getClaim("nameid"); Claim userId = jwt.getClaim("nameid");
Claim role = jwt.getClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
if(Objects.requireNonNull(role.asString()).equals("Student")){
PrefUtils.storeIsTutor(getApplicationContext(), false);
}
Log.e("LOGOWANIE",role.asString());
PrefUtils.storeIsLoggedIn(getApplicationContext(), true); PrefUtils.storeIsLoggedIn(getApplicationContext(), true);
PrefUtils.storeApiKey(getApplicationContext(), token); PrefUtils.storeApiKey(getApplicationContext(), token);
PrefUtils.storeUserId(getApplicationContext(), role.asString()); PrefUtils.storeUserId(getApplicationContext(), userId.asString());
getUserProfile(role.asString()); getUserProfile(userId.asString());
Intent data = new Intent(); Intent data = new Intent();
String txt = "Main Activity"; String txt = "Main Activity";

View File

@ -6,13 +6,9 @@ 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;
import com.getbase.floatingactionbutton.FloatingActionButton;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
@ -23,6 +19,8 @@ import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.annimon.stream.Stream;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.android.core.permissions.PermissionsListener; import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager; 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.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;
@ -56,6 +51,7 @@ import java.util.ArrayList;
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.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -64,14 +60,6 @@ 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;
public class MapActivity extends BaseActivity public class MapActivity extends BaseActivity
implements PermissionsListener, OnMapReadyCallback { implements PermissionsListener, OnMapReadyCallback {
@ -87,9 +75,14 @@ public class MapActivity extends BaseActivity
private int mInterval = 10000; private int mInterval = 10000;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private Runnable mStatusChecker; private Runnable mStatusChecker;
private Handler manualLocHandler = new Handler();
private Runnable manualLocStatusChecker;
private MapView mapView; private MapView mapView;
private MapboxMap mapboxMap; private MapboxMap mapboxMap;
private Button selectLocationButton;
private Marker droppedMarker; private Marker droppedMarker;
private Marker tmpLocalMarker;
private Coordinate droppedMarkercoordinate;
private HashMap<String, Coordinate> coordsMap = new HashMap<>(); private HashMap<String, Coordinate> coordsMap = new HashMap<>();
private HashMap<String, Marker> markerHash = new HashMap<>(); private HashMap<String, Marker> markerHash = new HashMap<>();
private Set<String> previousCoordsIds = new HashSet<>(); private Set<String> previousCoordsIds = new HashSet<>();
@ -98,13 +91,15 @@ public class MapActivity extends BaseActivity
private int zoomParam = 17; private int zoomParam = 17;
private int bearingParam = 180; private int bearingParam = 180;
private int tiltParam = 30; private int tiltParam = 30;
private String myID;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
myID = PrefUtils.getUserId(getApplicationContext());
// fetching coords service // fetching coords service
coordinateService = ApiClient.getClient(getApplicationContext()) coordinateService = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class); .create(CoordinateService.class);
@ -120,8 +115,10 @@ public class MapActivity extends BaseActivity
} }
}; };
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
selectLocationButton = findViewById(R.id.select_location_button);
Mapbox.getInstance(this, getString(R.string.access_token)); Mapbox.getInstance(this, getString(R.string.access_token));
mapView = findViewById(R.id.mapView); mapView = findViewById(R.id.mapView);
@ -132,14 +129,31 @@ 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;
mStatusChecker.run(); mStatusChecker.run();
enableLocationPlugin(); enableLocationPlugin();
mapboxMap.setOnMarkerClickListener(marker -> { mapboxMap.setOnMarkerClickListener(marker -> {
createMarkerModal(marker.getTitle()); String id = marker.getTitle();
if (id.equals(myID)) {
Log.e(tag + "Manual", "my own marker from API");
Button rmButton = findViewById(R.id.remove_location_button);
rmButton.setVisibility(View.VISIBLE);
rmButton.setOnClickListener(view -> {
Log.e(tag + "Manual", "manual coords sending stopped");
// TODO to remove after BGserv
manualLocHandler.removeCallbacks(manualLocStatusChecker);
rmButton.setVisibility(View.GONE);
Toast.makeText(MapActivity.this, "Your marker will disappear in next couple minutes", Toast.LENGTH_SHORT).show();
});
} else {
createMarkerModal(id);
}
return true; return true;
}); });
@ -198,148 +212,121 @@ public class MapActivity extends BaseActivity
} }
// Manual loc selection on long tap private void handleError(Throwable error) {
private void setOnMapLongClickListener() { showError(error);
}
final boolean[] cancel = {false}; private void showError(Throwable e) {
Button selectLocationButton = findViewById(R.id.select_location_button); 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() {
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> { mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
selectLocationButton.setVisibility(View.VISIBLE); selectLocationButton.setVisibility(View.VISIBLE);
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker); Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
if (tmpLocalMarker == null) {
if (droppedMarker == null) { tmpLocalMarker = mapboxMap.addMarker(new MarkerOptions()
droppedMarker = mapboxMap.addMarker(new MarkerOptions()
.position(latLng) .position(latLng)
.icon(icon) .icon(icon)
.title("My Loc") .title("My Loc")
.setSnippet("Snipecik")); .setSnippet("Snipecik"));
} else if (!cancel[0]) { } else {
ValueAnimator markerAnimator = ObjectAnimator.ofObject(droppedMarker, "position", ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position",
new mapUtils.LatLngEvaluator(), droppedMarker.getPosition(), latLng); new mapUtils.LatLngEvaluator(), tmpLocalMarker.getPosition(), latLng);
markerAnimator.setDuration(2000); markerAnimator.setDuration(2000);
markerAnimator.start(); markerAnimator.start();
} }
selectLocationButton.setOnClickListener((View view) -> { selectLocationButton.setOnClickListener((View view) -> {
if (tmpLocalMarker != null) {
if (!cancel[0] && droppedMarker != null) {
// Toast instructing user to tap on the mapboxMap // Toast instructing user to tap on the mapboxMap
// TODO PUT MANUAL CORD // TODO PUT MANUAL CORD
try { try {
Coordinate coordinate = new Coordinate( droppedMarkercoordinate = new Coordinate(
latLng.getLatitude(), latLng.getLatitude(),
latLng.getLongitude(), latLng.getLongitude(),
latLng.getAltitude(), latLng.getAltitude(),
"approx",
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()), PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
PrefUtils.getUserId(getApplicationContext()), PrefUtils.getUserId(getApplicationContext()),
PrefUtils.getLocationLevel(getApplicationContext()) PrefUtils.getLocationLevel(getApplicationContext())
); );
disposable.add( // TODO remove after BG sending
coordinateService manualLocStatusChecker = () -> {
.postCoordinate(coordinate) try {
.subscribeOn(Schedulers.io()) Log.e(tag + "Manual", "sending manual coords");
.observeOn(AndroidSchedulers.mainThread()) // TODO ^^^ wrapper to removve
.subscribeWith(new DisposableSingleObserver<Coordinate>() { disposable.add(
@SuppressLint("LongLogTag") coordinateService
@Override .postCoordinate(droppedMarkercoordinate)
public void onSuccess(Coordinate coord) { .subscribeOn(Schedulers.io())
Log.e(tag + "POST", String.valueOf(coord)); .observeOn(AndroidSchedulers.mainThread())
} .subscribeWith(new DisposableSingleObserver<Coordinate>() {
@SuppressLint("LongLogTag")
@Override
public void onSuccess(Coordinate coord) {
Log.e(tag + "POST", String.valueOf(coord));
}
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.e(tag + "onError", e.getMessage()); Log.e(tag + "onError", e.getMessage());
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
Log.e(tag + "onError", RestApiHelper.getErrorMessage(responseBody));
}
}
}));
// TODO \/\/\/\/\/ wrapper to removve
} finally {
manualLocHandler.postDelayed(manualLocStatusChecker, mInterval);
}
};
manualLocStatusChecker.run();
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
Log.e(tag + "onError", RestApiHelper.getErrorMessage(responseBody));
}
}
}));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Timber.e(String.valueOf(e)); Timber.e(String.valueOf(e));
} }
Toast.makeText( Toast.makeText(
MapActivity.this, MapActivity.this,
"Manual Locations selected!" + latLng, "Manual Locations selected!" + latLng,
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show(); ).show();
selectLocationButton.setBackgroundColor(
ContextCompat.getColor(MapActivity.this, R.color.colorAccent));
selectLocationButton.setText("Remove Manual location");
selectLocationButton.setVisibility(View.VISIBLE);
cancel[0] = true;
} else {
// TODO REMOVE Manual Locatio
mapboxMap.removeMarker(droppedMarker);
droppedMarker = null;
Toast.makeText(
MapActivity.this,
"REMOVED!!" + latLng,
Toast.LENGTH_LONG
).show();
cancel[0] = false;
selectLocationButton.setVisibility(View.GONE); selectLocationButton.setVisibility(View.GONE);
selectLocationButton.setText(R.string.select_a_location); mapboxMap.removeMarker(tmpLocalMarker);
selectLocationButton.setBackgroundColor( tmpLocalMarker = null;
ContextCompat.getColor(MapActivity.this, R.color.colorPrimary));
} }
}); });
}); });
} }
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(
// coordinateService.getTopCoordinates()
coordinateService.getOnlineCoordinates() coordinateService.getOnlineCoordinates()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -348,12 +335,17 @@ public class MapActivity extends BaseActivity
@Override @Override
public void onSuccess(List<Coordinate> coordsList) { public void onSuccess(List<Coordinate> coordsList) {
if (coordsList.isEmpty()) {
Log.e(tag, "200 empty []"); if (coordsList.isEmpty() && droppedMarker == null) {
//mapboxMap.clear(); Timber.e("200 empty []");
return; mapboxMap.clear();
} }
if (coordsList.isEmpty()) {
Timber.e("200 empty []");
mapboxMap.clear();
return;
}
ArrayList<String> tmp = new ArrayList<>(); ArrayList<String> tmp = new ArrayList<>();
for (Coordinate coordinate : coordsList) { for (Coordinate coordinate : coordsList) {
@ -364,7 +356,7 @@ public class MapActivity extends BaseActivity
if (previousCoordsIds.isEmpty()) { if (previousCoordsIds.isEmpty()) {
previousCoordsIds.addAll(currentCoordsIds); previousCoordsIds.addAll(currentCoordsIds);
} else { } 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)) { 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));
@ -389,9 +381,6 @@ public class MapActivity extends BaseActivity
if (coordinate != null) { if (coordinate != null) {
Log.e(tag, "Coordin: " + coordinate.getLatitude() + " | " + coordinate.getLongitude()); Log.e(tag, "Coordin: " + coordinate.getLatitude() + " | " + coordinate.getLongitude());
// Log.e(tag, "Element: " + element.getLatitude()+" | " + element.getLongitude());
// Log.e(tag, "isEqual: " + coordinate.getLatitude().equals(element.getLatitude()));
// Log.e(tag, "isEqual: " + coordinate.getLongitude().equals(element.getLongitude()));
boolean statement = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude()); boolean statement = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
Log.e(tag, "diff || diff: " + !statement); Log.e(tag, "diff || diff: " + !statement);
@ -417,13 +406,20 @@ 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()));
// 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);
markerHash.put(id, marker); markerHash.put(id, marker);
} }
@ -549,6 +545,8 @@ public class MapActivity extends BaseActivity
super.onDestroy(); super.onDestroy();
mapView.onDestroy(); mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker); mHandler.removeCallbacks(mStatusChecker);
// TODO remove after BG sending
manualLocHandler.removeCallbacks(manualLocStatusChecker);
disposable.dispose(); disposable.dispose();
} }
@ -589,20 +587,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) { private void getUserFromApi(String userNameToSearch) {
String message; 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) { @Override
ResponseBody responseBody = ((HttpException) e).response().errorBody(); public void onError(Throwable e) {
message = RestApiHelper.getErrorMessage(responseBody); showError(e);
} else { }
message = "Network Error!"; }));
}
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

@ -27,8 +27,10 @@ import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.service.FeedbackService; import com.uam.wmi.findmytutor.service.FeedbackService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService; import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
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.RightButtonPreference; import com.uam.wmi.findmytutor.utils.RightButtonPreference;
import com.uam.wmi.findmytutor.utils.SharingLevel;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -98,10 +100,10 @@ public class SharingFragment extends PreferenceFragment {
getStatuses(disposable); getStatuses(disposable);
locationLevelMapping = new HashMap<Integer, String>(); locationLevelMapping = new HashMap<Integer, String>();
locationLevelMapping.put(0,"presence"); locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
locationLevelMapping.put(1,"approximated"); locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
locationLevelMapping.put(2,"exact"); locationLevelMapping.put(2, SharingLevel.EXACT.toString());
locationLevelMapping.put(3,"manual"); locationLevelMapping.put(2, SharingLevel.MANUAL.toString());
statusMapping = new HashMap<Integer, String>(); statusMapping = new HashMap<Integer, String>();
statusMapping.put(0,"available"); statusMapping.put(0,"available");
@ -117,7 +119,6 @@ public class SharingFragment extends PreferenceFragment {
/** Sharing level list **/ /** Sharing level list **/
locationMode.setOnPreferenceChangeListener((preference, newValue) -> { locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference;
PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue))); PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue)));
if(PrefUtils.getLocationLevel(getApplicationContext()) == "manual"){ if(PrefUtils.getLocationLevel(getApplicationContext()) == "manual"){
preferenceCategory.addPreference(manualLocationList); preferenceCategory.addPreference(manualLocationList);
@ -139,6 +140,7 @@ public class SharingFragment extends PreferenceFragment {
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> { manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference; ListPreference lp = (ListPreference) preference;
//ToDo handle manual location change //ToDo handle manual location change
return true; return true;
}); });
/** Button 'choose from map' button listener **/ /** Button 'choose from map' button listener **/

View File

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

View File

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

View File

@ -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();

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.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.OnSuccessListener;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.geojson.Point;
import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.ApiClient; 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.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 java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -43,6 +47,9 @@ import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import timber.log.Timber; 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; import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
public class BackgroundLocalizationService extends Service { public class BackgroundLocalizationService extends Service {
@ -50,7 +57,6 @@ public class BackgroundLocalizationService extends Service {
private static final String TAG = "MyLocationService"; private static final String TAG = "MyLocationService";
private static final int LOCATION_INTERVAL = 1000; private static final int LOCATION_INTERVAL = 1000;
private static final float LOCATION_DISTANCE = 5f; private static final float LOCATION_DISTANCE = 5f;
public static String str_receiver = "background.location.broadcast";
private static long notify_interval = 10000; private static long notify_interval = 10000;
Location mLastLocation; Location mLastLocation;
Boolean stopService = false; Boolean stopService = false;
@ -64,6 +70,7 @@ public class BackgroundLocalizationService extends Service {
private Runnable mStatusChecker; private Runnable mStatusChecker;
private FusedLocationProviderClient mFusedLocationClient; private FusedLocationProviderClient mFusedLocationClient;
public BackgroundLocalizationService() { public BackgroundLocalizationService() {
providers.add(LocationManager.GPS_PROVIDER); providers.add(LocationManager.GPS_PROVIDER);
providers.add(LocationManager.NETWORK_PROVIDER); providers.add(LocationManager.NETWORK_PROVIDER);
@ -74,6 +81,7 @@ public class BackgroundLocalizationService extends Service {
new LocationListener(LocationManager.NETWORK_PROVIDER), new LocationListener(LocationManager.NETWORK_PROVIDER),
new LocationListener(LocationManager.PASSIVE_PROVIDER) new LocationListener(LocationManager.PASSIVE_PROVIDER)
}; };
} }
@Override @Override
@ -90,7 +98,7 @@ public class BackgroundLocalizationService extends Service {
stopService = intent.getBooleanExtra("request_stop", false); stopService = intent.getBooleanExtra("request_stop", false);
} }
if (stopService) { if (stopService) {
storeBackgroundLocationStatus(getApplication(),false); storeBackgroundLocationStatus(getApplication(), false);
stopForeground(true); stopForeground(true);
stopSelf(); stopSelf();
return START_STICKY; return START_STICKY;
@ -102,7 +110,7 @@ public class BackgroundLocalizationService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
Log.e(TAG, "onCreate"); Log.e(TAG, "onCreate");
storeBackgroundLocationStatus(getApplication(),true); storeBackgroundLocationStatus(getApplication(), true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startMyOwnForeground(); startMyOwnForeground();
@ -114,7 +122,6 @@ public class BackgroundLocalizationService extends Service {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
initializeLocationManager(); initializeLocationManager();
Integer providerIndex = 0; Integer providerIndex = 0;
@ -137,7 +144,7 @@ public class BackgroundLocalizationService extends Service {
providerIndex++; providerIndex++;
} }
if(!stopService){ if (!stopService) {
mStatusChecker = () -> { mStatusChecker = () -> {
try { try {
fn_getlocation(); fn_getlocation();
@ -202,20 +209,12 @@ public class BackgroundLocalizationService extends Service {
Log.e("Best localization:", String.valueOf(bestLocation)); Log.e("Best localization:", String.valueOf(bestLocation));
/* if (bestLocation != null)
fn_update(bestLocation);
*/
mFusedLocationClient.getLastLocation().addOnSuccessListener( mFusedLocationClient.getLastLocation().addOnSuccessListener(
new OnSuccessListener<Location>() { location -> {
@Override if (location != null) {
public void onSuccess(Location location) { mLastLocation = location;
if (location != null) { fn_update(location);
mLastLocation = location;
fn_update(location);
}
} }
}); });
} }
@ -283,11 +282,13 @@ public class BackgroundLocalizationService extends Service {
} }
} }
@SuppressLint("StaticFieldLeak")
private class Task extends AsyncTask { private class Task extends AsyncTask {
ApproximatedLocalization approximatedLocalization;
private Double latitude; private Double latitude;
private Double longitude; private Double longitude;
private Double altitude; private Double altitude;
private String approximatedBuildingPart = null;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext()) private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class); .create(CoordinateService.class);
@ -296,16 +297,30 @@ public class BackgroundLocalizationService extends Service {
latitude = location.getLatitude(); latitude = location.getLatitude();
longitude = location.getLongitude(); longitude = location.getLongitude();
altitude = location.getAltitude(); altitude = location.getAltitude();
approximatedLocalization = new ApproximatedLocalization(mapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
} }
@Override @Override
protected Object doInBackground(Object[] objects) { 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 { try {
Coordinate coordinate = new Coordinate( Coordinate coordinate = new Coordinate(
latitude, latitude,
longitude, longitude,
altitude, altitude,
approximatedBuildingPart,
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "", (PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "",
PrefUtils.getUserId(getApplicationContext()), PrefUtils.getUserId(getApplicationContext()),
PrefUtils.getLocationLevel(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

@ -138,7 +138,7 @@ public class PrefUtils {
} }
public static String getLocale(Context context) { public static String getLocale(Context context) {
return getSharedPreferences(context).getString("LOCALE", "pl"); return getSharedPreferences(context).getString("LOCALE", "en");
} }
public static Boolean isBackgroundLocationServiceRunning(Context context) { public static Boolean isBackgroundLocationServiceRunning(Context context) {

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,19 @@
package com.uam.wmi.findmytutor.utils;
public enum SharingLevel {
PRESENCE("presence"),
APPROXIMATED("approximated"),
EXACT("exact"),
MANUAL("manual");
private final String text;
SharingLevel(final String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}

View File

@ -6,6 +6,7 @@ import android.graphics.Color;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.content.res.AssetManager;
import com.mapbox.mapboxsdk.annotations.Polygon; import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.PolygonOptions;
@ -29,6 +30,23 @@ public class mapUtils {
.include(new LatLng(52.46548540224137, 16.925255680881094)) .include(new LatLng(52.46548540224137, 16.925255680881094))
.build(); .build();
// Map Bounds Area
public static void setMapBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
if (check) {
// Set bounds to WMI
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
makeNewCamera(mapboxMap, 52.466799, 16.927002, 17, 0, 0, 4000);
mapboxMap.setMinZoomPreference(16); // TODO export to map config
// drawBoundsArea(context, mapboxMap, mapView, check);
} else {
mapboxMap.setLatLngBoundsForCameraTarget(null);
mapboxMap.setMinZoomPreference(2);
// drawBoundsArea(context, mapboxMap, mapView, check);
}
}
// TODO: remove b4 release
private static final PolygonOptions boundsArea = new PolygonOptions() private static final PolygonOptions boundsArea = new PolygonOptions()
.add(WMI_BOUNDS.getNorthWest()) .add(WMI_BOUNDS.getNorthWest())
.add(WMI_BOUNDS.getNorthEast()) .add(WMI_BOUNDS.getNorthEast())
@ -40,15 +58,8 @@ public class mapUtils {
private static Polygon polygon; private static Polygon polygon;
private static View crosshair; private static View crosshair;
// Map Bounds Area private static void drawBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
public static void setMapBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
if (check) { if (check) {
// Set bounds to WMI
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
makeNewCamera(mapboxMap, 52.466799, 16.927002, 17, 0, 0,4000);
mapboxMap.setMinZoomPreference(16); // TODO export to map config
// Visualise bounds area // Visualise bounds area
// showBoundsArea // showBoundsArea
polygon = mapboxMap.addPolygon(boundsArea); polygon = mapboxMap.addPolygon(boundsArea);
@ -58,16 +69,13 @@ public class mapUtils {
crosshair.setBackgroundColor(Color.GREEN); crosshair.setBackgroundColor(Color.GREEN);
mapView.addView(crosshair); mapView.addView(crosshair);
} else { } else {
mapboxMap.setLatLngBoundsForCameraTarget(null);
mapboxMap.setMinZoomPreference(2);
mapboxMap.removePolygon(polygon); mapboxMap.removePolygon(polygon);
mapView.removeView(crosshair); mapView.removeView(crosshair);
} }
} }
public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration){ public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration) {
CameraPosition position = new CameraPosition.Builder() CameraPosition position = new CameraPosition.Builder()
.target(new LatLng(lat, lon)) // Sets the new camera position .target(new LatLng(lat, lon)) // Sets the new camera position
.zoom(zoomParam) // Sets the zoom .zoom(zoomParam) // Sets the zoom
@ -79,22 +87,6 @@ public class mapUtils {
.newCameraPosition(position), duration); .newCameraPosition(position), duration);
} }
// Function for marker animation
public static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation.
private LatLng latLng = new LatLng();
@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
latLng.setLatitude(startValue.getLatitude()
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
latLng.setLongitude(startValue.getLongitude()
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
return latLng;
}
}
// read file to JSON // read file to JSON
public static String loadJsonFromAsset(Context context, String filename) { public static String loadJsonFromAsset(Context context, String filename) {
// Using this method to load in GeoJSON files from the assets folder. // Using this method to load in GeoJSON files from the assets folder.
@ -112,4 +104,20 @@ public class mapUtils {
} }
} }
// Function for marker animation
public static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation.
private LatLng latLng = new LatLng();
@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
latLng.setLatitude(startValue.getLatitude()
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
latLng.setLongitude(startValue.getLongitude()
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
return latLng;
}
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 923 B

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -72,11 +72,6 @@
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
<Switch
android:id="@+id/tutor_login_switch"
android:layout_width="192dp"
android:layout_height="wrap_content"
android:text="Login as Tutor" />
<Button <Button
android:id="@+id/email_sign_in_button" android:id="@+id/email_sign_in_button"

View File

@ -111,6 +111,17 @@
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:visibility="gone" /> android:visibility="gone" />
<Button
android:id="@+id/remove_location_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="8dp"
android:background="@color/colorAccent"
android:text="@string/remove_manual_location"
android:textColor="@android:color/white"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View File

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

View File

@ -212,5 +212,7 @@
<string name="remove_location_updates" translatable="false" /> <string name="remove_location_updates" translatable="false" />
<string name="map_activity_label" translatable="false">MapActivity</string> <string name="map_activity_label" translatable="false">MapActivity</string>
<string name="nav_profile">User profile</string> <string name="nav_profile">User profile</string>
<string name="remove_manual_location">Remove Manual location</string>
</resources> </resources>