fixed switching location mode, adding custom status, and switching on location service when choosing manual location from map tab

This commit is contained in:
marcin.jedynski 2018-11-26 16:21:29 +01:00
parent 35ba11129c
commit 854ddadeea
3 changed files with 56 additions and 42 deletions

View File

@ -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())
@ -269,6 +268,8 @@ public class MapActivity extends BaseActivity
PrefUtils.getLocationLevel(getApplicationContext())
);
PrefUtils.putManualLocation(this, latLng);
handleBackgroundTaskLifeCycle();
// // TODO remove after BG sending
// manualLocStatusChecker = () -> {

View File

@ -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();
}
}));
}
@ -118,10 +122,10 @@ public class SharingFragment extends PreferenceFragment {
});
/** Sharing level list **/
locationMode.setSummary(PrefUtils.getLocationLevel(getApplicationContext()));
// 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){

View File

@ -159,7 +159,7 @@ public class PrefUtils {
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()));