Merge branch 'fix-bugs-related-to-network' of s416084/find-my-tutor-android into develop
This commit is contained in:
commit
331e7b5fe3
@ -86,6 +86,7 @@ public class BlackList extends AppCompatActivity {
|
|||||||
Switch aSwitch;
|
Switch aSwitch;
|
||||||
@BindView(R.id.add_to_black_list_fab)
|
@BindView(R.id.add_to_black_list_fab)
|
||||||
FloatingActionButton addToBlackListFab;
|
FloatingActionButton addToBlackListFab;
|
||||||
|
|
||||||
private Integer prevSize;
|
private Integer prevSize;
|
||||||
private BlackListAdapter mAdapter;
|
private BlackListAdapter mAdapter;
|
||||||
private List<User> blacklistedUsers = new ArrayList<>();
|
private List<User> blacklistedUsers = new ArrayList<>();
|
||||||
@ -283,27 +284,6 @@ public class BlackList extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
disposable.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
@ -358,4 +338,25 @@ public class BlackList extends AppCompatActivity {
|
|||||||
},this::showError)
|
},this::showError)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
disposable.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,6 @@ import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
|||||||
import com.uam.wmi.findmytutor.utils.RightButtonPreference;
|
import com.uam.wmi.findmytutor.utils.RightButtonPreference;
|
||||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||||
|
|
||||||
import org.apache.commons.collections4.BidiMap;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -59,9 +57,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
protected RightButtonPreference removeManualStatus;
|
protected RightButtonPreference removeManualStatus;
|
||||||
protected Preference manualStatus;
|
protected Preference manualStatus;
|
||||||
protected ListPreference statusList;
|
protected ListPreference statusList;
|
||||||
private HashMap<String,String> locationMap;
|
|
||||||
private ArrayList <String> locationUUIDs;
|
|
||||||
protected List<PredefinedCoordViewModel> predefinedCoordsList = new ArrayList<>();
|
protected List<PredefinedCoordViewModel> predefinedCoordsList = new ArrayList<>();
|
||||||
|
private HashMap<String, String> locationMap;
|
||||||
|
private ArrayList<String> locationUUIDs;
|
||||||
private HashMap<Integer, String> locationLevelMapping;
|
private HashMap<Integer, String> locationLevelMapping;
|
||||||
private HashMap<Integer, String> statusMapping;
|
private HashMap<Integer, String> statusMapping;
|
||||||
private PredefinedStatusesService statusesService;
|
private PredefinedStatusesService statusesService;
|
||||||
@ -70,9 +68,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
private AlertDialog.Builder builder;
|
private AlertDialog.Builder builder;
|
||||||
private String[] statusesArray;
|
private String[] statusesArray;
|
||||||
private boolean statusSwitchFlag;
|
private boolean statusSwitchFlag;
|
||||||
private ArrayList<String> predefinedLocationsList;
|
private ArrayList<String> predefinedLocationsList;
|
||||||
|
|
||||||
public static SharingFragment newInstance() {
|
public static SharingFragment newInstance() {
|
||||||
return new SharingFragment();
|
return new SharingFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +82,12 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
.subscribeWith(new DisposableSingleObserver<List<String>>() {
|
.subscribeWith(new DisposableSingleObserver<List<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<String> strings) {
|
public void onSuccess(List<String> strings) {
|
||||||
statusesArray = strings.toArray(new String[strings.size()]);
|
statusesArray = strings.toArray(new String[strings.size()]);
|
||||||
if(strings.isEmpty()){
|
if (strings.isEmpty()) {
|
||||||
disableStatusPreferences();
|
disableStatusPreferences();
|
||||||
}else{
|
} else {
|
||||||
enableStatusPreferences();
|
enableStatusPreferences();
|
||||||
}
|
}
|
||||||
// Log.d("STATUSES",Integer.toString(statusesArray.length ));
|
// Log.d("STATUSES",Integer.toString(statusesArray.length ));
|
||||||
setListPreferenceData(statusList, statusesArray, null);
|
setListPreferenceData(statusList, statusesArray, null);
|
||||||
}
|
}
|
||||||
@ -112,45 +110,46 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
public void onSuccess(List<PredefinedCoordViewModel> coords) {
|
public void onSuccess(List<PredefinedCoordViewModel> coords) {
|
||||||
|
|
||||||
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||||
locationMap = new HashMap<String,String>();
|
locationMap = new HashMap<String, String>();
|
||||||
locationUUIDs = new ArrayList<String>();
|
locationUUIDs = new ArrayList<String>();
|
||||||
for (PredefinedCoordViewModel i : coords) locationMap.put(i.getPredefinedCoordinateId(),i.getName());
|
for (PredefinedCoordViewModel i : coords)
|
||||||
for (PredefinedCoordViewModel i : coords) locationUUIDs.add(i.getPredefinedCoordinateId());
|
locationMap.put(i.getPredefinedCoordinateId(), i.getName());
|
||||||
List<String> predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList();
|
for (PredefinedCoordViewModel i : coords)
|
||||||
List<String> predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList();
|
locationUUIDs.add(i.getPredefinedCoordinateId());
|
||||||
|
List<String> predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList();
|
||||||
|
List<String> predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList();
|
||||||
predefinedCoordsList.addAll(coords);
|
predefinedCoordsList.addAll(coords);
|
||||||
|
|
||||||
String[] stringnames = predefinedLocationsNames.toArray(new String[0]);
|
String[] stringnames = predefinedLocationsNames.toArray(new String[0]);
|
||||||
predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames));
|
predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames));
|
||||||
if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
|
if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
|
||||||
preferenceCategory.removePreference(manualLocationList);
|
preferenceCategory.removePreference(manualLocationList);
|
||||||
preferenceCategory.removePreference(removeManualLocation);
|
preferenceCategory.removePreference(removeManualLocation);
|
||||||
preferenceCategory.removePreference(manualLocationButton);
|
preferenceCategory.removePreference(manualLocationButton);
|
||||||
}else{
|
} else {
|
||||||
if(predefinedCoordsList.isEmpty()){
|
if (predefinedCoordsList.isEmpty()) {
|
||||||
locationSharing.setEnabled(false);
|
locationSharing.setEnabled(false);
|
||||||
locationSharing.setChecked(false);
|
locationSharing.setChecked(false);
|
||||||
PrefUtils.disableSharing(getApplicationContext());
|
PrefUtils.disableSharing(getApplicationContext());
|
||||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||||
removeManualLocation.setEnabled(false);
|
removeManualLocation.setEnabled(false);
|
||||||
manualLocationList.setEnabled(false);
|
manualLocationList.setEnabled(false);
|
||||||
manualLocationList.setSummary("");
|
manualLocationList.setSummary("");
|
||||||
}else{
|
} else {
|
||||||
manualLocationList.setEnabled(true);
|
manualLocationList.setEnabled(true);
|
||||||
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
||||||
removeManualLocation.setEnabled(true);
|
removeManualLocation.setEnabled(true);
|
||||||
locationSharing.setEnabled(true);
|
locationSharing.setEnabled(true);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Integer> activesId = Stream.of(coords).indexed()
|
List<Integer> activesId = Stream.of(coords).indexed()
|
||||||
.filter(v -> v.getSecond().getPredefinedCoordinateId().equals(currentCoordId)).map(IntPair::getFirst).toList();
|
.filter(v -> v.getSecond().getPredefinedCoordinateId().equals(currentCoordId)).map(IntPair::getFirst).toList();
|
||||||
|
|
||||||
if( activesId.size() == 0){
|
if (activesId.size() == 0) {
|
||||||
setListPreferenceData(manualLocationList, stringnames, null);
|
setListPreferenceData(manualLocationList, stringnames, null);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setListPreferenceData(manualLocationList, stringnames, activesId.get(0));
|
setListPreferenceData(manualLocationList, stringnames, activesId.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,11 +179,11 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
removeManualStatus = (RightButtonPreference) findPreference("remove_manual_status");
|
removeManualStatus = (RightButtonPreference) findPreference("remove_manual_status");
|
||||||
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);
|
||||||
locationService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class);
|
locationService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class);
|
||||||
disposable = new CompositeDisposable();
|
disposable = new CompositeDisposable();
|
||||||
statusesArray = new String[0];
|
statusesArray = new String[0];
|
||||||
predefinedLocationsList = new ArrayList<String>();
|
predefinedLocationsList = new ArrayList<String>();
|
||||||
getStatuses(disposable);
|
getStatuses(disposable);
|
||||||
getLocations(disposable);
|
getLocations(disposable);
|
||||||
locationLevelMapping = new HashMap<Integer, String>();
|
locationLevelMapping = new HashMap<Integer, String>();
|
||||||
@ -216,21 +215,21 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
|
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
|
||||||
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
|
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
|
||||||
if (!predefinedCoordsList.isEmpty()) {
|
if (!predefinedCoordsList.isEmpty()) {
|
||||||
preferenceCategory.addPreference(manualLocationList);
|
preferenceCategory.addPreference(manualLocationList);
|
||||||
preferenceCategory.addPreference(removeManualLocation);
|
preferenceCategory.addPreference(removeManualLocation);
|
||||||
}else{
|
} else {
|
||||||
locationSharing.setEnabled(false);
|
locationSharing.setEnabled(false);
|
||||||
locationSharing.setChecked(false);
|
locationSharing.setChecked(false);
|
||||||
PrefUtils.disableSharing(getApplicationContext());
|
PrefUtils.disableSharing(getApplicationContext());
|
||||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||||
|
|
||||||
}
|
}
|
||||||
preferenceCategory.addPreference(manualLocationButton);
|
preferenceCategory.addPreference(manualLocationButton);
|
||||||
} else {
|
} else {
|
||||||
locationSharing.setEnabled(true);
|
locationSharing.setEnabled(true);
|
||||||
preferenceCategory.removePreference(manualLocationList);
|
preferenceCategory.removePreference(manualLocationList);
|
||||||
preferenceCategory.removePreference(manualLocationButton);
|
preferenceCategory.removePreference(manualLocationButton);
|
||||||
preferenceCategory.removePreference(removeManualLocation);
|
preferenceCategory.removePreference(removeManualLocation);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -240,6 +239,8 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
|
|
||||||
/** 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;
|
||||||
CharSequence[] entries = lp.getEntries();
|
CharSequence[] entries = lp.getEntries();
|
||||||
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
|
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
|
||||||
@ -260,7 +261,6 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Button 'choose from map' button listener **/
|
/** Button 'choose from map' button listener **/
|
||||||
manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
|
manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
|
||||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||||
@ -269,7 +269,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
statusSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
statusSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
/** Status list change listener **/
|
/** Status list change listener **/
|
||||||
statusList.setOnPreferenceChangeListener((preference, newValue) -> {
|
statusList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
@ -290,38 +290,39 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
removeManualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
removeManualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
showRemoveDialog(statusList.getEntries(),"status");
|
showRemoveDialog(statusList.getEntries(), "status");
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
removeManualLocation.setOnPreferenceChangeListener(((preference, newValue) -> {
|
removeManualLocation.setOnPreferenceChangeListener(((preference, newValue) -> {
|
||||||
showRemoveDialog(manualLocationList.getEntries(),"location");
|
showRemoveDialog(manualLocationList.getEntries(), "location");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
public void showRemoveDialog(CharSequence[] entries, String service){
|
|
||||||
boolean [] checked = new boolean[entries.length];
|
public void showRemoveDialog(CharSequence[] entries, String service) {
|
||||||
|
boolean[] checked = new boolean[entries.length];
|
||||||
ArrayList<String> tobeDeleted = new ArrayList<String>();
|
ArrayList<String> tobeDeleted = new ArrayList<String>();
|
||||||
// Log.d("sharingDialog", "no to siup");
|
// Log.d("sharingDialog", "no to siup");
|
||||||
builder.setPositiveButton("DELETE", new DialogInterface.OnClickListener() {
|
builder.setPositiveButton("DELETE", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
for (int i=0; i< entries.length; i++){
|
for (int i = 0; i < entries.length; i++) {
|
||||||
if(checked[i] == true) {
|
if (checked[i] == true) {
|
||||||
tobeDeleted.add((String) entries[i]);
|
tobeDeleted.add((String) entries[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeEntries(service,tobeDeleted);
|
removeEntries(service, tobeDeleted);
|
||||||
// Log.d("MANAGE-PREF",tobeDeleted.toString());
|
// Log.d("MANAGE-PREF",tobeDeleted.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setMultiChoiceItems(entries, checked, new DialogInterface.OnMultiChoiceClickListener() {
|
builder.setMultiChoiceItems(entries, checked, new DialogInterface.OnMultiChoiceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,34 +334,34 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeEntries(String service, ArrayList<String> toBeDeleted){
|
protected void removeEntries(String service, ArrayList<String> toBeDeleted) {
|
||||||
|
|
||||||
// Log.d("MANAGE-PREF", toBeDeleted.toString());
|
// Log.d("MANAGE-PREF", toBeDeleted.toString());
|
||||||
if(service.equals("status")){
|
if (service.equals("status")) {
|
||||||
for (String uuid:toBeDeleted) {
|
for (String uuid : toBeDeleted) {
|
||||||
disposable.add(statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), uuid)
|
disposable.add(statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), uuid)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::handleDeleteStatuses, this::handleError));
|
.subscribe(this::handleDeleteStatuses, this::handleError));
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
ArrayList<String> uuidsToBeDeleted = new ArrayList<String>();
|
ArrayList<String> uuidsToBeDeleted = new ArrayList<String>();
|
||||||
for (String name:toBeDeleted) {
|
for (String name : toBeDeleted) {
|
||||||
for (String uuid:locationUUIDs) {
|
for (String uuid : locationUUIDs) {
|
||||||
if(locationMap.get(uuid).equals(name)){
|
if (locationMap.get(uuid).equals(name)) {
|
||||||
uuidsToBeDeleted.add(uuid);
|
uuidsToBeDeleted.add(uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for (String uuid : uuidsToBeDeleted) {
|
||||||
for (String uuid : uuidsToBeDeleted) {
|
|
||||||
// predefinedCoordsList.removeIf(x -> x.getPredefinedCoordinateId().equals(uuid));
|
// predefinedCoordsList.removeIf(x -> x.getPredefinedCoordinateId().equals(uuid));
|
||||||
predefinedCoordsList.removeAll(Stream.of(predefinedCoordsList).filter(x -> x.getPredefinedCoordinateId().equals(uuid)).toList());
|
predefinedCoordsList.removeAll(Stream.of(predefinedCoordsList).filter(x -> x.getPredefinedCoordinateId().equals(uuid)).toList());
|
||||||
disposable.add(locationService.deleteUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), uuid)
|
disposable.add(locationService.deleteUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), uuid)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::handleDeleteLocations, this::handleError));
|
.subscribe(this::handleDeleteLocations, this::handleError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setListPreferenceData(ListPreference lp, String[] entries, Integer activeId) {
|
protected void setListPreferenceData(ListPreference lp, String[] entries, Integer activeId) {
|
||||||
@ -388,13 +389,13 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
;
|
;
|
||||||
|
|
||||||
private void handleResponse(List<String> resp) {
|
private void handleResponse(List<String> resp) {
|
||||||
if(resp.size() == 1){
|
if (resp.size() == 1) {
|
||||||
enableStatusPreferences();
|
enableStatusPreferences();
|
||||||
if(PrefUtils.isStatusEnabled(getApplicationContext()) == false){
|
if (PrefUtils.isStatusEnabled(getApplicationContext()) == false) {
|
||||||
PrefUtils.enableStatus(getApplicationContext());
|
PrefUtils.enableStatus(getApplicationContext());
|
||||||
statusSwitch.setChecked(true);
|
statusSwitch.setChecked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||||
setListPreferenceData(statusList, statusesArray, resp.size() - 1);
|
setListPreferenceData(statusList, statusesArray, resp.size() - 1);
|
||||||
statusList.setValueIndex(resp.size() - 1);
|
statusList.setValueIndex(resp.size() - 1);
|
||||||
@ -413,79 +414,84 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void handleDeleteStatuses(List<String> resp){
|
|
||||||
if(resp.isEmpty()){
|
|
||||||
disableStatusPreferences();
|
|
||||||
}else{
|
|
||||||
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
|
||||||
setListPreferenceData(statusList, statusesArray, null);
|
|
||||||
String currentEntry = PrefUtils.getUserStatus(getApplicationContext());
|
|
||||||
if(resp.contains(currentEntry)){
|
|
||||||
statusList.setValueIndex(resp.indexOf(currentEntry));
|
|
||||||
}else{
|
|
||||||
statusList.setValueIndex(0);
|
|
||||||
statusList.setSummary(resp.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
private void handleDeleteStatuses(List<String> resp) {
|
||||||
private void handleDeleteLocations(List<PredefinedCoordViewModel> resp){
|
if (resp.isEmpty()) {
|
||||||
getLocations(disposable);
|
disableStatusPreferences();
|
||||||
String currentEntry = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
} else {
|
||||||
if(resp.isEmpty()){
|
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||||
disableManualLocationPreferences();
|
setListPreferenceData(statusList, statusesArray, null);
|
||||||
}else{
|
String currentEntry = PrefUtils.getUserStatus(getApplicationContext());
|
||||||
if(!Stream.of(resp).filter(x -> x.getName().equals(currentEntry)).toList().isEmpty())
|
if (resp.contains(currentEntry)) {
|
||||||
{
|
statusList.setValueIndex(resp.indexOf(currentEntry));
|
||||||
for (PredefinedCoordViewModel location: resp) {
|
} else {
|
||||||
if(location.getName().equals(currentEntry)){
|
statusList.setValueIndex(0);
|
||||||
manualLocationList.setValueIndex(resp.indexOf(location));
|
statusList.setSummary(resp.get(0));
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
manualLocationList.setValueIndex(0);
|
|
||||||
manualLocationList.setSummary(resp.get(0).getName());
|
|
||||||
//todo czy na pewno w shared pref sa dobre wartosci
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private void disableStatusPreferences(){
|
|
||||||
removeManualStatus.setEnabled(false);
|
|
||||||
statusList.setEnabled(false);
|
|
||||||
statusSwitch.setEnabled(false);
|
|
||||||
statusList.setSummary("");
|
|
||||||
PrefUtils.disableStatus(getApplicationContext());
|
|
||||||
|
|
||||||
}
|
private void handleDeleteLocations(List<PredefinedCoordViewModel> resp) {
|
||||||
private void enableStatusPreferences(){
|
getLocations(disposable);
|
||||||
removeManualStatus.setEnabled(true);
|
String currentEntry = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||||
statusList.setEnabled(true);
|
if (resp.isEmpty()) {
|
||||||
statusSwitch.setEnabled(true);
|
disableManualLocationPreferences();
|
||||||
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
} else {
|
||||||
}
|
if (!Stream.of(resp).filter(x -> x.getName().equals(currentEntry)).toList().isEmpty()) {
|
||||||
private void disableManualLocationPreferences(){
|
for (PredefinedCoordViewModel location : resp) {
|
||||||
removeManualLocation.setEnabled(false);
|
if (location.getName().equals(currentEntry)) {
|
||||||
manualLocationList.setEnabled(false);
|
manualLocationList.setValueIndex(resp.indexOf(location));
|
||||||
manualLocationList.setSummary("");
|
break;
|
||||||
locationSharing.setChecked(false);
|
}
|
||||||
locationSharing.setEnabled(false);
|
}
|
||||||
PrefUtils.disableSharing(getApplicationContext());
|
} else {
|
||||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
manualLocationList.setValueIndex(0);
|
||||||
|
manualLocationList.setSummary(resp.get(0).getName());
|
||||||
}
|
//todo czy na pewno w shared pref sa dobre wartosci
|
||||||
private void enableManualLocationPreferences(){
|
}
|
||||||
removeManualLocation.setEnabled(true);
|
|
||||||
manualLocationList.setEnabled(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
locationSharing.setChecked(PrefUtils.isEnableSharingLocalization(getApplicationContext()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disableStatusPreferences() {
|
||||||
|
removeManualStatus.setEnabled(false);
|
||||||
|
statusList.setEnabled(false);
|
||||||
|
statusSwitch.setEnabled(false);
|
||||||
|
statusList.setSummary("");
|
||||||
|
PrefUtils.disableStatus(getApplicationContext());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableStatusPreferences() {
|
||||||
|
removeManualStatus.setEnabled(true);
|
||||||
|
statusList.setEnabled(true);
|
||||||
|
statusSwitch.setEnabled(true);
|
||||||
|
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disableManualLocationPreferences() {
|
||||||
|
removeManualLocation.setEnabled(false);
|
||||||
|
manualLocationList.setEnabled(false);
|
||||||
|
manualLocationList.setSummary("");
|
||||||
|
locationSharing.setChecked(false);
|
||||||
|
locationSharing.setEnabled(false);
|
||||||
|
PrefUtils.disableSharing(getApplicationContext());
|
||||||
|
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableManualLocationPreferences() {
|
||||||
|
removeManualLocation.setEnabled(true);
|
||||||
|
manualLocationList.setEnabled(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
locationSharing.setChecked(PrefUtils.isEnableSharingLocalization(getApplicationContext()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
@ -499,4 +505,10 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
|||||||
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
disposable.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,12 @@ public class TutorTab extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
int code = ((HttpException) e).response().code();
|
int code = 0;
|
||||||
|
|
||||||
|
if (e instanceof HttpException) {
|
||||||
|
code = ((HttpException) e).response().code();
|
||||||
|
}
|
||||||
|
|
||||||
if( code == 404){
|
if( code == 404){
|
||||||
ifTutorTabExists = false;
|
ifTutorTabExists = false;
|
||||||
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),new ArrayList<DutyHourViewModel>());
|
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),new ArrayList<DutyHourViewModel>());
|
||||||
|
@ -56,12 +56,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
|||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.functions.Function;
|
import io.reactivex.functions.Function;
|
||||||
import io.reactivex.observers.DisposableObserver;
|
import io.reactivex.observers.DisposableObserver;
|
||||||
import io.reactivex.observers.DisposableSingleObserver;
|
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class WhiteList extends AppCompatActivity {
|
public class WhiteList extends AppCompatActivity {
|
||||||
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
@ -77,12 +74,12 @@ public class WhiteList extends AppCompatActivity {
|
|||||||
Switch aSwitch;
|
Switch aSwitch;
|
||||||
@BindView(R.id.add_to_white_list_fab)
|
@BindView(R.id.add_to_white_list_fab)
|
||||||
FloatingActionButton addToWhiteListFab;
|
FloatingActionButton addToWhiteListFab;
|
||||||
|
|
||||||
private WhiteListAdapter mAdapter;
|
private WhiteListAdapter mAdapter;
|
||||||
private Integer prevSize;
|
private Integer prevSize;
|
||||||
private List<User> whitelistedUsers = new ArrayList<>();
|
private List<User> whitelistedUsers = new ArrayList<>();
|
||||||
private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL"));
|
private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL"));
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -228,11 +225,12 @@ public class WhiteList extends AppCompatActivity {
|
|||||||
|
|
||||||
private void sendUserToWhitelist(String body) {
|
private void sendUserToWhitelist(String body) {
|
||||||
StudentIdModel studentIdModel = new StudentIdModel(body);
|
StudentIdModel studentIdModel = new StudentIdModel(body);
|
||||||
|
|
||||||
disposable.add(
|
disposable.add(
|
||||||
userService.addStudentToWhitelist(PrefUtils.getUserId(getApplicationContext()), studentIdModel)
|
userService.addStudentToWhitelist(tutorId, studentIdModel)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::handleAddUser,this::showError)
|
.subscribe(this::handleAddUser,this::showError)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,32 +267,6 @@ public class WhiteList extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
disposable.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
getMenuInflater().inflate(R.menu.menu_white_list, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
@ -343,4 +315,31 @@ public class WhiteList extends AppCompatActivity {
|
|||||||
},this::showError)
|
},this::showError)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
disposable.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.menu_white_list, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,6 @@ public class WrapContentLinearLayoutManager extends LinearLayoutManager {
|
|||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
|
|
||||||
super(context, orientation, reverseLayout);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||||
try {
|
try {
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
android:defaultValue="0"
|
android:defaultValue="0"
|
||||||
android:key="key_manual_location_value"
|
android:key="key_manual_location_value"
|
||||||
android:summary="%s"
|
android:summary="%s"
|
||||||
|
android:entries="@array/manual_location_entries"
|
||||||
|
android:entryValues="@array/manual_location_values"
|
||||||
android:title="@string/title_list_manual_location" />
|
android:title="@string/title_list_manual_location" />
|
||||||
<com.uam.wmi.findmytutor.utils.RightButtonPreference
|
<com.uam.wmi.findmytutor.utils.RightButtonPreference
|
||||||
android:key="manual_location_button"
|
android:key="manual_location_button"
|
||||||
@ -47,9 +49,11 @@
|
|||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:title="@string/status_switch_title"/>
|
android:title="@string/status_switch_title"/>
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="2"
|
android:defaultValue="0"
|
||||||
android:key="@string/key_status_value"
|
android:key="@string/key_status_value"
|
||||||
android:summary="%s"
|
android:summary="%s"
|
||||||
|
android:entries="@array/status_entries"
|
||||||
|
android:entryValues="@array/status_values"
|
||||||
android:title="@string/status_list_title" />
|
android:title="@string/status_list_title" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="key_manual_status"
|
android:key="key_manual_status"
|
||||||
|
@ -55,26 +55,17 @@
|
|||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="status_entries">
|
<string-array name="status_entries">
|
||||||
<item>@string/description_available</item>
|
<item>@string/description_available</item>
|
||||||
<item>@string/description_busy</item>
|
|
||||||
<item>@string/description_consultation</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="status_values">
|
<string-array name="status_values">
|
||||||
<item>0</item>
|
<item>0</item>
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="manual_location_entries">
|
<string-array name="manual_location_entries">
|
||||||
<item>@string/assembly_c</item>
|
<item>@string/assembly_c</item>
|
||||||
<item>@string/assembly_a</item>
|
|
||||||
<item>@string/passage_d</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="manual_location_values">
|
<string-array name="manual_location_values">
|
||||||
<item>0</item>
|
<item>0</item>
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="language_entries">
|
<string-array name="language_entries">
|
||||||
|
|
||||||
<item>@string/lang_eng</item>
|
<item>@string/lang_eng</item>
|
||||||
<item>@string/lang_pol</item>
|
<item>@string/lang_pol</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
Loading…
Reference in New Issue
Block a user