Merge branch 'develop' into blackNwhiteLists

This commit is contained in:
Domagalski 2019-01-03 21:47:50 +01:00
commit 1eed752b1a
15 changed files with 230 additions and 86 deletions

View File

@ -29,7 +29,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -53,6 +53,7 @@ import io.reactivex.schedulers.Schedulers;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
import static com.uam.wmi.findmytutor.utils.Const.defaultMapZoom;
import static com.uam.wmi.findmytutor.utils.Const.onlineBackgroundLocationInterval;
import static com.uam.wmi.findmytutor.utils.Const.searchMapZoom;
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
@ -200,7 +201,6 @@ public abstract class BaseActivity
public void stopBackgroundLocalizationTask() {
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
stopIntent.putExtra("request_stop", true);
Log.e("Localization", "JEstem w stop BG");
stopService(stopIntent);
@ -210,6 +210,7 @@ public abstract class BaseActivity
checkPermissions();
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
startIntent.putExtra("notify_interval", onlineBackgroundLocationInterval);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
startForegroundService(startIntent);
@ -219,17 +220,12 @@ public abstract class BaseActivity
}
public void handleBackgroundTaskLifeCycle() {
Log.e("Localization", String.valueOf(PrefUtils.isEnableSharingLocalization(getApplicationContext())));
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()) && isTutor;
Log.e("Localization", String.valueOf(shouldServiceRun));
if (shouldServiceRun) {
startBackgroundLocalizationTask();
Log.e("Localization", "JEstem i odpalam");
} else {
stopBackgroundLocalizationTask();
Log.e("Localization", "JEstem i nie odpalam");
}
}
@ -285,7 +281,6 @@ public abstract class BaseActivity
getMenuInflater().inflate(R.menu.menu_main, menu);
infoMenuItem = menu.findItem(R.id.action_info);
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
searchView = (SearchView) myActionMenuItem.getActionView();
@ -295,6 +290,10 @@ public abstract class BaseActivity
adjustMapToSearch(defaultMapZoom);
}
if (!hasFocus && activeFragment.equals(ActiveFragment.USER_LIST)) {
((UsersListFragment) userListFragment).restoreUsersList();
}
if(hasFocus && activeFragment.equals(ActiveFragment.NONE)){
adjustMapToSearch(searchMapZoom);
}
@ -303,6 +302,7 @@ public abstract class BaseActivity
RxSearchObservable.fromView(searchView)
.skip(0)
.map(String::toLowerCase)
.filter(t -> !t.isEmpty())
.debounce(250, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())

View File

@ -333,7 +333,7 @@ public class MapActivity extends BaseActivity
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
EditText modalUserInput = view.findViewById(R.id.feedback_input);
EditText modalUserInput = view.findViewById(R.id.manual_input);
alertDialog.setOnShowListener(dialogInterface -> {
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);

View File

@ -153,6 +153,8 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
/** Sharing level list **/
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
((MapActivity) getActivity()).stopBackgroundLocalizationTask();
((MapActivity) getActivity()).startBackgroundLocalizationTask();
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));

View File

