Merge branch 'mapManualLocation' of s416084/find-my-tutor-android into develop
This commit is contained in:
commit
52ff05767e
@ -154,8 +154,11 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void loginProcess(String email, String password) {
|
private void loginProcess(String email, String password) {
|
||||||
ValidateUser user = new ValidateUser(email, password);
|
ValidateUser user = new ValidateUser(email, password);
|
||||||
|
LdapUser fuser = new LdapUser(email,password,"wmi","tutor","henryk","zdzblo",email);
|
||||||
|
|
||||||
disposable.add(ldapService.validate(user)
|
// disposable.add(ldapService.validate(user)
|
||||||
|
|
||||||
|
disposable.add(ldapService.fakeValidate(fuser)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::handleResponse, this::handleError));
|
.subscribe(this::handleResponse, this::handleError));
|
||||||
|
@ -95,7 +95,6 @@ public class MapActivity extends BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
myID = PrefUtils.getUserId(getApplicationContext());
|
myID = PrefUtils.getUserId(getApplicationContext());
|
||||||
// fetching coords service
|
// fetching coords service
|
||||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||||
@ -140,8 +139,10 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
removeLocationButton.setOnClickListener(view -> {
|
removeLocationButton.setOnClickListener(view -> {
|
||||||
Log.e(tag + "Manual", "manual coords sending stopped");
|
Log.e(tag + "Manual", "manual coords sending stopped");
|
||||||
|
stopBackgroundLocalizationTask();
|
||||||
|
|
||||||
// TODO to remove after BGserv
|
// TODO to remove after BGserv
|
||||||
manualLocHandler.removeCallbacks(manualLocStatusChecker);
|
// manualLocHandler.removeCallbacks(manualLocStatusChecker);
|
||||||
|
|
||||||
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, "Your marker will disappear in next couple minutes", Toast.LENGTH_SHORT).show();
|
||||||
@ -156,7 +157,9 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
|
|
||||||
setToggleMapBoundsArea();
|
setToggleMapBoundsArea();
|
||||||
setOnMapLongClickListener();
|
if (PrefUtils.getIsTutor(this)) {
|
||||||
|
setOnMapLongClickListener();
|
||||||
|
}
|
||||||
// addStaticLayer();
|
// addStaticLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,44 +267,8 @@ public class MapActivity extends BaseActivity
|
|||||||
PrefUtils.getUserId(getApplicationContext()),
|
PrefUtils.getUserId(getApplicationContext()),
|
||||||
PrefUtils.getLocationLevel(getApplicationContext())
|
PrefUtils.getLocationLevel(getApplicationContext())
|
||||||
);
|
);
|
||||||
|
PrefUtils.putManualLocation(this, latLng);
|
||||||
// TODO remove after BG sending
|
handleBackgroundTaskLifeCycle();
|
||||||
manualLocStatusChecker = () -> {
|
|
||||||
try {
|
|
||||||
Log.e(tag + "Manual", "sending manual coords");
|
|
||||||
// TODO ^^^ wrapper to removve
|
|
||||||
disposable.add(
|
|
||||||
coordinateService
|
|
||||||
.postCoordinate(droppedMarkercoordinate)
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
|
||||||
@SuppressLint("LongLogTag")
|
|
||||||
@Override
|
|
||||||
public void onSuccess(Coordinate coord) {
|
|
||||||
Log.e(tag + "POST", String.valueOf(coord));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("LongLogTag")
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
|
|
||||||
Log.e(tag + "onError", e.getMessage());
|
|
||||||
|
|
||||||
if (e instanceof HttpException) {
|
|
||||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
|
||||||
Log.e(tag + "onError", RestApiHelper.getErrorMessage(responseBody));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
// TODO \/\/\/\/\/ wrapper to removve
|
|
||||||
} finally {
|
|
||||||
manualLocHandler.postDelayed(manualLocStatusChecker, mInterval);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
manualLocStatusChecker.run();
|
|
||||||
|
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Timber.e(String.valueOf(e));
|
Timber.e(String.valueOf(e));
|
||||||
@ -334,7 +301,7 @@ public class MapActivity extends BaseActivity
|
|||||||
public void onSuccess(List<Coordinate> coordsList) {
|
public void onSuccess(List<Coordinate> coordsList) {
|
||||||
|
|
||||||
|
|
||||||
if (coordsList.isEmpty() && tmpLocalMarker != null) {
|
if (tmpLocalMarker != null && coordsList.isEmpty()) {
|
||||||
Timber.e("200 empty []");
|
Timber.e("200 empty []");
|
||||||
mapboxMap.clear();
|
mapboxMap.clear();
|
||||||
return;
|
return;
|
||||||
@ -350,16 +317,13 @@ public class MapActivity extends BaseActivity
|
|||||||
previousCoordsIds.addAll(currentCoordsIds);
|
previousCoordsIds.addAll(currentCoordsIds);
|
||||||
} else {
|
} else {
|
||||||
// here we clear + it returns bool if sth was removed
|
// here we clear + it returns bool if sth was removed
|
||||||
if (previousCoordsIds.removeAll(currentCoordsIds)) {
|
previousCoordsIds.removeAll(currentCoordsIds);
|
||||||
for (String toRemoveId : previousCoordsIds) {
|
for (String toRemoveId : previousCoordsIds) {
|
||||||
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
||||||
mapboxMap.removeMarker(markerHash.get(toRemoveId));
|
mapboxMap.removeMarker(markerHash.get(toRemoveId));
|
||||||
markerHash.remove(toRemoveId);
|
markerHash.remove(toRemoveId);
|
||||||
coordsMap.remove(toRemoveId);
|
coordsMap.remove(toRemoveId);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO double check when some markers api will change
|
|
||||||
Log.e(tag + "delete: ", "nothing to remove");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,8 +360,8 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
coordsMap.put(id, element);
|
coordsMap.put(id, element);
|
||||||
marker.setPosition(toDestination);
|
marker.setPosition(toDestination);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(tag, "Marker Added: " + id);
|
Log.e(tag, "Marker Added: " + id);
|
||||||
|
|
||||||
|
@ -63,14 +63,17 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
protected Preference manualStatus;
|
protected Preference manualStatus;
|
||||||
protected ListPreference statusList;
|
protected ListPreference statusList;
|
||||||
|
|
||||||
void getStatuses(CompositeDisposable disposable){
|
void getStatuses(CompositeDisposable disposable) {
|
||||||
disposable.add(statusesService.getUserPredefinedStatuses(PrefUtils.getUserId(getApplicationContext()))
|
disposable.add(statusesService.getUserPredefinedStatuses(PrefUtils.getUserId(getApplicationContext()))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribeWith(new DisposableSingleObserver<List<String>>() {
|
.subscribeWith(new DisposableSingleObserver<List<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<String> strings) {
|
public void onSuccess(List<String> strings) {
|
||||||
setListPreferenceData(statusList.getKey(),strings.toArray(new String[strings.size()]));
|
String[] statusesArray = strings.toArray(new String[strings.size()]);
|
||||||
|
setListPreferenceData(statusList.getKey(), statusesArray);
|
||||||
|
Log.d("GETSTATUSES", Arrays.toString(statusesArray));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,6 +81,7 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +97,7 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
manualLocationList = findPreference("key_manual_location_value");
|
manualLocationList = findPreference("key_manual_location_value");
|
||||||
manualLocationButton = (RightButtonPreference) findPreference("manual_location_button");
|
manualLocationButton = (RightButtonPreference) findPreference("manual_location_button");
|
||||||
manualStatus = findPreference("key_manual_status");
|
manualStatus = findPreference("key_manual_status");
|
||||||
statusList =(ListPreference) findPreference("key_status_value");
|
statusList = (ListPreference) findPreference("key_status_value");
|
||||||
|
|
||||||
statusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
|
statusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
|
||||||
disposable = new CompositeDisposable();
|
disposable = new CompositeDisposable();
|
||||||
@ -105,27 +109,27 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
locationLevelMapping.put(2, SharingLevel.EXACT.toString());
|
locationLevelMapping.put(2, SharingLevel.EXACT.toString());
|
||||||
locationLevelMapping.put(3, SharingLevel.MANUAL.toString());
|
locationLevelMapping.put(3, SharingLevel.MANUAL.toString());
|
||||||
|
|
||||||
|
|
||||||
statusMapping = new HashMap<Integer, String>();
|
statusMapping = new HashMap<Integer, String>();
|
||||||
statusMapping.put(0,"available");
|
statusMapping.put(0, "available");
|
||||||
statusMapping.put(1,"consultation");
|
statusMapping.put(1, "consultation");
|
||||||
statusMapping.put(2,"busy");
|
statusMapping.put(2, "busy");
|
||||||
|
|
||||||
/** Main sharing switch**/
|
/** Main sharing switch**/
|
||||||
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
|
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
|
||||||
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
|
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
|
||||||
((MapActivity)getActivity()).handleBackgroundTaskLifeCycle();
|
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Sharing level list **/
|
/** Sharing level list **/
|
||||||
|
// locationMode.setSummary(PrefUtils.getLocationLevel(getApplicationContext()));
|
||||||
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
|
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue)));
|
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
|
||||||
if(PrefUtils.getLocationLevel(getApplicationContext()) == "manual"){
|
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) {
|
||||||
preferenceCategory.addPreference(manualLocationList);
|
preferenceCategory.addPreference(manualLocationList);
|
||||||
preferenceCategory.addPreference(manualLocationButton);
|
preferenceCategory.addPreference(manualLocationButton);
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
preferenceCategory.removePreference(manualLocationList);
|
preferenceCategory.removePreference(manualLocationList);
|
||||||
preferenceCategory.removePreference(manualLocationButton);
|
preferenceCategory.removePreference(manualLocationButton);
|
||||||
}
|
}
|
||||||
@ -133,7 +137,7 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/** Manual location category hiding when location level is != manual **/
|
/** Manual location category hiding when location level is != manual **/
|
||||||
if(!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")){
|
if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
|
||||||
preferenceCategory.removePreference(manualLocationList);
|
preferenceCategory.removePreference(manualLocationList);
|
||||||
preferenceCategory.removePreference(manualLocationButton);
|
preferenceCategory.removePreference(manualLocationButton);
|
||||||
}
|
}
|
||||||
@ -160,7 +164,7 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
statusList.setOnPreferenceChangeListener((preference, newValue) -> {
|
statusList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
ListPreference lp = (ListPreference) preference;
|
ListPreference lp = (ListPreference) preference;
|
||||||
CharSequence [] entries = lp.getEntries();
|
CharSequence [] entries = lp.getEntries();
|
||||||
PrefUtils.storeStatus(getApplicationContext(),(String) entries[Integer.parseInt((String) newValue)]);
|
PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]);
|
||||||
// PrefUtils.storeStatus(getApplicationContext(),statusMapping.get(Integer.parseInt((String) newValue)));
|
// PrefUtils.storeStatus(getApplicationContext(),statusMapping.get(Integer.parseInt((String) newValue)));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -171,10 +175,16 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
// updateListPreference(lp, newValue, "manual_statuses");
|
// updateListPreference(lp, newValue, "manual_statuses");
|
||||||
// PrefUtils.storeStatus(getApplicationContext(),(String) newValue);
|
// PrefUtils.storeStatus(getApplicationContext(),(String) newValue);
|
||||||
// statusList.setValue((String) newValue);
|
// statusList.setValue((String) newValue);
|
||||||
disposable.add(statusesService.postUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()),(String) newValue)
|
disposable.add(statusesService.postUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), (String) newValue)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::handleResponse, this::handleError));
|
.subscribe(this::handleResponse, this::handleError));
|
||||||
|
// Log.d("GETSTATUSES", "statusy po dodaniu nowego");
|
||||||
|
// getStatuses(disposable);
|
||||||
|
// CharSequence[] entriesIndexes = statusList.getEntries();
|
||||||
|
//// Log.d("GETENTRIES", Arrays.toString(entriesIndexes));
|
||||||
|
// Log.d("GETENTRIES ostatni w handle response", (String) entriesIndexes[entriesIndexes.length - 1]);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -194,25 +204,26 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getListPreferenceValue(String key){
|
public String getListPreferenceValue(String key) {
|
||||||
ListPreference lp = (ListPreference) findPreference(key);
|
ListPreference lp = (ListPreference) findPreference(key);
|
||||||
return (String)lp.getEntry();
|
return (String) lp.getEntry();
|
||||||
|
|
||||||
}
|
}
|
||||||
protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){
|
|
||||||
CharSequence [] entries = lp.getEntries();
|
protected void updateListPreference(ListPreference lp, Object newValue, String storageKey) {
|
||||||
|
CharSequence[] entries = lp.getEntries();
|
||||||
Set<String> defaultEntries = new HashSet(Arrays.asList(entries));
|
Set<String> defaultEntries = new HashSet(Arrays.asList(entries));
|
||||||
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
|
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
|
||||||
|
|
||||||
Set <String> manualStatusSet = sharedPref.getStringSet(storageKey,defaultEntries);
|
Set<String> manualStatusSet = sharedPref.getStringSet(storageKey, defaultEntries);
|
||||||
manualStatusSet.add((String) newValue);
|
manualStatusSet.add((String) newValue);
|
||||||
String [] manualStatusArr = manualStatusSet.toArray(new String[0]);
|
String[] manualStatusArr = manualStatusSet.toArray(new String[0]);
|
||||||
//Arrays.sort(manualStatusArr);
|
//Arrays.sort(manualStatusArr);
|
||||||
setListPreferenceData(lp.getKey(),manualStatusArr);
|
setListPreferenceData(lp.getKey(), manualStatusArr);
|
||||||
// lp.setValue((String) newValue);
|
// lp.setValue((String) newValue);
|
||||||
|
|
||||||
SharedPreferences.Editor editor = sharedPref.edit();
|
SharedPreferences.Editor editor = sharedPref.edit();
|
||||||
editor.putStringSet(storageKey,manualStatusSet);
|
editor.putStringSet(storageKey, manualStatusSet);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,36 +231,38 @@ public class SharingFragment extends PreferenceFragment {
|
|||||||
//todo bug z pustym statusem
|
//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];
|
||||||
|
|
||||||
for (int i = 0; i < entries.length; i++){
|
for (int i = 0; i < entries.length; i++) {
|
||||||
entryValues[i] = Integer.toString(i);
|
entryValues[i] = Integer.toString(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
lp.setDefaultValue("1");
|
lp.setDefaultValue("1");
|
||||||
lp.setEntryValues(entryValues);
|
lp.setEntryValues(entryValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleResponse(List<String> resp) {
|
private void handleResponse(List<String> resp) {
|
||||||
getStatuses(disposable);
|
String newStatus = resp.toArray(new String[resp.size()])[resp.size() - 1];
|
||||||
String newStatus = resp.toArray(new String[resp.size()])[resp.size()-1];
|
Log.d("GETSTATUSES new status", newStatus);
|
||||||
// Toast.makeText(getApplicationContext(), newStatus, Toast.LENGTH_SHORT).show();
|
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||||
|
setListPreferenceData(statusList.getKey(), statusesArray);
|
||||||
statusList.setValue(Integer.toString(resp.size()-1));
|
// Log.d("GETSTATUSES nowe lokalne", Arrays.toString(statusList.getEntries()));
|
||||||
statusList.setSummary(newStatus);
|
// statusList.setValue(newStatus);
|
||||||
|
statusList.setValueIndex(resp.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleError(Throwable error) {
|
private void handleError (Throwable error){
|
||||||
if (error instanceof HttpException) {
|
if (error instanceof HttpException) {
|
||||||
|
|
||||||
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
||||||
Toast.makeText(getApplicationContext(),
|
Toast.makeText(getApplicationContext(),
|
||||||
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
|
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getApplicationContext(),
|
Toast.makeText(getApplicationContext(),
|
||||||
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
Log.d("FEEDBACK",error.getMessage());
|
Log.d("FEEDBACK", error.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import com.google.android.gms.location.LocationServices;
|
|||||||
import com.google.android.gms.tasks.OnSuccessListener;
|
import com.google.android.gms.tasks.OnSuccessListener;
|
||||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||||
import com.mapbox.geojson.Point;
|
import com.mapbox.geojson.Point;
|
||||||
|
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||||
@ -304,15 +305,20 @@ public class BackgroundLocalizationService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
protected Object doInBackground(Object[] objects) {
|
protected Object doInBackground(Object[] objects) {
|
||||||
|
|
||||||
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
|
String locationLevel = PrefUtils.getLocationLevel(getApplicationContext());
|
||||||
|
|
||||||
|
if (locationLevel.equals(SharingLevel.PRESENCE.toString())) {
|
||||||
latitude = presenceLatitude;
|
latitude = presenceLatitude;
|
||||||
longitude = presencelongitude;
|
longitude = presencelongitude;
|
||||||
approximatedBuildingPart = presenceApproximatedName;
|
approximatedBuildingPart = presenceApproximatedName;
|
||||||
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())) {
|
} else if (locationLevel.equals(SharingLevel.APPROXIMATED.toString())) {
|
||||||
List<Double> points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart);
|
List<Double> points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart);
|
||||||
|
|
||||||
latitude = points.get(0);
|
latitude = points.get(0);
|
||||||
longitude = points.get(1);
|
longitude = points.get(1);
|
||||||
|
} else if (locationLevel.equals(SharingLevel.MANUAL.toString())) {
|
||||||
|
LatLng latLng = PrefUtils.getManualLocation(getApplicationContext());
|
||||||
|
latitude = latLng.getLatitude();
|
||||||
|
longitude = latLng.getLongitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -323,7 +329,7 @@ public class BackgroundLocalizationService extends Service {
|
|||||||
approximatedBuildingPart,
|
approximatedBuildingPart,
|
||||||
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "",
|
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "",
|
||||||
PrefUtils.getUserId(getApplicationContext()),
|
PrefUtils.getUserId(getApplicationContext()),
|
||||||
PrefUtils.getLocationLevel(getApplicationContext())
|
locationLevel
|
||||||
);
|
);
|
||||||
|
|
||||||
disposable.add(
|
disposable.add(
|
||||||
|
@ -5,6 +5,8 @@ import android.content.SharedPreferences;
|
|||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||||
import com.uam.wmi.findmytutor.activity.SharingFragment;
|
import com.uam.wmi.findmytutor.activity.SharingFragment;
|
||||||
import com.auth0.android.jwt.Claim;
|
import com.auth0.android.jwt.Claim;
|
||||||
import com.auth0.android.jwt.JWT;
|
import com.auth0.android.jwt.JWT;
|
||||||
@ -20,11 +22,11 @@ public class PrefUtils {
|
|||||||
return context.getSharedPreferences("com.uam.wmi.findmytutor_preferences", Context.MODE_PRIVATE);
|
return context.getSharedPreferences("com.uam.wmi.findmytutor_preferences", Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getAllKeys(Context context){
|
public static void getAllKeys(Context context) {
|
||||||
Map<String,?> keys = getSharedPreferences(context).getAll();
|
Map<String, ?> keys = getSharedPreferences(context).getAll();
|
||||||
|
|
||||||
for(Map.Entry<String,?> entry : keys.entrySet()){
|
for (Map.Entry<String, ?> entry : keys.entrySet()) {
|
||||||
Log.d("map values",entry.getKey() + ": " + entry.getValue().toString());
|
Log.d("map values", entry.getKey() + ": " + entry.getValue().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,14 +56,16 @@ public class PrefUtils {
|
|||||||
return getSharedPreferences(context).getString("USER_ID", null);
|
return getSharedPreferences(context).getString("USER_ID", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStatusEnabled(Context context){
|
public static boolean isStatusEnabled(Context context) {
|
||||||
return getSharedPreferences(context).getBoolean("key_status_enabled",false);
|
return getSharedPreferences(context).getBoolean("key_status_enabled", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUserStatus(Context context) {
|
public static String getUserStatus(Context context) {
|
||||||
return getSharedPreferences(context).getString("status_entry", "Available");
|
return getSharedPreferences(context).getString("status_entry", "Available");
|
||||||
}
|
}
|
||||||
public static void storeStatus(Context context, String status){
|
|
||||||
|
public static void storeStatus(Context context, String status) {
|
||||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||||
editor.putString("status_entry", status);
|
editor.putString("status_entry", status);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
@ -91,15 +95,17 @@ public class PrefUtils {
|
|||||||
return getSharedPreferences(context).getBoolean("key_sharing_enabled", false);
|
return getSharedPreferences(context).getBoolean("key_sharing_enabled", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void storeEnableSharingLocalization(Context context,Boolean isChecked) {
|
public static void storeEnableSharingLocalization(Context context, Boolean isChecked) {
|
||||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||||
editor.putBoolean("key_sharing_enabled", isChecked);
|
editor.putBoolean("key_sharing_enabled", isChecked);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
public static String getLocationLevel(Context context){
|
|
||||||
|
public static String getLocationLevel(Context context) {
|
||||||
return getSharedPreferences(context).getString("location_mode", "exact");
|
return getSharedPreferences(context).getString("location_mode", "exact");
|
||||||
}
|
}
|
||||||
public static void storeLocationMode(Context context, String mode){
|
|
||||||
|
public static void storeLocationMode(Context context, String mode) {
|
||||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||||
editor.putString("location_mode", mode);
|
editor.putString("location_mode", mode);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
@ -150,4 +156,22 @@ public class PrefUtils {
|
|||||||
editor.putBoolean("BACKGROUND_SERVICE_STATUS", status);
|
editor.putBoolean("BACKGROUND_SERVICE_STATUS", status);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void putManualLocation(Context context, LatLng latLng) {
|
||||||
|
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||||
|
editor.putString("key_location_level","3");
|
||||||
|
editor.putString("location_mode", "manual");
|
||||||
|
editor.putBoolean("key_sharing_enabled", true);
|
||||||
|
editor.putLong("longitude_manual_location", Double.doubleToRawLongBits(latLng.getLongitude()));
|
||||||
|
editor.putLong("latitude_manual_location", Double.doubleToRawLongBits(latLng.getLatitude()));
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LatLng getManualLocation(Context context) {
|
||||||
|
return new LatLng(
|
||||||
|
Double.longBitsToDouble(getSharedPreferences(context).getLong("latitude_manual_location", 0)),
|
||||||
|
Double.longBitsToDouble(getSharedPreferences(context).getLong("longitude_manual_location", 0))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user