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