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

This commit is contained in:
Mieszko Wrzeszczyński 2018-12-07 18:01:01 +00:00 committed by Gogs
commit e5f7a81c9a
8 changed files with 39 additions and 41 deletions

View File

@ -29,7 +29,7 @@
</value> </value>
</option> </option>
</component> </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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -10,8 +10,8 @@ android {
applicationId "com.uam.wmi.findmytutor" applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 27 targetSdkVersion 27
versionCode 15 versionCode 1
versionName "0.9.1-alpha" versionName "0.9.2-alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }

View File

@ -16,8 +16,8 @@ import io.swagger.annotations.ApiModelProperty;
*/ */
public class Coordinate extends BaseResponse { public class Coordinate extends BaseResponse {
private Range<Double> latitudeRange = Const.latitudeRange; private Range<Double> latitudeRange = Const.buildingLatitudeRange;
private Range<Double> longtitudeRange = Const.longitudeRange; private Range<Double> longtitudeRange = Const.buildingLongitudeRange;
private List<String> allowedApproximatedLocations = Const.validApproximatedLocations; private List<String> allowedApproximatedLocations = Const.validApproximatedLocations;
@SerializedName("coordinateId") @SerializedName("coordinateId")

View File

@ -25,7 +25,6 @@ import android.util.Log;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationServices;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.geojson.Point; import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.model.Coordinate;
@ -33,23 +32,21 @@ import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization; import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
import com.uam.wmi.findmytutor.utils.MapUtils; import com.uam.wmi.findmytutor.utils.MapUtils;
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.SharingLevel; import com.uam.wmi.findmytutor.utils.SharingLevel;
import org.apache.commons.collections4.queue.CircularFifoQueue; import org.apache.commons.collections4.queue.CircularFifoQueue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import static com.uam.wmi.findmytutor.utils.Const.defaultBackgroundLocationInterval; import static com.uam.wmi.findmytutor.utils.Const.offlineBackgroundLocationInterval;
import static com.uam.wmi.findmytutor.utils.Const.onlineBackgroundLocationInterval;
import static com.uam.wmi.findmytutor.utils.Const.presenceApproximatedName; import static com.uam.wmi.findmytutor.utils.Const.presenceApproximatedName;
import static com.uam.wmi.findmytutor.utils.Const.presenceLatitude; import static com.uam.wmi.findmytutor.utils.Const.presenceLatitude;
import static com.uam.wmi.findmytutor.utils.Const.presenceLongitude; import static com.uam.wmi.findmytutor.utils.Const.presenceLongitude;
@ -58,12 +55,12 @@ import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationSta
public class BackgroundLocalizationService extends Service { 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 float LOCATION_DISTANCE = 1f;
private static final float LOCATION_DISTANCE = 5f; private static long notify_interval = onlineBackgroundLocationInterval;
private static long notify_interval = defaultBackgroundLocationInterval; private static long notify_interval_inside_building = onlineBackgroundLocationInterval;
private static long notify_interval_inside_building = defaultBackgroundLocationInterval; private static long notify_interval_outside_building = offlineBackgroundLocationInterval;
private static long notify_interval_outside_building = 360000; private static int coordinatesHistoryLength = 5;
private static int coordinatesHistoryLength = 10; private static final Long LOCATION_INTERVAL = notify_interval;
private Location mLastLocation; private Location mLastLocation;
private Boolean stopService = false; private Boolean stopService = false;
private ArrayList<String> providers = new ArrayList<String>(); private ArrayList<String> providers = new ArrayList<String>();
@ -149,7 +146,7 @@ public class BackgroundLocalizationService extends Service {
if (!stopService) { if (!stopService) {
mStatusChecker = () -> { mStatusChecker = () -> {
try { try {
fn_getlocation(); getLocalizationFromListeners();
changeBackgroundMode(); changeBackgroundMode();
} finally { } finally {
mHandler.postDelayed(mStatusChecker, notify_interval); mHandler.postDelayed(mStatusChecker, notify_interval);
@ -178,9 +175,8 @@ public class BackgroundLocalizationService extends Service {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
private void startMyOwnForeground() { private void startMyOwnForeground() {
String NOTIFICATION_CHANNEL_ID = "com.example.fmt"; String NOTIFICATION_CHANNEL_ID = "com.example.fmt";
String channelName = "My Background Service"; String channelName = "FMT Background location service";
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE); NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE); chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
@ -197,7 +193,7 @@ public class BackgroundLocalizationService extends Service {
startForeground(2, notification); startForeground(2, notification);
} }
private void fn_getlocation() { 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) { 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 // TODO: Consider calling
// ActivityCompat#requestPermissions // ActivityCompat#requestPermissions
@ -218,7 +214,7 @@ public class BackgroundLocalizationService extends Service {
if (location != null) { if (location != null) {
mLastLocation = location; mLastLocation = location;
coordinatesHistory.add(location); coordinatesHistory.add(location);
fn_update(location); sendCoordinateToBackend(location);
} }
triggerAnotherLocationListener.set(true); triggerAnotherLocationListener.set(true);
@ -237,12 +233,11 @@ public class BackgroundLocalizationService extends Service {
} }
coordinatesHistory.add(bestLocation); coordinatesHistory.add(bestLocation);
Log.e("Best localization:", String.valueOf(bestLocation));
} }
} }
private void fn_update(Location location) { private void sendCoordinateToBackend(Location location) {
new Task(location).execute(); new Task(location).execute();
} }
@ -278,7 +273,7 @@ public class BackgroundLocalizationService extends Service {
private class LocationListener implements android.location.LocationListener { private class LocationListener implements android.location.LocationListener {
public LocationListener(String provider) { LocationListener(String provider) {
Log.e(TAG, "LocationListener " + provider); Log.e(TAG, "LocationListener " + provider);
mLastLocation = new Location(provider); mLastLocation = new Location(provider);
} }
@ -328,6 +323,7 @@ public class BackgroundLocalizationService extends Service {
protected Object doInBackground(Object[] objects) { protected Object doInBackground(Object[] objects) {
String locationLevel = PrefUtils.getLocationLevel(getApplicationContext()); String locationLevel = PrefUtils.getLocationLevel(getApplicationContext());
String status = (PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "";
if (locationLevel.equals(SharingLevel.PRESENCE.toString())) { if (locationLevel.equals(SharingLevel.PRESENCE.toString())) {
latitude = presenceLatitude; latitude = presenceLatitude;
@ -350,7 +346,7 @@ public class BackgroundLocalizationService extends Service {
longitude, longitude,
altitude, altitude,
approximatedBuildingPart, approximatedBuildingPart,
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "", status,
PrefUtils.getUserId(getApplicationContext()), PrefUtils.getUserId(getApplicationContext()),
locationLevel locationLevel
); );
@ -361,16 +357,14 @@ public class BackgroundLocalizationService extends Service {
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<Coordinate>() { .subscribeWith(new DisposableSingleObserver<Coordinate>() {
@SuppressLint("LongLogTag")
@Override @Override
public void onSuccess(Coordinate coord) { public void onSuccess(Coordinate coordinate) {
Log.e("CoordinateService onSuccess", String.valueOf(coord)); Log.e(TAG, String.valueOf(coordinate));
} }
@SuppressLint("LongLogTag")
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.e("CoordinateService onError", e.getMessage()); Log.e(TAG, e.getMessage());
} }
})); }));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {

View File

@ -10,7 +10,7 @@ import retrofit2.http.POST;
public interface FeedbackService { public interface FeedbackService {
@POST("api/Feedback") @POST("api/Feedback")
Observable<Void> postFeedback(@Body Feedback feedback); Observable<Response<Void>> postFeedback(@Body Feedback feedback);
@GET("api/Feedback") @GET("api/Feedback")
Observable<Void> getFeedback(); Observable<Void> getFeedback();

View File

@ -6,13 +6,17 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class Const { public class Const {
public final static Integer defaultBackgroundLocationInterval = 15000; public final static Integer onlineBackgroundLocationInterval = 15000;
public final static Integer offlineBackgroundLocationInterval = 36000;
public final static Integer defaultMapZoom = 17; public final static Integer defaultMapZoom = 17;
public final static Integer searchMapZoom = 13; public final static Integer searchMapZoom = 13;
public final static Double presenceLatitude = 52.466365; public final static Double presenceLatitude = 52.466365;
public final static Double presenceLongitude = 16.926792; public final static Double presenceLongitude = 16.926792;
public final static String presenceApproximatedName = "Unknown"; public final static String presenceApproximatedName = "Unknown";
public final static Range<Double> latitudeRange = Range.create(52.466092, 52.467529); public final static Range<Double> buildingLatitudeRange = Range.create(52.466092, 52.467529);
public final static Range<Double> longitudeRange = Range.create(16.926159, 16.927759); public final static Range<Double> buildingLongitudeRange = Range.create(16.926159, 16.927759);
public final static Range<Double> outsideLatitudeRange = Range.create(52.463512, 52.468837);
public final static Range<Double> outsideLongitudeRange = Range.create(16.922372, 16.936004);
public final static List<String> validApproximatedLocations = Arrays.asList("Skrzydło B", "Skrzydło A", "Aule", "Łącznik", "Biblioteka", "Hol", "Unknown"); public final static List<String> validApproximatedLocations = Arrays.asList("Skrzydło B", "Skrzydło A", "Aule", "Łącznik", "Biblioteka", "Hol", "Unknown");
} }

View File

@ -82,10 +82,9 @@ public class FeedbackUtils {
try { try {
appVersion = activityContext.getPackageManager().getPackageInfo(activityContext.getPackageName(), 0).versionName; appVersion = activityContext.getPackageManager().getPackageInfo(activityContext.getPackageName(), 0).versionName;
if( !mode ){ if( !mode ){
body = PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext) + "\n" + body;
userFeedback = new Feedback(mode, userFeedback = new Feedback(mode,
header, header,
PrefUtils.getUserId(activityContext), PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext) + " | " + PrefUtils.getUserId(activityContext),
"Android "+ Build.VERSION.RELEASE, "Android "+ Build.VERSION.RELEASE,
appVersion, appVersion,
Build.MODEL, Build.MODEL,
@ -113,8 +112,10 @@ public class FeedbackUtils {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));
} }
private void handleResponse( Void resp) { private void handleResponse( Response<Void> resp) {
Toast.makeText(activityContext, activityContext.getString(R.string.modal_feedback_thankyou), Toast.LENGTH_SHORT).show(); Toast.makeText(activityContext, activityContext.getString(R.string.modal_feedback_thankyou), Toast.LENGTH_SHORT).show();
Log.d("FEEDBACK toast","gdzie jest mój tost");
} }
private void handleError(Throwable error) { private void handleError(Throwable error) {

View File

@ -14,8 +14,8 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import static com.uam.wmi.findmytutor.utils.Const.latitudeRange; import static com.uam.wmi.findmytutor.utils.Const.outsideLongitudeRange;
import static com.uam.wmi.findmytutor.utils.Const.longitudeRange; import static com.uam.wmi.findmytutor.utils.Const.outsideLatitudeRange;
public class MapUtils { public class MapUtils {
@ -59,7 +59,6 @@ public class MapUtils {
// 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.
try { try {
InputStream is = context.getAssets().open(filename); InputStream is = context.getAssets().open(filename);
int size = is.available(); int size = is.available();
@ -75,7 +74,7 @@ public class MapUtils {
} }
public static Boolean checkIfCoordinateIsValid(Location coordinate){ public static Boolean checkIfCoordinateIsValid(Location coordinate){
return latitudeRange.contains(coordinate.getLatitude()) && longitudeRange.contains(coordinate.getLongitude()); return outsideLatitudeRange.contains(coordinate.getLatitude()) && outsideLongitudeRange.contains(coordinate.getLongitude());
} }
// Function for marker animation // Function for marker animation