Fix partially manual predefined locations
This commit is contained in:
parent
a52e5dd89b
commit
c05d03a4d0
@ -26,10 +26,13 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.ActiveFragment;
|
||||
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RxSearchObservable;
|
||||
|
||||
@ -46,6 +49,8 @@ import io.reactivex.functions.Function;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.deafultMapZoom;
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.searchMapZoom;
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||
|
||||
|
||||
@ -53,7 +58,6 @@ public abstract class BaseActivity
|
||||
extends AppCompatActivity
|
||||
implements BottomNavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
protected static final int REQUEST_PERMISSIONS = 100;
|
||||
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
|
||||
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{
|
||||
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS};
|
||||
@ -271,6 +275,11 @@ public abstract class BaseActivity
|
||||
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus && activeFragment.equals(ActiveFragment.NONE)) {
|
||||
restoreMapMarkers();
|
||||
adjustMapToSearch(deafultMapZoom);
|
||||
}
|
||||
|
||||
if(hasFocus && activeFragment.equals(ActiveFragment.NONE)){
|
||||
adjustMapToSearch(searchMapZoom);
|
||||
}
|
||||
});
|
||||
|
||||
@ -299,6 +308,8 @@ public abstract class BaseActivity
|
||||
|
||||
abstract void restoreMapMarkers();
|
||||
|
||||
abstract void adjustMapToSearch(Integer zoom);
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||
|
@ -4,7 +4,6 @@ import android.Manifest;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -25,6 +24,7 @@ import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
@ -46,13 +46,13 @@ import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
|
||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
import com.uam.wmi.findmytutor.utils.ManualLocationUtils;
|
||||
import com.uam.wmi.findmytutor.utils.MapMarker;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -99,6 +99,7 @@ public class MapActivity extends BaseActivity
|
||||
private int tiltParam = 30;
|
||||
private String myId;
|
||||
private boolean isTutor;
|
||||
private ApproximatedLocalization approximatedLocalization;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -132,7 +133,7 @@ public class MapActivity extends BaseActivity
|
||||
//start background task
|
||||
handleBackgroundTaskLifeCycle();
|
||||
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
|
||||
|
||||
approximatedLocalization = new ApproximatedLocalization(MapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -153,7 +154,7 @@ public class MapActivity extends BaseActivity
|
||||
stopBackgroundLocalizationTask();
|
||||
|
||||
removeLocationButton.setVisibility(View.GONE);
|
||||
Toast.makeText(MapActivity.this, "Your marker will disappear in next couple minutes", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(MapActivity.this, R.string.manual_marker_info, Toast.LENGTH_SHORT).show();
|
||||
|
||||
});
|
||||
} else {
|
||||
@ -163,8 +164,13 @@ public class MapActivity extends BaseActivity
|
||||
return true;
|
||||
});
|
||||
|
||||
setOnMapLongClickListener();
|
||||
mapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true);
|
||||
if (isTutor) {
|
||||
setOnMapLongClickListener();
|
||||
}
|
||||
|
||||
|
||||
setOnMapClickListener();
|
||||
MapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true);
|
||||
}
|
||||
|
||||
private void updateUserHashMap(String userId, Long markerId) {
|
||||
@ -220,16 +226,21 @@ public class MapActivity extends BaseActivity
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
Log.e("ERR",e.toString());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message = "Network Error!";
|
||||
message = getString(R.string.network_error);
|
||||
}
|
||||
|
||||
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void setOnMapClickListener() {
|
||||
mapboxMap.addOnMapClickListener(e -> removeLocationButton.setVisibility(View.GONE));
|
||||
}
|
||||
|
||||
private void setOnMapLongClickListener() {
|
||||
|
||||
@ -246,14 +257,11 @@ public class MapActivity extends BaseActivity
|
||||
.position(latLng);
|
||||
|
||||
tmpLocalMarker = mapboxMap.addMarker(markerOptions);
|
||||
MapMarker marker = new MapMarker(tmpLocalMarker, markerOptions, defaultIcon, sharingLevel);
|
||||
|
||||
updateUserHashMap(myId, marker.getMarker().getId());
|
||||
|
||||
new MapMarker(tmpLocalMarker, markerOptions, defaultIcon, sharingLevel);
|
||||
|
||||
} else {
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position",
|
||||
new mapUtils.LatLngEvaluator(), tmpLocalMarker.getPosition(), latLng);
|
||||
new MapUtils.LatLngEvaluator(), tmpLocalMarker.getPosition(), latLng);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
@ -261,21 +269,22 @@ public class MapActivity extends BaseActivity
|
||||
selectLocationButton.setOnClickListener((View view) -> {
|
||||
if (tmpLocalMarker != null) {
|
||||
|
||||
String approximatedLocation = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
|
||||
try {
|
||||
droppedMarkercoordinate = new Coordinate(
|
||||
latLng.getLatitude(),
|
||||
latLng.getLongitude(),
|
||||
latLng.getAltitude(),
|
||||
"approx",
|
||||
approximatedLocation,
|
||||
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
);
|
||||
|
||||
PrefUtils.putManualLocation(this, latLng);
|
||||
handleBackgroundTaskLifeCycle();
|
||||
PrefUtils.putManualLocation(this, latLng, approximatedLocation);
|
||||
|
||||
handleBackgroundTaskLifeCycle();
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
@ -283,7 +292,7 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
Toast.makeText(
|
||||
MapActivity.this,
|
||||
"Manual Locations selected!" + latLng,
|
||||
getString(R.string.manual_location_selected),
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
|
||||
@ -301,7 +310,7 @@ public class MapActivity extends BaseActivity
|
||||
public void showLocationDialog(LatLng latLng) {
|
||||
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.location_modal, null);
|
||||
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.location_modal, null);
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this);
|
||||
|
||||
alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null);
|
||||
@ -328,42 +337,42 @@ public class MapActivity extends BaseActivity
|
||||
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.modal_location_hint), Toast.LENGTH_SHORT).show();
|
||||
modalUserInput.requestFocus();
|
||||
} else {
|
||||
PrefUtils.putManualLocation(getApplicationContext(), latLng);
|
||||
sendLocation(body,latLng);
|
||||
sendLocation(body, latLng);
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
|
||||
private void sendLocation(String body, LatLng latLng) {
|
||||
PredefinedStatusesService predefinedStatusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
|
||||
|
||||
PredefinedCoordViewModel droppedMarkercoordinate = new PredefinedCoordViewModel(
|
||||
latLng.getLatitude(),
|
||||
latLng.getLongitude(),
|
||||
latLng.getAltitude(),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
"string",
|
||||
"predefined",
|
||||
approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())),
|
||||
SharingLevel.PREDEFINED.toString(),
|
||||
body
|
||||
);
|
||||
|
||||
PredefinedStatusesService predefinedStatusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
|
||||
CompositeDisposable disposable = new CompositeDisposable();
|
||||
disposable.add(predefinedStatusesService.postUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), droppedMarkercoordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
disposable.add(
|
||||
predefinedStatusesService.postUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), droppedMarkercoordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::SaveCurrentManualLocation, this::handleError)
|
||||
);
|
||||
}
|
||||
|
||||
private void handleResponse(List<PredefinedCoordViewModel> resp) {
|
||||
Toast.makeText(getApplicationContext(), "Location saved!", Toast.LENGTH_SHORT).show();
|
||||
private void SaveCurrentManualLocation(PredefinedCoordViewModel resp) {
|
||||
Toast.makeText(getApplicationContext(), R.string.location_saved, Toast.LENGTH_SHORT).show();
|
||||
PrefUtils.putCurrentManualLocation(getApplicationContext(),resp.getPredefinedCoordinateId());
|
||||
}
|
||||
|
||||
private void fetchTopCoords() {
|
||||
@ -379,7 +388,6 @@ public class MapActivity extends BaseActivity
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
|
||||
if (tmpLocalMarker != null && coordsList.isEmpty()) {
|
||||
Timber.e("200 empty []");
|
||||
mapboxMap.clear();
|
||||
@ -433,7 +441,7 @@ public class MapActivity extends BaseActivity
|
||||
LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude());
|
||||
// TODO fix flickiering markers
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new mapUtils.LatLngEvaluator(),
|
||||
new MapUtils.LatLngEvaluator(),
|
||||
marker.getPosition(),
|
||||
toDestination);
|
||||
markerAnimator.setDuration(2000);
|
||||
@ -555,7 +563,7 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
Location lastKnownLocation = locationComponent.getLastKnownLocation();
|
||||
if (lastKnownLocation != null) {
|
||||
mapUtils.makeNewCamera(mapboxMap,
|
||||
MapUtils.makeNewCamera(mapboxMap,
|
||||
lastKnownLocation.getLatitude(),
|
||||
lastKnownLocation.getLongitude(),
|
||||
zoomParam,
|
||||
@ -713,4 +721,8 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
public void adjustMapToSearch(Integer zoom) {
|
||||
MapUtils.setZoom(mapboxMap,zoom);
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
languagesList.setDefaultValue(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
languagesList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
||||
if (!newValue.toString().equals("0")){
|
||||
|
@ -13,6 +13,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.annimon.stream.IntPair;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
@ -65,12 +66,12 @@ public class SharingFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onSuccess(List<String> strings) {
|
||||
String[] statusesArray = strings.toArray(new String[strings.size()]);
|
||||
setListPreferenceData(statusList.getKey(), statusesArray);
|
||||
setListPreferenceData(statusList.getKey(), statusesArray,strings.size() -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(), R.string.error_status_fetch, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}));
|
||||
@ -87,14 +88,21 @@ public class SharingFragment extends PreferenceFragment {
|
||||
List<String> names = Stream.of(coords).map(PredefinedCoordViewModel::getName).collect(com.annimon.stream.Collectors.toList());
|
||||
predefinedCoordsList.addAll(coords);
|
||||
String[] stringnames = names.toArray(new String[0]);
|
||||
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||
|
||||
setListPreferenceData(manualLocationList.getKey(), stringnames);
|
||||
List<Integer> activeId = Stream.of(coords).indexed()
|
||||
.filter(v -> v.getSecond().getPredefinedCoordinateId().equals(currentCoordId)).map(IntPair::getFirst).toList();
|
||||
|
||||
if(activeId.size() > 0)
|
||||
setListPreferenceData(manualLocationList.getKey(), stringnames, activeId.get(0));
|
||||
else{
|
||||
setListPreferenceData(manualLocationList.getKey(), stringnames,null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(), R.string.manual_status_error, Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
}));
|
||||
@ -161,13 +169,15 @@ public class SharingFragment extends PreferenceFragment {
|
||||
preferenceCategory.removePreference(manualLocationList);
|
||||
preferenceCategory.removePreference(manualLocationButton);
|
||||
}
|
||||
|
||||
/** Custom manual location list change listener **/
|
||||
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
|
||||
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).single();
|
||||
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
|
||||
|
||||
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData());
|
||||
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation() );
|
||||
PrefUtils.putCurrentManualLocation(getApplicationContext(),temp.getPredefinedCoordinateId());
|
||||
|
||||
return true;
|
||||
});
|
||||
@ -210,8 +220,7 @@ public class SharingFragment extends PreferenceFragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
protected void setListPreferenceData(String lp_name, String[] entries) {
|
||||
//todo bug z pustym statusem
|
||||
protected void setListPreferenceData(String lp_name, String[] entries, Integer activeId) {
|
||||
ListPreference lp = (ListPreference) findPreference(lp_name);
|
||||
lp.setEntries(entries);
|
||||
CharSequence[] entryValues = new CharSequence[entries.length];
|
||||
@ -220,13 +229,17 @@ public class SharingFragment extends PreferenceFragment {
|
||||
entryValues[i] = Integer.toString(i);
|
||||
}
|
||||
|
||||
lp.setDefaultValue("0");
|
||||
lp.setDefaultValue(0);
|
||||
lp.setEntryValues(entryValues);
|
||||
}
|
||||
|
||||
if(entries.length > 0)
|
||||
lp.setValueIndex(activeId);
|
||||
};
|
||||
|
||||
private void handleResponse(List<String> resp) {
|
||||
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||
setListPreferenceData(statusList.getKey(), statusesArray);
|
||||
|
||||
setListPreferenceData(statusList.getKey(), statusesArray,resp.size() - 1);
|
||||
|
||||
statusList.setValueIndex(resp.size() - 1);
|
||||
PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() - 1));
|
||||
|
@ -8,7 +8,7 @@ public class PredefinedCoordViewModel {
|
||||
|
||||
@SerializedName("predefinedCoordinateId")
|
||||
@Expose
|
||||
private UUID predefinedCoordinateId;
|
||||
private String predefinedCoordinateId;
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
@ -67,7 +67,6 @@ public class PredefinedCoordViewModel {
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param approximatedLocation
|
||||
* @param predefinedCoordinateId
|
||||
*/
|
||||
public PredefinedCoordViewModel(Double latitude, Double longitude, Double altitude, String userId, String approximatedLocation, String displayMode, String name) {
|
||||
super();
|
||||
@ -80,11 +79,11 @@ public class PredefinedCoordViewModel {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public UUID getPredefinedCoordinateId() {
|
||||
public String getPredefinedCoordinateId() {
|
||||
return predefinedCoordinateId;
|
||||
}
|
||||
|
||||
public void setPredefinedCoordinateId(UUID predefinedCoordinateId) {
|
||||
public void setPredefinedCoordinateId(String predefinedCoordinateId) {
|
||||
this.predefinedCoordinateId = predefinedCoordinateId;
|
||||
}
|
||||
|
||||
|
@ -51,24 +51,21 @@ public class ApiClient {
|
||||
|
||||
httpClient.addInterceptor(interceptor);
|
||||
|
||||
httpClient.addInterceptor(new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request original = chain.request();
|
||||
Request.Builder requestBuilder = original.newBuilder()
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Content-Type", "application/json");
|
||||
httpClient.addInterceptor(chain -> {
|
||||
Request original = chain.request();
|
||||
Request.Builder requestBuilder = original.newBuilder()
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Content-Type", "application/json");
|
||||
|
||||
|
||||
// Adding Authorization token (API Key)
|
||||
// Requests will be denied without API key
|
||||
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {
|
||||
requestBuilder.addHeader("Authorization", "Bearer " + PrefUtils.getApiKey(context));
|
||||
}
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
return chain.proceed(request);
|
||||
// Adding Authorization token (API Key)
|
||||
// Requests will be denied without API key
|
||||
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {
|
||||
requestBuilder.addHeader("Authorization", "Bearer " + PrefUtils.getApiKey(context));
|
||||
}
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
return chain.proceed(request);
|
||||
});
|
||||
|
||||
okHttpClient = httpClient.build();
|
||||
|
@ -34,10 +34,11 @@ import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
@ -57,26 +58,19 @@ public class BackgroundLocalizationService extends Service {
|
||||
private static final int LOCATION_INTERVAL = 1000;
|
||||
private static final float LOCATION_DISTANCE = 5f;
|
||||
public static String str_receiver = "background.location.broadcast";
|
||||
private static long notify_interval = 20000;
|
||||
private static long notify_interval = 10000;
|
||||
Location mLastLocation;
|
||||
Boolean stopService = false;
|
||||
Intent intent;
|
||||
ArrayList<String> providers = new ArrayList<String>();
|
||||
LocationListener[] mLocationListeners;
|
||||
|
||||
private LocationManager mLocationManager = null;
|
||||
private Handler mHandler = new Handler();
|
||||
private HandlerThread mHandlerThread = null;
|
||||
private Runnable mStatusChecker;
|
||||
private FusedLocationProviderClient mFusedLocationClient;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Double altitude;
|
||||
private String approximatedBuildingPart = null;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private CoordinateService coordinateService = null;
|
||||
|
||||
private Location mLastLocation;
|
||||
private Boolean stopService = false;
|
||||
private Intent intent;
|
||||
private ArrayList<String> providers = new ArrayList<String>();
|
||||
private LocationListener[] mLocationListeners;
|
||||
private ApproximatedLocalization approximatedLocalization;
|
||||
|
||||
public BackgroundLocalizationService() {
|
||||
providers.add(LocationManager.GPS_PROVIDER);
|
||||
@ -117,11 +111,6 @@ public class BackgroundLocalizationService extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.e(TAG, "onCreate");
|
||||
approximatedLocalization = new ApproximatedLocalization(mapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
|
||||
|
||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
storeBackgroundLocationStatus(getApplication(), true);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
@ -158,6 +147,7 @@ public class BackgroundLocalizationService extends Service {
|
||||
|
||||
if (!stopService) {
|
||||
|
||||
|
||||
mStatusChecker = () -> {
|
||||
try {
|
||||
fn_getlocation();
|
||||
@ -167,9 +157,11 @@ public class BackgroundLocalizationService extends Service {
|
||||
};
|
||||
|
||||
AsyncTask.execute(mStatusChecker);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startMyOwnForeground() {
|
||||
@ -231,68 +223,8 @@ public class BackgroundLocalizationService extends Service {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
private void fn_update(Location location) {
|
||||
Double latitude = location.getLatitude();
|
||||
Double longitude = location.getLongitude();
|
||||
Double altitude = location.getAltitude();
|
||||
|
||||
String locationLevel = PrefUtils.getLocationLevel(getApplicationContext());
|
||||
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
|
||||
|
||||
if (locationLevel.equals(SharingLevel.PRESENCE.toString())) {
|
||||
latitude = presenceLatitude;
|
||||
longitude = presenceLongitude;
|
||||
approximatedBuildingPart = presenceApproximatedName;
|
||||
} else if (locationLevel.equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
List<Double> points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart);
|
||||
latitude = points.get(0);
|
||||
longitude = points.get(1);
|
||||
} else if (locationLevel.equals(SharingLevel.MANUAL.toString())) {
|
||||
LatLng latLng = PrefUtils.getManualLocation(getApplicationContext());
|
||||
latitude = latLng.getLatitude();
|
||||
longitude = latLng.getLongitude();
|
||||
}
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latitude,
|
||||
longitude,
|
||||
altitude,
|
||||
approximatedBuildingPart,
|
||||
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "",
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
locationLevel
|
||||
);
|
||||
|
||||
disposable.add(
|
||||
coordinateService
|
||||
.postCoordinate(coordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onSuccess(Coordinate coord) {
|
||||
Log.e("CoordinateService onSuccess", String.valueOf(coord));
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
Log.e("CoordinateService onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
Log.e("CoordinateService onError", RestApiHelper.getErrorMessage(responseBody));
|
||||
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e("CoordinateService onError",e.toString());
|
||||
}
|
||||
new Task(location).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -326,6 +258,13 @@ public class BackgroundLocalizationService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private class TimerTaskToGetLocation extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
mHandler.post(BackgroundLocalizationService.this::fn_getlocation);
|
||||
}
|
||||
}
|
||||
|
||||
private class LocationListener implements android.location.LocationListener {
|
||||
|
||||
public LocationListener(String provider) {
|
||||
@ -354,4 +293,87 @@ public class BackgroundLocalizationService extends Service {
|
||||
Log.e(TAG, "onStatusChanged: " + provider);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class Task extends AsyncTask {
|
||||
private ApproximatedLocalization approximatedLocalization;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Double altitude;
|
||||
private String approximatedBuildingPart = null;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
private Task(Location location) {
|
||||
latitude = location.getLatitude();
|
||||
longitude = location.getLongitude();
|
||||
altitude = location.getAltitude();
|
||||
approximatedLocalization = new ApproximatedLocalization(MapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
|
||||
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object[] objects) {
|
||||
|
||||
String locationLevel = PrefUtils.getLocationLevel(getApplicationContext());
|
||||
|
||||
if (locationLevel.equals(SharingLevel.PRESENCE.toString())) {
|
||||
latitude = presenceLatitude;
|
||||
longitude = presenceLongitude;
|
||||
approximatedBuildingPart = presenceApproximatedName;
|
||||
} else if (locationLevel.equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
List<Double> points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart);
|
||||
latitude = points.get(0);
|
||||
longitude = points.get(1);
|
||||
} else if (locationLevel.equals(SharingLevel.MANUAL.toString())) {
|
||||
LatLng latLng = PrefUtils.getManualLocation(getApplicationContext());
|
||||
latitude = latLng.getLatitude();
|
||||
longitude = latLng.getLongitude();
|
||||
approximatedBuildingPart = PrefUtils.getManualLocationApproximation(getApplicationContext());
|
||||
}
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latitude,
|
||||
longitude,
|
||||
altitude,
|
||||
approximatedBuildingPart,
|
||||
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "",
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
locationLevel
|
||||
);
|
||||
|
||||
disposable.add(
|
||||
coordinateService
|
||||
.postCoordinate(coordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onSuccess(Coordinate coord) {
|
||||
Log.e("CoordinateService onSuccess", String.valueOf(coord));
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
Log.e("CoordinateService onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
Log.e("CoordinateService onError", RestApiHelper.getErrorMessage(responseBody));
|
||||
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ public interface PredefinedStatusesService {
|
||||
Single<List<PredefinedCoordViewModel>> getUserPredefinedCoords(@Path("tutorId") String tutorId);
|
||||
|
||||
@POST("api/users/predefined/coordinate/{tutorId}")
|
||||
Single<List<PredefinedCoordViewModel>> postUserPredefinedCoord(@Path("tutorId") String tutorId, @Body PredefinedCoordViewModel coord);
|
||||
Single <PredefinedCoordViewModel> postUserPredefinedCoord(@Path("tutorId") String tutorId, @Body PredefinedCoordViewModel coord);
|
||||
|
||||
@DELETE("api/users/predefined/coordinate/{tutorId}")
|
||||
Single<List<PredefinedCoordViewModel>> deleteUserPredefinedCoord(@Path("tutorId") String tutorId, @Body PredefinedCoordViewModel coord);
|
||||
|
@ -3,6 +3,8 @@ package com.uam.wmi.findmytutor.utils;
|
||||
import android.util.Range;
|
||||
|
||||
public class Consts {
|
||||
public final static Integer deafultMapZoom = 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";
|
||||
|
@ -30,6 +30,7 @@ import retrofit2.Response;
|
||||
|
||||
public class FeedbackUtils {
|
||||
private Context activityContext;
|
||||
AlertDialog.Builder alertDialogBuilderUserInput;
|
||||
public FeedbackUtils(Context context){
|
||||
activityContext = context;
|
||||
}
|
||||
@ -37,7 +38,7 @@ public class FeedbackUtils {
|
||||
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(activityContext);
|
||||
View view = layoutInflaterAndroid.inflate(R.layout.feedback_modal, null);
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(activityContext);
|
||||
alertDialogBuilderUserInput = new AlertDialog.Builder(activityContext);
|
||||
alertDialogBuilderUserInput.setView(view).setPositiveButton(activityContext.getString(R.string.modal_feedback_send),null);
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
public class LocaleUtils {
|
||||
public static String getCurrentLocale(Context context){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
|
||||
return String.valueOf(context.getResources().getConfiguration().getLocales().get(0));
|
||||
} else{
|
||||
//noinspection deprecation
|
||||
return String.valueOf(context.getResources().getConfiguration().locale);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ import java.io.InputStream;
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.latitudeRange;
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.longtitudeRange;
|
||||
|
||||
public class mapUtils {
|
||||
public class MapUtils {
|
||||
|
||||
// Boundires
|
||||
private static final LatLngBounds WMI_BOUNDS = new LatLngBounds.Builder()
|
||||
@ -41,7 +41,7 @@ public class mapUtils {
|
||||
if (check) {
|
||||
// Set bounds to WMI
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
|
||||
makeNewCamera(mapboxMap, 52.466799, 16.927002, 16, 0, 0, 4000);
|
||||
makeNewCamera(mapboxMap, 52.466799, 16.927002, 17, 0, 0, 4000);
|
||||
mapboxMap.setMinZoomPreference(16); // TODO export to map config
|
||||
} else {
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(null);
|
||||
@ -49,6 +49,12 @@ public class mapUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// Map Bounds Area
|
||||
public static void setZoom(MapboxMap mapboxMap, Integer zoom) {
|
||||
makeNewCamera(mapboxMap, 52.466799, 16.927002, zoom, 0, 0, 1000);
|
||||
mapboxMap.setMinZoomPreference(16); // TODO export to map config
|
||||
}
|
||||
|
||||
public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration) {
|
||||
CameraPosition position = new CameraPosition.Builder()
|
||||
.target(new LatLng(lat, lon)) // Sets the new camera position
|
@ -144,7 +144,7 @@ public class PrefUtils {
|
||||
}
|
||||
|
||||
public static String getLocale(Context context) {
|
||||
return getSharedPreferences(context).getString("LOCALE", "en");
|
||||
return getSharedPreferences(context).getString("LOCALE", LocaleUtils.getCurrentLocale(context));
|
||||
}
|
||||
|
||||
public static Boolean isBackgroundLocationServiceRunning(Context context) {
|
||||
@ -157,14 +157,14 @@ public class PrefUtils {
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void putManualLocation(Context context, LatLng latLng) {
|
||||
public static void putManualLocation(Context context, LatLng latLng, String approximatedLocation) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("key_location_level","3");
|
||||
editor.putString("location_mode", "manual");
|
||||
editor.putString("approx_manual_loc", approximatedLocation);
|
||||
editor.putBoolean("key_sharing_enabled", true);
|
||||
editor.putLong("longitude_manual_location", Double.doubleToRawLongBits(latLng.getLongitude()));
|
||||
editor.putLong("latitude_manual_location", Double.doubleToRawLongBits(latLng.getLatitude()));
|
||||
Log.d("SAVE_COORD","zapisane");
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@ -175,4 +175,18 @@ public class PrefUtils {
|
||||
);
|
||||
}
|
||||
|
||||
public static String getManualLocationApproximation(Context context) {
|
||||
return getSharedPreferences(context).getString("approx_manual_loc", "unknown");
|
||||
}
|
||||
|
||||
public static void putCurrentManualLocation(Context context,String manualId) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("current_manual_location", manualId);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getCurrentManualLocation(Context context) {
|
||||
return getSharedPreferences(context).getString("current_manual_location", null);
|
||||
}
|
||||
|
||||
}
|
@ -23,7 +23,7 @@ public class RestApiHelper extends Activity {
|
||||
JSONObject jsonObject = new JSONObject(responseBody.string());
|
||||
return jsonObject.getString("message");
|
||||
} catch (Exception e) {
|
||||
return e.getMessage();
|
||||
return "Something went wrong!";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp"
|
||||
android:layout_height="120dp"
|
||||
android:contentDescription="@string/logo_find_my_tutor"
|
||||
app:srcCompat="@drawable/logo_design_black2" />
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/login_form"
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
@ -146,10 +146,19 @@
|
||||
<string name="modal_feedback_thankyou">Dziękujemy za przesłanie feedbacku.</string>
|
||||
<string name="remove_manual_location">Usuń manualną lokację</string>
|
||||
<string name="title_activity_tutor_tab">Profil</string>
|
||||
<string name="saveButton">Zapisz</string>
|
||||
<string name="saveButton">Zapisz!</string>
|
||||
<string name="tutorTabHint">Tutaj możesz dodać swoją notatkę. Będzie widoczna dla innych użytkowników.</string>
|
||||
<string name="modal_location_send">WYŚLIJ</string>
|
||||
<string name="modal_location_hint">Proszę nazwać wybraną lokację.</string>
|
||||
<string name="manual_modal_title">Czy chcesz zapisać tę lokalizację?</string>
|
||||
<string name="lbl_ok">Zapisz!</string>
|
||||
<string name="lbl_cancel">Zakończ!</string>
|
||||
<string name="manual_marker_info">Twój marker zniknie w ciągu kilku minut.</string>
|
||||
<string name="manual_location_selected">Lokalizacja manualna wybrana!</string>
|
||||
<string name="location_saved">Lokacja zapisana!</string>
|
||||
<string name="network_error">Błąd sieci!</string>
|
||||
<string name="manual_status_error">Błąd podczas pobierania danych.</string>
|
||||
<string name="error_status_fetch">Błąd podczas pobierania statusów.</string>
|
||||
</resources>
|
||||
|
||||
|
||||
|
@ -222,6 +222,10 @@
|
||||
<string name="manual_modal_title">Do you want to save this localization?</string>
|
||||
<string name="lbl_ok">Save!</string>
|
||||
<string name="lbl_cancel">Cancel!</string>
|
||||
|
||||
|
||||
<string name="manual_marker_info">Your marker will disappear in next couple minutes</string>
|
||||
<string name="manual_location_selected">Manual Locations selected!</string>
|
||||
<string name="location_saved">Location saved!</string>
|
||||
<string name="network_error">Network Error!</string>
|
||||
<string name="manual_status_error">Error handling status fetch</string>
|
||||
<string name="error_status_fetch">Error handling status fetch</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user