From 367bc7518ed9e37e52b17747289e7cd1049ed740 Mon Sep 17 00:00:00 2001 From: "marcin.jedynski" Date: Thu, 6 Dec 2018 22:31:02 +0100 Subject: [PATCH 1/4] fixed toast on send feedback, minor model adjustment of feedback --- .../com/uam/wmi/findmytutor/service/FeedbackService.java | 2 +- .../java/com/uam/wmi/findmytutor/utils/FeedbackUtils.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/FeedbackService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/FeedbackService.java index 6461a19..c5b318b 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/FeedbackService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/FeedbackService.java @@ -10,7 +10,7 @@ import retrofit2.http.POST; public interface FeedbackService { @POST("api/Feedback") - Observable postFeedback(@Body Feedback feedback); + Observable> postFeedback(@Body Feedback feedback); @GET("api/Feedback") Observable getFeedback(); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/FeedbackUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/FeedbackUtils.java index 17021d3..26f2031 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/FeedbackUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/FeedbackUtils.java @@ -82,10 +82,9 @@ public class FeedbackUtils { try { appVersion = activityContext.getPackageManager().getPackageInfo(activityContext.getPackageName(), 0).versionName; if( !mode ){ - body = PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext) + "\n" + body; userFeedback = new Feedback(mode, header, - PrefUtils.getUserId(activityContext), + PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext) + " | " + PrefUtils.getUserId(activityContext), "Android "+ Build.VERSION.RELEASE, appVersion, Build.MODEL, @@ -113,8 +112,10 @@ public class FeedbackUtils { .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::handleResponse, this::handleError)); } - private void handleResponse( Void resp) { + private void handleResponse( Response resp) { 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) { From a9469cce76ebf9fe6c56ad951fec20f6bd36ec43 Mon Sep 17 00:00:00 2001 From: "marcin.jedynski" Date: Thu, 6 Dec 2018 23:58:47 +0100 Subject: [PATCH 2/4] reverted api url back to master --- .../main/java/com/uam/wmi/findmytutor/network/ApiClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java index 1835496..ad2003d 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java @@ -26,7 +26,7 @@ public class ApiClient { private static Retrofit retrofit = null; private static int REQUEST_TIMEOUT = 60; private static OkHttpClient okHttpClient; - private static final String BASE_URL = "https://s416084.projektstudencki.pl/master/"; + private static final String BASE_URL = "https://s416084.projektstudencki.pl/develop/"; public static Retrofit getClient(Context context) { From 527701420bfb82d664597b681012414094ec5c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 7 Dec 2018 18:57:26 +0100 Subject: [PATCH 3/4] Add onfline and offline zones --- .idea/misc.xml | 2 +- app/build.gradle | 4 +- .../uam/wmi/findmytutor/model/Coordinate.java | 4 +- .../BackgroundLocalizationService.java | 44 ++++++++----------- .../com/uam/wmi/findmytutor/utils/Const.java | 10 +++-- .../uam/wmi/findmytutor/utils/MapUtils.java | 7 ++- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index dc44dda..b0c7b20 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index f053e5e..3c500f0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.uam.wmi.findmytutor" minSdkVersion 22 targetSdkVersion 27 - versionCode 15 - versionName "0.9.1-alpha" + versionCode 1 + versionName "0.9.2-alpha" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/Coordinate.java b/app/src/main/java/com/uam/wmi/findmytutor/model/Coordinate.java index 4d598ff..0323cfd 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/model/Coordinate.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/Coordinate.java @@ -16,8 +16,8 @@ import io.swagger.annotations.ApiModelProperty; */ public class Coordinate extends BaseResponse { - private Range latitudeRange = Const.latitudeRange; - private Range longtitudeRange = Const.longitudeRange; + private Range latitudeRange = Const.buildingLatitudeRange; + private Range longtitudeRange = Const.buildingLongitudeRange; private List allowedApproximatedLocations = Const.validApproximatedLocations; @SerializedName("coordinateId") diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java index 715473e..3377a35 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java @@ -25,7 +25,6 @@ import android.util.Log; import com.annimon.stream.Stream; import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationServices; -import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.geometry.LatLng; 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.MapUtils; import com.uam.wmi.findmytutor.utils.PrefUtils; -import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.SharingLevel; import org.apache.commons.collections4.queue.CircularFifoQueue; import java.util.ArrayList; import java.util.List; -import java.util.TimerTask; import java.util.concurrent.atomic.AtomicReference; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.observers.DisposableSingleObserver; 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.presenceLatitude; 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 { private static final String TAG = "MyLocationService"; - private static final int LOCATION_INTERVAL = 1000; - private static final float LOCATION_DISTANCE = 5f; - private static long notify_interval = defaultBackgroundLocationInterval; - private static long notify_interval_inside_building = defaultBackgroundLocationInterval; - private static long notify_interval_outside_building = 360000; - private static int coordinatesHistoryLength = 10; + private static final float LOCATION_DISTANCE = 1f; + private static long notify_interval = onlineBackgroundLocationInterval; + private static long notify_interval_inside_building = onlineBackgroundLocationInterval; + private static long notify_interval_outside_building = offlineBackgroundLocationInterval; + private static int coordinatesHistoryLength = 5; + private static final Long LOCATION_INTERVAL = notify_interval; private Location mLastLocation; private Boolean stopService = false; private ArrayList providers = new ArrayList(); @@ -149,7 +146,7 @@ public class BackgroundLocalizationService extends Service { if (!stopService) { mStatusChecker = () -> { try { - fn_getlocation(); + getLocalizationFromListeners(); changeBackgroundMode(); } finally { mHandler.postDelayed(mStatusChecker, notify_interval); @@ -178,9 +175,8 @@ public class BackgroundLocalizationService extends Service { @RequiresApi(api = Build.VERSION_CODES.O) private void startMyOwnForeground() { - 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); chan.setLightColor(Color.BLUE); chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); @@ -197,7 +193,7 @@ public class BackgroundLocalizationService extends Service { 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) { // TODO: Consider calling // ActivityCompat#requestPermissions @@ -218,7 +214,7 @@ public class BackgroundLocalizationService extends Service { if (location != null) { mLastLocation = location; coordinatesHistory.add(location); - fn_update(location); + sendCoordinateToBackend(location); } triggerAnotherLocationListener.set(true); @@ -237,12 +233,11 @@ public class BackgroundLocalizationService extends Service { } 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(); } @@ -278,7 +273,7 @@ public class BackgroundLocalizationService extends Service { private class LocationListener implements android.location.LocationListener { - public LocationListener(String provider) { + LocationListener(String provider) { Log.e(TAG, "LocationListener " + provider); mLastLocation = new Location(provider); } @@ -328,6 +323,7 @@ public class BackgroundLocalizationService extends Service { protected Object doInBackground(Object[] objects) { String locationLevel = PrefUtils.getLocationLevel(getApplicationContext()); + String status = (PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : ""; if (locationLevel.equals(SharingLevel.PRESENCE.toString())) { latitude = presenceLatitude; @@ -350,7 +346,7 @@ public class BackgroundLocalizationService extends Service { longitude, altitude, approximatedBuildingPart, - (PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "", + status, PrefUtils.getUserId(getApplicationContext()), locationLevel ); @@ -361,16 +357,14 @@ public class BackgroundLocalizationService extends Service { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableSingleObserver() { - @SuppressLint("LongLogTag") @Override - public void onSuccess(Coordinate coord) { - Log.e("CoordinateService onSuccess", String.valueOf(coord)); + public void onSuccess(Coordinate coordinate) { + Log.e(TAG, String.valueOf(coordinate)); } - @SuppressLint("LongLogTag") @Override public void onError(Throwable e) { - Log.e("CoordinateService onError", e.getMessage()); + Log.e(TAG, e.getMessage()); } })); } catch (IllegalArgumentException e) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java index fa92616..6a4282a 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java @@ -6,13 +6,17 @@ import java.util.Arrays; import java.util.List; 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 searchMapZoom = 13; public final static Double presenceLatitude = 52.466365; public final static Double presenceLongitude = 16.926792; public final static String presenceApproximatedName = "Unknown"; - public final static Range latitudeRange = Range.create(52.466092, 52.467529); - public final static Range longitudeRange = Range.create(16.926159, 16.927759); + public final static Range buildingLatitudeRange = Range.create(52.466092, 52.467529); + public final static Range buildingLongitudeRange = Range.create(16.926159, 16.927759); + public final static Range outsideLatitudeRange = Range.create(52.463512, 52.468837); + public final static Range outsideLongitudeRange = Range.create(16.922372, 16.936004); public final static List validApproximatedLocations = Arrays.asList("Skrzydło B", "Skrzydło A", "Aule", "Łącznik", "Biblioteka", "Hol", "Unknown"); } + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java index b63cf5f..3164e2b 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java @@ -14,8 +14,8 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; import java.io.IOException; import java.io.InputStream; -import static com.uam.wmi.findmytutor.utils.Const.latitudeRange; -import static com.uam.wmi.findmytutor.utils.Const.longitudeRange; +import static com.uam.wmi.findmytutor.utils.Const.outsideLongitudeRange; +import static com.uam.wmi.findmytutor.utils.Const.outsideLatitudeRange; public class MapUtils { @@ -59,7 +59,6 @@ public class MapUtils { // read file to JSON public static String loadJsonFromAsset(Context context, String filename) { - // Using this method to load in GeoJSON files from the assets folder. try { InputStream is = context.getAssets().open(filename); int size = is.available(); @@ -75,7 +74,7 @@ public class MapUtils { } 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 From fd49c66ee1c8288989470571c68bda7c4890afa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Fri, 7 Dec 2018 18:59:30 +0100 Subject: [PATCH 4/4] Adjust to master --- .../main/java/com/uam/wmi/findmytutor/network/ApiClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java index ad2003d..1835496 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/network/ApiClient.java @@ -26,7 +26,7 @@ public class ApiClient { private static Retrofit retrofit = null; private static int REQUEST_TIMEOUT = 60; private static OkHttpClient okHttpClient; - private static final String BASE_URL = "https://s416084.projektstudencki.pl/develop/"; + private static final String BASE_URL = "https://s416084.projektstudencki.pl/master/"; public static Retrofit getClient(Context context) {