@ -10,6 +10,7 @@ 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.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -160,11 +161,7 @@ public class UsersListFragment extends Fragment {
}
public void searchUser(String textToSearch) {
tutorsFiltered.clear();
tutorsFiltered.addAll(Stream.of(tutorsList).filter(t ->
t.toSearchAbleString().toLowerCase().contains(textToSearch.toLowerCase())).toList());
mAdapter.notifyDataSetChanged();
searchTutorInBackend(textToSearch);
}
private void showNoteDialog(final User user) {
@ -232,7 +229,7 @@ public class UsersListFragment extends Fragment {
private void fetchAllTutors() {
disposable.add(
(fetchOnlyOnlineUsers ?
userService.getAllOnlineTutors() :
userService.getAllActiveTutors() :
userService.getAllOfflineTutors())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -276,6 +273,31 @@ public class UsersListFragment extends Fragment {
}
private void searchTutorInBackend(String searchString) {
disposable.add(
userService.searchUser(searchString)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<User>>() {
@Override
public void onSuccess(List<User> users) {
tutorsFiltered.clear();
tutorsFiltered.addAll(users);
mAdapter.notifyDataSetChanged();
}
@Override
public void onError(Throwable e) {
showSearchError(e);
}
}));
}
public void restoreUsersList(){
fetchAllTutors();
}
private int sortByUserName(User t1, User t2) {
return plCollator.compare(t1.getLastName(), t2.getLastName());
}
@ -288,11 +310,33 @@ public class UsersListFragment extends Fragment {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
} else {
message = "Network Error !";
message = getString(R.string.network_err);
}
Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG)
.show();
createSnackbar(message);
}
private void showSearchError(Throwable e) {
String message;
Log.e(TAG, String.valueOf(e));
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
} else {
message = getString(R.string.search_null);
}
createSnackbar(message);
}
private void createSnackbar(String msg){
Snackbar snackbar = Snackbar.make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);
View view = snackbar.getView();
CoordinatorLayout.LayoutParams params=(CoordinatorLayout.LayoutParams)view.getLayoutParams();
params.gravity = Gravity.TOP;
view.setLayoutParams(params);
snackbar.show();
}
private void toggleEmptyNotes() {

View File

@ -11,11 +11,13 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat;
@ -23,6 +25,9 @@ import android.util.Log;
import com.annimon.stream.Stream;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
@ -54,10 +59,11 @@ import static java.lang.String.valueOf;
public class BackgroundLocalizationService extends Service {
private static final String TAG = "MyLocationService";
private static long notify_interval = onlineBackgroundLocationInterval;
private static long notify_interval_inside_building = onlineBackgroundLocationInterval;
private static long notify_interval_outside_building = offlineBackgroundLocationInterval;
private static Integer notify_interval = onlineBackgroundLocationInterval;
private static Integer notify_interval_inside_building = onlineBackgroundLocationInterval;
private static Integer notify_interval_outside_building = offlineBackgroundLocationInterval;
private static int coordinatesHistoryLength = 5;
private Boolean highAccuracyMode;
private Location mLastLocation;
private Boolean stopService = false;
private ArrayList<String> providers = new ArrayList<String>();
@ -66,6 +72,10 @@ public class BackgroundLocalizationService extends Service {
private Runnable mStatusChecker;
private FusedLocationProviderClient mFusedLocationClient;
private Location fakeLoc = null;
private LocationRequest mLocationRequest;
private Location mCurrentLocation;
private LocationCallback mLocationCallback;
private LocationListener mLocationListener;
public BackgroundLocalizationService() {
providers.add(LocationManager.GPS_PROVIDER);
@ -90,7 +100,9 @@ public class BackgroundLocalizationService extends Service {
if (intent != null) {
stopService = intent.getBooleanExtra("request_stop", false);
notify_interval = intent.getIntExtra("notify_interval", onlineBackgroundLocationInterval);
}
if (stopService) {
storeBackgroundLocationStatus(getApplication(), false);
stopForeground(true);
@ -101,6 +113,20 @@ public class BackgroundLocalizationService extends Service {
return START_STICKY;
}
private void createLocationCallback() {
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
if (locationResult != null) {
mCurrentLocation = locationResult.getLastLocation();
sendCoordinateToBackend(mCurrentLocation);
changeBackgroundMode();
}
}
};
}
@Override
public void onCreate() {
Log.e(TAG, "onCreate");
@ -114,20 +140,14 @@ public class BackgroundLocalizationService extends Service {
startForeground(1001, notification);
}
if (!stopService) {
if (!stopService && !PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
createFusedLocationClient();
} else if (!stopService &&
PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
mStatusChecker = () -> {
try {
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
sendCoordinateToBackend(fakeLoc);
} else {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
getLocalizationFromListeners();
changeBackgroundMode();
}
sendCoordinateToBackend(fakeLoc);
} finally {
mFusedLocationClient = null;
destroyLocationListeners();
mHandler.postDelayed(mStatusChecker, notify_interval);
}
};
@ -136,21 +156,54 @@ public class BackgroundLocalizationService extends Service {
}
}
private void changeBackgroundMode() {
if (coordinatesHistory.size() > 4) {
Boolean shouldExtendTimeInterval = Stream.of(coordinatesHistory)
.map(MapUtils::checkIfCoordinateIsValid).takeWhile(s -> !s).toList().size() == coordinatesHistory.size();
Boolean shouldAbbreviateTimeInterval = Stream.of(coordinatesHistory).
map(MapUtils::checkIfCoordinateIsValid).toList().get(coordinatesHistory.size() - 1);
if (shouldExtendTimeInterval) {
notify_interval = notify_interval_outside_building;
} else if (shouldAbbreviateTimeInterval) {
notify_interval = notify_interval_inside_building;
}
private void createFusedLocationClient() {
Integer saveMode = Long.valueOf(notify_interval).compareTo(Long.valueOf(offlineBackgroundLocationInterval));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mLocationRequest = new LocationRequest();
if (saveMode != 0) {
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
} else {
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
}
mLocationRequest.setFastestInterval(notify_interval);
mLocationRequest.setInterval(notify_interval);
createLocationCallback();
if (!stopService) {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mFusedLocationClient.requestLocationUpdates(mLocationRequest,
mLocationCallback, Looper.getMainLooper());
}
}
private void changeBackgroundMode() {
Integer prevInterval = notify_interval;
Boolean shouldExtendTimeInterval = Stream.of(coordinatesHistory)
.map(MapUtils::checkIfCoordinateIsValid).takeWhile(s -> !s).toList().size() == coordinatesHistory.size();
Boolean shouldAbbreviateTimeInterval = Stream.of(coordinatesHistory).
map(MapUtils::checkIfCoordinateIsValid).filter(x -> x).toList().size() > 0;
if (shouldAbbreviateTimeInterval) {
notify_interval = notify_interval_inside_building;
}
if (coordinatesHistory.size() > 4 && shouldExtendTimeInterval) {
notify_interval = notify_interval_outside_building;
}
Integer changedMode = Long.valueOf(prevInterval).compareTo(Long.valueOf(notify_interval));
if (changedMode != 0) {
updateListeners();
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
@ -173,30 +226,6 @@ public class BackgroundLocalizationService extends Service {
startForeground(2, notification);
}
private void getLocalizationFromListeners() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mFusedLocationClient.getLastLocation().addOnSuccessListener(
location -> {
if (location != null) {
mLastLocation = location;
coordinatesHistory.add(location);
sendCoordinateToBackend(location);
}
});
}
private void sendCoordinateToBackend(Location location) {
new Task(location).execute();
}
@ -211,7 +240,41 @@ public class BackgroundLocalizationService extends Service {
}
private void destroyLocationListeners() {
if (mFusedLocationClient != null) {
mFusedLocationClient.removeLocationUpdates(mLocationCallback);
mFusedLocationClient = null;
mLocationCallback = null;
mLocationRequest = null;
}
}
private void updateListeners() {
if (mFusedLocationClient != null) {
mFusedLocationClient.removeLocationUpdates(mLocationCallback)
.addOnCompleteListener(task -> {
restartService();
mFusedLocationClient = null;
mLocationCallback = null;
mLocationRequest = null;
});
}
}
private void restartService() {
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
stopIntent.putExtra("request_stop", true);
stopService(stopIntent);
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
startIntent.putExtra("notify_interval", notify_interval);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
startForegroundService(startIntent);
} else {
startService(startIntent);
}
}
@ -260,6 +323,12 @@ public class BackgroundLocalizationService extends Service {
approximatedBuildingPart = PrefUtils.getManualLocationApproximation(getApplicationContext());
}
Location fakeLoc = new Location("");
fakeLoc.setLatitude(latitude);
fakeLoc.setLongitude(longitude);
coordinatesHistory.add(fakeLoc);
try {
Coordinate coordinate = new Coordinate(
latitude,
@ -277,7 +346,6 @@ public class BackgroundLocalizationService extends Service {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableCompletableObserver() {
@Override
public void onComplete() {
Log.e(TAG, "CoordinateSuccess");
@ -285,9 +353,7 @@ public class BackgroundLocalizationService extends Service {
@Override
public void onError(Throwable e) {
Log.e(TAG, "onErr" + valueOf(e));
}
}));
} catch (IllegalArgumentException e) {

View File

@ -19,6 +19,7 @@ import retrofit2.http.HTTP;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
public interface UserService {
@ -34,9 +35,15 @@ public interface UserService {
@GET("api/users/tutors/online")
Single <List<User>> getAllOnlineTutors();
@GET("api/users/tutors/active")
Single <List<User>> getAllActiveTutors();
@GET("api/users/tutors/offline")
Single <List<User>> getAllOfflineTutors();
@GET("api/users/tutors/search")
Single <List<User>> searchUser(@Query(value = "searchString", encoded = true) String searchString);
@POST("api/users")
Completable createUser(@Body User user);

View File

@ -6,9 +6,9 @@ import java.util.Arrays;
import java.util.List;
public class Const {
public final static String BASE_URL = "https://s416084.projektstudencki.pl/develop/";
public final static String BASE_URL = "https://s416084.projektstudencki.pl/master/";
public final static Integer onlineBackgroundLocationInterval = 7000;
public final static Integer offlineBackgroundLocationInterval = 36000;
public final static Integer offlineBackgroundLocationInterval = 360000;
public final static Integer defaultMapZoom = 17;
public final static Integer searchMapZoom = 13;
public final static Double presenceLatitude = 52.466365;

View File

@ -21,6 +21,7 @@ public class RxSearchObservable {
@Override
public boolean onQueryTextSubmit(String s) {
subject.onNext(s);
searchView.clearFocus();
return false;
}
@ -31,6 +32,8 @@ public class RxSearchObservable {
}
});

View File

@ -72,4 +72,6 @@
android:text="@string/info_icon_userlist_summary"
android:textColor="@color/half_black"/>
</LinearLayout>

View File

@ -24,14 +24,14 @@
android:textStyle="normal" />
<EditText
android:id="@+id/feedback_input"
android:id="@+id/manual_input"
android:layout_width="315dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="@string/modal_feedback_hint"
android:hint="@string/modal_manual_hint"
android:maxLength="30"
android:maxLines="1"
android:requiresFadingEdge="vertical"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:clickable="true"
android:focusable="true"
@ -13,7 +13,7 @@
<TextView
android:id="@+id/firstName"
android:layout_width="271dp"
android:layout_width="270dp"
android:layout_height="22dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
@ -26,23 +26,25 @@
android:id="@+id/lastName"
android:layout_width="270dp"
android:layout_height="22dp"
android:layout_marginStart="12dp"
android:layout_below="@+id/firstName"
android:layout_alignEnd="@+id/firstName"
android:layout_marginTop="10dp"
android:layout_marginEnd="0dp"
android:layout_alignParentStart="true"
android:textColor="@color/note_list_text"
android:textSize="15sp" />
<TextView
android:id="@+id/isOnline"
android:layout_width="48dp"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_below="@+id/firstName"
android:layout_marginStart="7dp"
android:layout_marginTop="-10dp"
android:layout_toEndOf="@+id/firstName"
android:textColor="@color/note_list_text"
android:layout_alignParentEnd="true"
android:textSize="@dimen/note_list_text" />

View File

@ -6,6 +6,8 @@
android:id="@+id/action_search"
android:icon="@drawable/ic_menu_search"
app:showAsAction="always"
android:focusable="true"
android:focusableInTouchMode="true"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="@string/search"/>
<item

View File

@ -253,15 +253,18 @@
<string name="scrap_tutor_tab">Pobierz dane z WMI</string>
<string name="scrap_tutor_msg">Dane zostały zaktualizwane!</string>
<string name="no_online_users">Brak użytkowników online.</string>
<!--(ENG) Checkbox online users list -->
<string name="no_online_users">Brak aktywnych użytkowników.</string>
<string name="no_offline_users">Brak użytkowników offline.</string>
<string name="only_online_users">Tylko użytkownicy online</string>
<string name="activity_title_blacklist">Czarna lista</string>
<string name="activity_title_whitelist">Biała lista</string>
<string name="title_activity_white_list">Biała lista</string>
<string name="white_list_title">Dodaj użytkownika do białej listy</string>
<string name="no_such_a_user">Nie ma takiego użytkownika</string>
<string name="only_online_users">Tylko aktywni użytkownicy</string>
<string name="network_err">Błąd sieci!</string>
<string name="search_null">Brak wyników!</string>
<string name="modal_manual_hint">Nadaj nazwę tej lokalizacji.</string>
</resources>

View File

@ -298,6 +298,7 @@
<string name="info_icon_userlist_tab_level_status_offline">- user is currently offline</string>
<string name="info_icon_userlist_tab_level_status_inactive">- user is inactive </string>
<string name="info_icon_userlist_tab_level_status_inactive_tip">(didnt share any localization data since 7 days)</string>
<<<<<<< HEAD
<string name="title_activity_black_list">BlackList</string>
<string name="title_activity_white_list">Whitelist</string>
<string name="index_user">User index</string>
@ -393,11 +394,17 @@
"For example, position the FAB to one side of stream of a cards so the FAB wont interfere "
"when a user tries to pick up one of cards.\n\n"
</string>
=======
<string name="info_icon_userlist_summary">After clicking on a name, the tutor tab will pop up, containing details about selected tutor.\n\nYou can search for any tutor on the map by entering his name and surname in the search field.\n\nBy default, only active users are shown. You can change that in menu (three dots icon).\n\nYou can also search for a tutor directly, by entering name and surname of person that you look for.</string>
<!--(ENG) Blacklist -->
<string name="title_activity_black_list">Blacklist</string>
<string name="index_user">User index</string>
<string name="black_list_title">Add user to blacklist</string>
>>>>>>> develop
<string name="add">Add</string>
<string name="info_icon_userlist_summary">After clicking on a name, the tutor tab will pop up, containing details about selected tutor.</string>
<string name="possitive_dialog_button">Yes</string>
<string name="pref_title_acra" translatable="false">App issues reporting</string>
<!--(ENG) Profile Activity strings-->
@ -424,9 +431,15 @@
<string name="off">OFF</string>
<string name="scrap_tutor_tab">Scrap!</string>
<string name="scrap_tutor_msg">Data updated!</string>
<string name="no_online_users">Currently, there are no\nonline users.</string>
<!--(ENG) Checkbox online users list -->
<string name="no_online_users">Currently, there are no\nactive users.</string>
<string name="no_offline_users">Currently, there are no\noffline users.</string>
<string name="only_online_users">Only online users</string>
<string name="no_such_a_user">No such a user</string>
<string name="network_err">Network Error !</string>
<string name="search_null">Search response is empty!</string>
<string name="modal_manual_hint">Insert a name for this localization.</string>
</resources>