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

View File

@ -70,7 +70,10 @@ public class SharingFragment extends PreferenceFragment {
.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();
} }
})); }));
} }
@ -118,10 +122,10 @@ public class SharingFragment extends PreferenceFragment {
}); });
/** Sharing level list **/ /** Sharing level list **/
locationMode.setSummary(PrefUtils.getLocationLevel(getApplicationContext())); // 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);
@ -175,6 +179,12 @@ public class SharingFragment extends PreferenceFragment {
.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;
}); });
@ -199,6 +209,7 @@ public class SharingFragment extends PreferenceFragment {
return (String) lp.getEntry(); return (String) lp.getEntry();
} }
protected void updateListPreference(ListPreference lp, Object newValue, String storageKey) { protected void updateListPreference(ListPreference lp, Object newValue, String storageKey) {
CharSequence[] entries = lp.getEntries(); CharSequence[] entries = lp.getEntries();
Set<String> defaultEntries = new HashSet(Arrays.asList(entries)); Set<String> defaultEntries = new HashSet(Arrays.asList(entries));
@ -229,13 +240,15 @@ public class SharingFragment extends PreferenceFragment {
lp.setDefaultValue("1"); lp.setDefaultValue("1");
lp.setEntryValues(entryValues); 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)); private void handleResponse(List<String> resp) {
statusList.setSummary(newStatus); 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){ private void handleError (Throwable error){

View File

@ -159,7 +159,7 @@ public class PrefUtils {
public static void putManualLocation(Context context, LatLng latLng) { public static void putManualLocation(Context context, LatLng latLng) {
SharedPreferences.Editor editor = getSharedPreferences(context).edit(); SharedPreferences.Editor editor = getSharedPreferences(context).edit();
editor.putString("key_location_level","3");
editor.putString("location_mode", "manual"); editor.putString("location_mode", "manual");
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()));