diff --git a/app/build.gradle b/app/build.gradle index 9f7f82f..c399fb1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { applicationId "com.uam.wmi.findmytutor" minSdkVersion 22 targetSdkVersion 27 - versionCode 35 + versionCode 36 versionName "0.9.6-beta" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java index b327a86..ce91562 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BlackList.java @@ -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); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index e742a29..4e90226 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -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 locationMap; + private ArrayList locationUUIDs; protected List predefinedCoordsList = new ArrayList<>(); - private HashMap locationMap; - private ArrayList locationUUIDs; private HashMap locationLevelMapping; private HashMap statusMapping; private PredefinedStatusesService statusesService; @@ -68,9 +70,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere private AlertDialog.Builder builder; private String[] statusesArray; private boolean statusSwitchFlag; - private ArrayList predefinedLocationsList; + private ArrayList predefinedLocationsList; - public static SharingFragment newInstance() { + public static SharingFragment newInstance() { return new SharingFragment(); } @@ -82,12 +84,12 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere .subscribeWith(new DisposableSingleObserver>() { @Override public void onSuccess(List strings) { - statusesArray = strings.toArray(new String[strings.size()]); - if (strings.isEmpty()) { - disableStatusPreferences(); - } else { - enableStatusPreferences(); - } + statusesArray = strings.toArray(new String[strings.size()]); + if(strings.isEmpty()){ + disableStatusPreferences(); + }else{ + enableStatusPreferences(); + } // Log.d("STATUSES",Integer.toString(statusesArray.length )); setListPreferenceData(statusList, statusesArray, null); } @@ -110,46 +112,45 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere public void onSuccess(List coords) { String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext()); - locationMap = new HashMap(); - locationUUIDs = new ArrayList(); - for (PredefinedCoordViewModel i : coords) - locationMap.put(i.getPredefinedCoordinateId(), i.getName()); - for (PredefinedCoordViewModel i : coords) - locationUUIDs.add(i.getPredefinedCoordinateId()); - List predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList(); - List predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList(); + locationMap = new HashMap(); + locationUUIDs = new ArrayList(); + for (PredefinedCoordViewModel i : coords) locationMap.put(i.getPredefinedCoordinateId(),i.getName()); + for (PredefinedCoordViewModel i : coords) locationUUIDs.add(i.getPredefinedCoordinateId()); + List predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList(); + List predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList(); predefinedCoordsList.addAll(coords); String[] stringnames = predefinedLocationsNames.toArray(new String[0]); - predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames)); - if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) { - preferenceCategory.removePreference(manualLocationList); - preferenceCategory.removePreference(removeManualLocation); - preferenceCategory.removePreference(manualLocationButton); - } else { - if (predefinedCoordsList.isEmpty()) { - locationSharing.setEnabled(false); - locationSharing.setChecked(false); - PrefUtils.disableSharing(getApplicationContext()); - ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle(); - removeManualLocation.setEnabled(false); - manualLocationList.setEnabled(false); - manualLocationList.setSummary(""); - } else { - manualLocationList.setEnabled(true); - manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext())); - removeManualLocation.setEnabled(true); - locationSharing.setEnabled(true); + predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames)); + if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) { + preferenceCategory.removePreference(manualLocationList); + preferenceCategory.removePreference(removeManualLocation); + preferenceCategory.removePreference(manualLocationButton); + }else{ + if(predefinedCoordsList.isEmpty()){ + locationSharing.setEnabled(false); + locationSharing.setChecked(false); + PrefUtils.disableSharing(getApplicationContext()); + ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle(); + removeManualLocation.setEnabled(false); + manualLocationList.setEnabled(false); + manualLocationList.setSummary(""); + }else{ + manualLocationList.setEnabled(true); + manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext())); + removeManualLocation.setEnabled(true); + locationSharing.setEnabled(true); - } - } + } + } List 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)); } @@ -179,11 +180,11 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere removeManualStatus = (RightButtonPreference) findPreference("remove_manual_status"); manualStatus = findPreference("key_manual_status"); statusList = (ListPreference) findPreference("key_status_value"); - statusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class); - locationService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class); + statusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class); + locationService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class); disposable = new CompositeDisposable(); statusesArray = new String[0]; - predefinedLocationsList = new ArrayList(); + predefinedLocationsList = new ArrayList(); getStatuses(disposable); getLocations(disposable); locationLevelMapping = new HashMap(); @@ -215,21 +216,21 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue))); if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) { if (!predefinedCoordsList.isEmpty()) { - preferenceCategory.addPreference(manualLocationList); - preferenceCategory.addPreference(removeManualLocation); - } else { - locationSharing.setEnabled(false); - locationSharing.setChecked(false); - PrefUtils.disableSharing(getApplicationContext()); - ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle(); + preferenceCategory.addPreference(manualLocationList); + preferenceCategory.addPreference(removeManualLocation); + }else{ + locationSharing.setEnabled(false); + locationSharing.setChecked(false); + PrefUtils.disableSharing(getApplicationContext()); + ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle(); } preferenceCategory.addPreference(manualLocationButton); } else { - locationSharing.setEnabled(true); + locationSharing.setEnabled(true); preferenceCategory.removePreference(manualLocationList); preferenceCategory.removePreference(manualLocationButton); - preferenceCategory.removePreference(removeManualLocation); + preferenceCategory.removePreference(removeManualLocation); } return true; }); @@ -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(); @@ -269,7 +269,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere return true; }); statusSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - return true; + return true; }); /** Status list change listener **/ statusList.setOnPreferenceChangeListener((preference, newValue) -> { @@ -290,39 +290,38 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere return true; }); - removeManualStatus.setOnPreferenceChangeListener((preference, newValue) -> { - showRemoveDialog(statusList.getEntries(), "status"); - return true; - }); - removeManualLocation.setOnPreferenceChangeListener(((preference, newValue) -> { - showRemoveDialog(manualLocationList.getEntries(), "location"); - return true; + removeManualStatus.setOnPreferenceChangeListener((preference, newValue) -> { + showRemoveDialog(statusList.getEntries(),"status"); + return true; + }); + removeManualLocation.setOnPreferenceChangeListener(((preference, newValue) -> { + 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 tobeDeleted = new ArrayList(); // 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) { - tobeDeleted.add((String) entries[i]); - } - } - removeEntries(service, tobeDeleted); + 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) { + tobeDeleted.add((String) entries[i]); + } + } + removeEntries(service,tobeDeleted); // Log.d("MANAGE-PREF",tobeDeleted.toString()); - } - }); - builder.setMultiChoiceItems(entries, checked, new DialogInterface.OnMultiChoiceClickListener() { - @Override - public void onClick(DialogInterface dialog, int which, boolean isChecked) { + } + }); + builder.setMultiChoiceItems(entries, checked, new DialogInterface.OnMultiChoiceClickListener() { + @Override + public void onClick(DialogInterface dialog, int which, boolean isChecked) { - } - }); + } + }); builder.create().show(); } @@ -334,34 +333,34 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere return view; } - protected void removeEntries(String service, ArrayList toBeDeleted) { + protected void removeEntries(String service, ArrayList toBeDeleted){ // Log.d("MANAGE-PREF", toBeDeleted.toString()); - 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 { - ArrayList uuidsToBeDeleted = new ArrayList(); - for (String name : toBeDeleted) { - for (String uuid : locationUUIDs) { - if (locationMap.get(uuid).equals(name)) { - uuidsToBeDeleted.add(uuid); - } + 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 { + ArrayList uuidsToBeDeleted = new ArrayList(); + for (String name:toBeDeleted) { + for (String uuid:locationUUIDs) { + if(locationMap.get(uuid).equals(name)){ + uuidsToBeDeleted.add(uuid); } - } - for (String uuid : uuidsToBeDeleted) { + } + } + for (String uuid : uuidsToBeDeleted) { // predefinedCoordsList.removeIf(x -> x.getPredefinedCoordinateId().equals(uuid)); - predefinedCoordsList.removeAll(Stream.of(predefinedCoordsList).filter(x -> x.getPredefinedCoordinateId().equals(uuid)).toList()); - disposable.add(locationService.deleteUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), uuid) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::handleDeleteLocations, this::handleError)); - } - } + predefinedCoordsList.removeAll(Stream.of(predefinedCoordsList).filter(x -> x.getPredefinedCoordinateId().equals(uuid)).toList()); + disposable.add(locationService.deleteUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), uuid) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::handleDeleteLocations, this::handleError)); + } + } } protected void setListPreferenceData(ListPreference lp, String[] entries, Integer activeId) { @@ -389,13 +388,13 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere ; private void handleResponse(List resp) { - if (resp.size() == 1) { - enableStatusPreferences(); - if (PrefUtils.isStatusEnabled(getApplicationContext()) == false) { - PrefUtils.enableStatus(getApplicationContext()); - statusSwitch.setChecked(true); - } - } + if(resp.size() == 1){ + enableStatusPreferences(); + if(PrefUtils.isStatusEnabled(getApplicationContext()) == false){ + PrefUtils.enableStatus(getApplicationContext()); + statusSwitch.setChecked(true); + } + } String[] statusesArray = resp.toArray(new String[resp.size()]); setListPreferenceData(statusList, statusesArray, resp.size() - 1); statusList.setValueIndex(resp.size() - 1); @@ -414,84 +413,79 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere "Network error " + error.getMessage(), Toast.LENGTH_SHORT).show(); } } + private void handleDeleteStatuses(List 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 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 handleDeleteLocations(List resp){ + getLocations(disposable); + String currentEntry = PrefUtils.getCurrentManualLocation(getApplicationContext()); + 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)){ + manualLocationList.setValueIndex(resp.indexOf(location)); + 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 resp) { - getLocations(disposable); - String currentEntry = PrefUtils.getCurrentManualLocation(getApplicationContext()); - 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)) { - manualLocationList.setValueIndex(resp.indexOf(location)); - break; - } - } - } else { - manualLocationList.setValueIndex(0); - manualLocationList.setSummary(resp.get(0).getName()); - //todo czy na pewno w shared pref sa dobre wartosci - } + } + 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())); } - } - - 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 public void onResume() { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java index 1809924..575ff5d 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java @@ -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){ diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/RightButtonPreference.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/RightButtonPreference.java index 6a8b281..3814e03 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/RightButtonPreference.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/RightButtonPreference.java @@ -11,20 +11,16 @@ import com.uam.wmi.findmytutor.R; public class RightButtonPreference extends Preference { - private Button prefButton; private String buttonText; public RightButtonPreference(Context context, AttributeSet attrs) { super(context, attrs); - setWidgetLayoutResource(R.layout.preference_button_widget); + setWidgetLayoutResource(R.layout.preference_button_widget); for (int i=0;i - -