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) {
|
||||
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())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
|
@ -95,7 +95,6 @@ public class MapActivity extends BaseActivity
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
myID = PrefUtils.getUserId(getApplicationContext());
|
||||
// fetching coords service
|
||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
@ -140,8 +139,10 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
removeLocationButton.setOnClickListener(view -> {
|
||||
Log.e(tag + "Manual", "manual coords sending stopped");
|
||||
stopBackgroundLocalizationTask();
|
||||
|
||||
// TODO to remove after BGserv
|
||||
manualLocHandler.removeCallbacks(manualLocStatusChecker);
|
||||
// manualLocHandler.removeCallbacks(manualLocStatusChecker);
|
||||
|
||||
removeLocationButton.setVisibility(View.GONE);
|
||||
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();
|
||||
if (PrefUtils.getIsTutor(this)) {
|
||||
setOnMapLongClickListener();
|
||||
}
|
||||
// addStaticLayer();
|
||||
}
|
||||
|
||||
@ -264,44 +267,8 @@ public class MapActivity extends BaseActivity
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
);
|
||||
|
||||
// TODO remove after BG sending
|
||||
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();
|
||||
|
||||
PrefUtils.putManualLocation(this, latLng);
|
||||
handleBackgroundTaskLifeCycle();
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
@ -334,7 +301,7 @@ public class MapActivity extends BaseActivity
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
|
||||
if (coordsList.isEmpty() && tmpLocalMarker != null) {
|
||||
if (tmpLocalMarker != null && coordsList.isEmpty()) {
|
||||
Timber.e("200 empty []");
|
||||
mapboxMap.clear();
|
||||
return;
|
||||
@ -350,16 +317,13 @@ public class MapActivity extends BaseActivity
|
||||
previousCoordsIds.addAll(currentCoordsIds);
|
||||
} else {
|
||||
// here we clear + it returns bool if sth was removed
|
||||
if (previousCoordsIds.removeAll(currentCoordsIds)) {
|
||||
previousCoordsIds.removeAll(currentCoordsIds);
|
||||
for (String toRemoveId : previousCoordsIds) {
|
||||
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
||||
mapboxMap.removeMarker(markerHash.get(toRemoveId));
|
||||
markerHash.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);
|
||||
marker.setPosition(toDestination);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.e(tag, "Marker Added: " + id);
|
||||
|
||||
|
@ -70,7 +70,10 @@ public class SharingFragment extends PreferenceFragment {
|
||||
.subscribeWith(new DisposableSingleObserver<List<String>>() {
|
||||
@Override
|
||||
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
|
||||
@ -78,6 +81,7 @@ public class SharingFragment extends PreferenceFragment {
|
||||
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
@ -105,7 +109,6 @@ public class SharingFragment extends PreferenceFragment {
|
||||
locationLevelMapping.put(2, SharingLevel.EXACT.toString());
|
||||
locationLevelMapping.put(3, SharingLevel.MANUAL.toString());
|
||||
|
||||
|
||||
statusMapping = new HashMap<Integer, String>();
|
||||
statusMapping.put(0, "available");
|
||||
statusMapping.put(1, "consultation");
|
||||
@ -119,9 +122,10 @@ public class SharingFragment extends PreferenceFragment {
|
||||
});
|
||||
|
||||
/** Sharing level list **/
|
||||
// locationMode.setSummary(PrefUtils.getLocationLevel(getApplicationContext()));
|
||||
locationMode.setOnPreferenceChangeListener((preference, 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(manualLocationButton);
|
||||
|
||||
@ -175,6 +179,12 @@ public class SharingFragment extends PreferenceFragment {
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.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;
|
||||
});
|
||||
@ -199,6 +209,7 @@ public class SharingFragment extends PreferenceFragment {
|
||||
return (String) lp.getEntry();
|
||||
|
||||
}
|
||||
|
||||
protected void updateListPreference(ListPreference lp, Object newValue, String storageKey) {
|
||||
CharSequence[] entries = lp.getEntries();
|
||||
Set<String> defaultEntries = new HashSet(Arrays.asList(entries));
|
||||
@ -229,13 +240,15 @@ public class SharingFragment extends PreferenceFragment {
|
||||
lp.setDefaultValue("1");
|
||||
lp.setEntryValues(entryValues);
|
||||
}
|
||||
private void handleResponse(List<String> resp) {
|
||||
getStatuses(disposable);
|
||||
String newStatus = resp.toArray(new String[resp.size()])[resp.size()-1];
|
||||
// Toast.makeText(getApplicationContext(), newStatus, Toast.LENGTH_SHORT).show();
|
||||
|
||||
statusList.setValue(Integer.toString(resp.size()-1));
|
||||
statusList.setSummary(newStatus);
|
||||
private void handleResponse(List<String> resp) {
|
||||
String newStatus = resp.toArray(new String[resp.size()])[resp.size() - 1];
|
||||
Log.d("GETSTATUSES new status", newStatus);
|
||||
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||
setListPreferenceData(statusList.getKey(), statusesArray);
|
||||
// Log.d("GETSTATUSES nowe lokalne", Arrays.toString(statusList.getEntries()));
|
||||
// statusList.setValue(newStatus);
|
||||
statusList.setValueIndex(resp.size() - 1);
|
||||
}
|
||||
|
||||
private void handleError (Throwable error){
|
||||
|
@ -28,6 +28,7 @@ import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
@ -304,15 +305,20 @@ public class BackgroundLocalizationService extends Service {
|
||||
@Override
|
||||
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;
|
||||
longitude = presencelongitude;
|
||||
approximatedBuildingPart = presenceApproximatedName;
|
||||
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
} 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 {
|
||||
@ -323,7 +329,7 @@ public class BackgroundLocalizationService extends Service {
|
||||
approximatedBuildingPart,
|
||||
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "",
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
locationLevel
|
||||
);
|
||||
|
||||
disposable.add(
|
||||
|
@ -5,6 +5,8 @@ import android.content.SharedPreferences;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.uam.wmi.findmytutor.activity.SharingFragment;
|
||||
import com.auth0.android.jwt.Claim;
|
||||
import com.auth0.android.jwt.JWT;
|
||||
@ -58,9 +60,11 @@ public class PrefUtils {
|
||||
return getSharedPreferences(context).getBoolean("key_status_enabled", false);
|
||||
|
||||
}
|
||||
|
||||
public static String getUserStatus(Context context) {
|
||||
return getSharedPreferences(context).getString("status_entry", "Available");
|
||||
}
|
||||
|
||||
public static void storeStatus(Context context, String status) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("status_entry", status);
|
||||
@ -96,9 +100,11 @@ public class PrefUtils {
|
||||
editor.putBoolean("key_sharing_enabled", isChecked);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getLocationLevel(Context context) {
|
||||
return getSharedPreferences(context).getString("location_mode", "exact");
|
||||
}
|
||||
|
||||
public static void storeLocationMode(Context context, String mode) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("location_mode", mode);
|
||||
@ -150,4 +156,22 @@ public class PrefUtils {
|
||||
editor.putBoolean("BACKGROUND_SERVICE_STATUS", status);
|
||||
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