Fix networks issues
This commit is contained in:
parent
9525d47600
commit
e4b0bb1f3d
@ -98,6 +98,7 @@ public class BlackList extends AppCompatActivity {
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
setContentView(R.layout.activity_black_list);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
tutorId = PrefUtils.getUserId(getApplicationContext());
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
@ -31,6 +31,8 @@ import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.RightButtonPreference;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
|
||||
import org.apache.commons.collections4.BidiMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -57,9 +59,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
protected RightButtonPreference removeManualStatus;
|
||||
protected Preference manualStatus;
|
||||
protected ListPreference statusList;
|
||||
private HashMap<String,String> locationMap;
|
||||
private ArrayList <String> locationUUIDs;
|
||||
protected List<PredefinedCoordViewModel> predefinedCoordsList = new ArrayList<>();
|
||||
private HashMap<String, String> locationMap;
|
||||
private ArrayList<String> locationUUIDs;
|
||||
private HashMap<Integer, String> locationLevelMapping;
|
||||
private HashMap<Integer, String> statusMapping;
|
||||
private PredefinedStatusesService statusesService;
|
||||
@ -83,9 +85,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
@Override
|
||||
public void onSuccess(List<String> strings) {
|
||||
statusesArray = strings.toArray(new String[strings.size()]);
|
||||
if (strings.isEmpty()) {
|
||||
if(strings.isEmpty()){
|
||||
disableStatusPreferences();
|
||||
} else {
|
||||
}else{
|
||||
enableStatusPreferences();
|
||||
}
|
||||
// Log.d("STATUSES",Integer.toString(statusesArray.length ));
|
||||
@ -110,12 +112,10 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
public void onSuccess(List<PredefinedCoordViewModel> coords) {
|
||||
|
||||
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||
locationMap = new HashMap<String, String>();
|
||||
locationMap = new HashMap<String,String>();
|
||||
locationUUIDs = new ArrayList<String>();
|
||||
for (PredefinedCoordViewModel i : coords)
|
||||
locationMap.put(i.getPredefinedCoordinateId(), i.getName());
|
||||
for (PredefinedCoordViewModel i : coords)
|
||||
locationUUIDs.add(i.getPredefinedCoordinateId());
|
||||
for (PredefinedCoordViewModel i : coords) locationMap.put(i.getPredefinedCoordinateId(),i.getName());
|
||||
for (PredefinedCoordViewModel i : coords) 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);
|
||||
@ -126,8 +126,8 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
preferenceCategory.removePreference(manualLocationList);
|
||||
preferenceCategory.removePreference(removeManualLocation);
|
||||
preferenceCategory.removePreference(manualLocationButton);
|
||||
} else {
|
||||
if (predefinedCoordsList.isEmpty()) {
|
||||
}else{
|
||||
if(predefinedCoordsList.isEmpty()){
|
||||
locationSharing.setEnabled(false);
|
||||
locationSharing.setChecked(false);
|
||||
PrefUtils.disableSharing(getApplicationContext());
|
||||
@ -135,7 +135,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
removeManualLocation.setEnabled(false);
|
||||
manualLocationList.setEnabled(false);
|
||||
manualLocationList.setSummary("");
|
||||
} else {
|
||||
}else{
|
||||
manualLocationList.setEnabled(true);
|
||||
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
||||
removeManualLocation.setEnabled(true);
|
||||
@ -147,9 +147,10 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
List<Integer> activesId = Stream.of(coords).indexed()
|
||||
.filter(v -> v.getSecond().getPredefinedCoordinateId().equals(currentCoordId)).map(IntPair::getFirst).toList();
|
||||
|
||||
if (activesId.size() == 0) {
|
||||
if( activesId.size() == 0){
|
||||
setListPreferenceData(manualLocationList, stringnames, null);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
setListPreferenceData(manualLocationList, stringnames, activesId.get(0));
|
||||
}
|
||||
|
||||
@ -217,7 +218,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
if (!predefinedCoordsList.isEmpty()) {
|
||||
preferenceCategory.addPreference(manualLocationList);
|
||||
preferenceCategory.addPreference(removeManualLocation);
|
||||
} else {
|
||||
}else{
|
||||
locationSharing.setEnabled(false);
|
||||
locationSharing.setChecked(false);
|
||||
PrefUtils.disableSharing(getApplicationContext());
|
||||
@ -239,8 +240,6 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
|
||||
/** Custom manual location list change listener **/
|
||||
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
||||
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
CharSequence[] entries = lp.getEntries();
|
||||
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
|
||||
@ -261,6 +260,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
});
|
||||
|
||||
|
||||
|
||||
/** Button 'choose from map' button listener **/
|
||||
manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
@ -291,29 +291,28 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
return true;
|
||||
});
|
||||
removeManualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
showRemoveDialog(statusList.getEntries(), "status");
|
||||
showRemoveDialog(statusList.getEntries(),"status");
|
||||
return true;
|
||||
});
|
||||
removeManualLocation.setOnPreferenceChangeListener(((preference, newValue) -> {
|
||||
showRemoveDialog(manualLocationList.getEntries(), "location");
|
||||
showRemoveDialog(manualLocationList.getEntries(),"location");
|
||||
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>();
|
||||
// Log.d("sharingDialog", "no to siup");
|
||||
builder.setPositiveButton("DELETE", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (checked[i] == true) {
|
||||
for (int i=0; i< entries.length; i++){
|
||||
if(checked[i] == true) {
|
||||
tobeDeleted.add((String) entries[i]);
|
||||
}
|
||||
}
|
||||
removeEntries(service, tobeDeleted);
|
||||
removeEntries(service,tobeDeleted);
|
||||
// Log.d("MANAGE-PREF",tobeDeleted.toString());
|
||||
}
|
||||
});
|
||||
@ -334,21 +333,21 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
return view;
|
||||
}
|
||||
|
||||
protected void removeEntries(String service, ArrayList<String> toBeDeleted) {
|
||||
protected void removeEntries(String service, ArrayList<String> toBeDeleted){
|
||||
|
||||
// Log.d("MANAGE-PREF", toBeDeleted.toString());
|
||||
if (service.equals("status")) {
|
||||
for (String uuid : toBeDeleted) {
|
||||
if(service.equals("status")){
|
||||
for (String uuid:toBeDeleted) {
|
||||
disposable.add(statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), uuid)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleDeleteStatuses, this::handleError));
|
||||
}
|
||||
} else {
|
||||
}else {
|
||||
ArrayList<String> uuidsToBeDeleted = new ArrayList<String>();
|
||||
for (String name : toBeDeleted) {
|
||||
for (String uuid : locationUUIDs) {
|
||||
if (locationMap.get(uuid).equals(name)) {
|
||||
for (String name:toBeDeleted) {
|
||||
for (String uuid:locationUUIDs) {
|
||||
if(locationMap.get(uuid).equals(name)){
|
||||
uuidsToBeDeleted.add(uuid);
|
||||
}
|
||||
}
|
||||
@ -389,9 +388,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
;
|
||||
|
||||
private void handleResponse(List<String> resp) {
|
||||
if (resp.size() == 1) {
|
||||
if(resp.size() == 1){
|
||||
enableStatusPreferences();
|
||||
if (PrefUtils.isStatusEnabled(getApplicationContext()) == false) {
|
||||
if(PrefUtils.isStatusEnabled(getApplicationContext()) == false){
|
||||
PrefUtils.enableStatus(getApplicationContext());
|
||||
statusSwitch.setChecked(true);
|
||||
}
|
||||
@ -414,38 +413,37 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeleteStatuses(List<String> resp) {
|
||||
if (resp.isEmpty()) {
|
||||
private void handleDeleteStatuses(List<String> resp){
|
||||
if(resp.isEmpty()){
|
||||
disableStatusPreferences();
|
||||
} else {
|
||||
}else{
|
||||
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||
setListPreferenceData(statusList, statusesArray, null);
|
||||
String currentEntry = PrefUtils.getUserStatus(getApplicationContext());
|
||||
if (resp.contains(currentEntry)) {
|
||||
if(resp.contains(currentEntry)){
|
||||
statusList.setValueIndex(resp.indexOf(currentEntry));
|
||||
} else {
|
||||
}else{
|
||||
statusList.setValueIndex(0);
|
||||
statusList.setSummary(resp.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleDeleteLocations(List<PredefinedCoordViewModel> resp) {
|
||||
private void handleDeleteLocations(List<PredefinedCoordViewModel> resp){
|
||||
getLocations(disposable);
|
||||
String currentEntry = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||
if (resp.isEmpty()) {
|
||||
if(resp.isEmpty()){
|
||||
disableManualLocationPreferences();
|
||||
} else {
|
||||
if (!Stream.of(resp).filter(x -> x.getName().equals(currentEntry)).toList().isEmpty()) {
|
||||
for (PredefinedCoordViewModel location : resp) {
|
||||
if (location.getName().equals(currentEntry)) {
|
||||
}else{
|
||||
if(!Stream.of(resp).filter(x -> x.getName().equals(currentEntry)).toList().isEmpty())
|
||||
{
|
||||
for (PredefinedCoordViewModel location: resp) {
|
||||
if(location.getName().equals(currentEntry)){
|
||||
manualLocationList.setValueIndex(resp.indexOf(location));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
manualLocationList.setValueIndex(0);
|
||||
manualLocationList.setSummary(resp.get(0).getName());
|
||||
//todo czy na pewno w shared pref sa dobre wartosci
|
||||
@ -453,8 +451,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void disableStatusPreferences() {
|
||||
private void disableStatusPreferences(){
|
||||
removeManualStatus.setEnabled(false);
|
||||
statusList.setEnabled(false);
|
||||
statusSwitch.setEnabled(false);
|
||||
@ -462,15 +459,13 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
PrefUtils.disableStatus(getApplicationContext());
|
||||
|
||||
}
|
||||
|
||||
private void enableStatusPreferences() {
|
||||
private void enableStatusPreferences(){
|
||||
removeManualStatus.setEnabled(true);
|
||||
statusList.setEnabled(true);
|
||||
statusSwitch.setEnabled(true);
|
||||
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
||||
}
|
||||
|
||||
private void disableManualLocationPreferences() {
|
||||
private void disableManualLocationPreferences(){
|
||||
removeManualLocation.setEnabled(false);
|
||||
manualLocationList.setEnabled(false);
|
||||
manualLocationList.setSummary("");
|
||||
@ -480,8 +475,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||
|
||||
}
|
||||
|
||||
private void enableManualLocationPreferences() {
|
||||
private void enableManualLocationPreferences(){
|
||||
removeManualLocation.setEnabled(true);
|
||||
manualLocationList.setEnabled(true);
|
||||
|
||||
|
@ -29,6 +29,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableCompletableObserver;
|
||||
@ -61,9 +62,10 @@ public class TutorTab extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
setContentView(R.layout.content_tutor_tab);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
userName = findViewById(R.id.userName);
|
||||
userNote = (TextInputEditText) findViewById(R.id.userNote);
|
||||
@ -149,7 +151,6 @@ public class TutorTab extends AppCompatActivity {
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
private void addEmptyDuty(DutyHoursAdapter adapter){
|
||||
|
@ -11,7 +11,6 @@ import com.uam.wmi.findmytutor.R;
|
||||
|
||||
public class RightButtonPreference extends Preference {
|
||||
|
||||
|
||||
private Button prefButton;
|
||||
private String buttonText;
|
||||
|
||||
@ -22,9 +21,6 @@ public class RightButtonPreference extends Preference {
|
||||
String attr = attrs.getAttributeName(i);
|
||||
String val = attrs.getAttributeValue(i);
|
||||
if (attr.equalsIgnoreCase("text")) {
|
||||
// buttonText = val;
|
||||
Log.d("RightButtonPreference", "step = " + val);
|
||||
|
||||
buttonText = context.getResources().getString(Integer.parseInt(val.substring(1)));
|
||||
}
|
||||
}
|
||||
@ -35,24 +31,19 @@ public class RightButtonPreference extends Preference {
|
||||
}
|
||||
@Override
|
||||
protected View onCreateView(ViewGroup parent) {
|
||||
View view = super.onCreateView(parent);
|
||||
|
||||
return view;
|
||||
return super.onCreateView(parent);
|
||||
}
|
||||
@Override
|
||||
protected void onBindView(View view)
|
||||
{
|
||||
super.onBindView(view);
|
||||
prefButton = (Button) view.findViewById(R.id.button_choose_from_map);
|
||||
prefButton = view.findViewById(R.id.button_choose_from_map);
|
||||
prefButton.setText(buttonText);
|
||||
if(prefButton != null)
|
||||
{
|
||||
prefButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
prefButton.setOnClickListener(view1 -> {
|
||||
callChangeListener(null);
|
||||
notifyChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -16,7 +16,7 @@
|
||||
android:persistent="true"
|
||||
android:title="@string/title_sharing"/>
|
||||
<ListPreference
|
||||
android:defaultValue="1"
|
||||
android:defaultValue="2"
|
||||
android:dialogTitle="@string/settings_location_level"
|
||||
android:entries="@array/location_level_entries"
|
||||
android:entryValues="@array/location_level_values"
|
||||
@ -33,7 +33,6 @@
|
||||
<com.uam.wmi.findmytutor.utils.RightButtonPreference
|
||||
android:key="manual_location_button"
|
||||
android:text="@string/preference_manual_location_button"
|
||||
|
||||
/>
|
||||
<com.uam.wmi.findmytutor.utils.RightButtonPreference
|
||||
android:key="remove_manual_location"
|
||||
|
Loading…
Reference in New Issue
Block a user