diff --git a/.idea/misc.xml b/.idea/misc.xml index dc44dda..b0c7b20 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + 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 ce91562..ddaa7b1 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 @@ -162,10 +162,10 @@ public class BlackList extends AppCompatActivity { private void fetchBlackListedUsers() { prevSize = blacklistedUsers.size(); - blacklistedUsers.clear(); disposable.add(getListOfBlacklistedUsers(tutorId) + .doOnSubscribe(t -> didFetched = false) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .flatMap((Function, Observable>) Observable::fromIterable) @@ -179,11 +179,13 @@ public class BlackList extends AppCompatActivity { @Override public void onError(Throwable e) { showError(e); + didFetched = false; } @Override public void onComplete() { Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b)); + didFetched = true; refreshUI(); } })); 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 5c161d5..51b809e 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 @@ -123,7 +123,26 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere List predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList(); List predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList(); predefinedCoordsList.addAll(coords); - + 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); + } + } String[] stringnames = predefinedLocationsNames.toArray(new String[0]); predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames)); List activesId = Stream.of(coords).indexed() @@ -180,26 +199,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere statusMapping.put(0, "available"); statusMapping.put(1, "consultation"); statusMapping.put(2, "busy"); - 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); - } - } + statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext())); manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext())); @@ -214,9 +214,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere /** Sharing level list **/ locationMode.setOnPreferenceChangeListener((preference, newValue) -> { - ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle(); + ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle(); + 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 (!predefinedCoordsList.isEmpty()) { preferenceCategory.addPreference(manualLocationList); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java index aad7e70..c767af3 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/WhiteList.java @@ -44,7 +44,6 @@ import com.uam.wmi.findmytutor.utils.WrapContentLinearLayoutManager; import java.text.Collator; import java.util.ArrayList; import java.util.Collections; - import java.util.List; import java.util.Locale; @@ -61,11 +60,6 @@ import okhttp3.ResponseBody; public class WhiteList extends AppCompatActivity { - private CompositeDisposable disposable = new CompositeDisposable(); - private UserService userService; - private boolean didFetched = false; - private String tutorId; - @BindView(R.id.recycler_view_whitelist) RecyclerView recyclerView; @BindView(R.id.white_list_empty_text_view) @@ -74,7 +68,10 @@ public class WhiteList extends AppCompatActivity { Switch aSwitch; @BindView(R.id.add_to_white_list_fab) FloatingActionButton addToWhiteListFab; - + private CompositeDisposable disposable = new CompositeDisposable(); + private UserService userService; + private boolean didFetched = false; + private String tutorId; private WhiteListAdapter mAdapter; private Integer prevSize; private List whitelistedUsers = new ArrayList<>(); @@ -90,12 +87,12 @@ public class WhiteList extends AppCompatActivity { userService = ApiClient.getClient(getApplicationContext()) .create(UserService.class); - if (PrefUtils.isWhiteListing(this)){ - aSwitch.setText(getString(R.string.action_white_list) +" ON"); + if (PrefUtils.isWhiteListing(this)) { + aSwitch.setText(getString(R.string.action_white_list) + " ON"); aSwitch.setChecked(true); handleChangeRequest(true); - }else{ - aSwitch.setText(getString(R.string.action_white_list) +" OFF"); + } else { + aSwitch.setText(getString(R.string.action_white_list) + " OFF"); aSwitch.setChecked(false); handleChangeRequest(false); } @@ -132,7 +129,7 @@ public class WhiteList extends AppCompatActivity { } private Observable> getListOfWhitelistedUsers(String userId) { - return userService.getTutorWhitelistedByID(userId) + return userService.getTutorWhitelistedByID(userId) .toObservable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); @@ -151,30 +148,33 @@ public class WhiteList extends AppCompatActivity { whitelistedUsers.clear(); disposable.add(getListOfWhitelistedUsers(tutorId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .flatMap((Function, Observable>) Observable::fromIterable) - .flatMap((Function>) this::getUserObservable) - .subscribeWith(new DisposableObserver() { - @Override - public void onNext(User user) { - whitelistedUsers.add(user); - } + .doOnSubscribe(t -> didFetched = false) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .flatMap((Function, Observable>) Observable::fromIterable) + .flatMap((Function>) this::getUserObservable) + .subscribeWith(new DisposableObserver() { + @Override + public void onNext(User user) { + whitelistedUsers.add(user); + } - @Override - public void onError(Throwable e) { - showError(e); - } + @Override + public void onError(Throwable e) { + showError(e); + didFetched = false; + } - @Override - public void onComplete() { - Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a,b)); - refreshUI(); - } - })); + @Override + public void onComplete() { + Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a, b)); + didFetched = true; + refreshUI(); + } + })); } - private void refreshUI(){ + private void refreshUI() { toggleEmptyNotes(); mAdapter.notifyItemRangeInserted(prevSize, whitelistedUsers.size() - prevSize); mAdapter.notifyDataSetChanged(); @@ -184,7 +184,7 @@ public class WhiteList extends AppCompatActivity { return plCollator.compare(t1.getLastName(), t2.getLastName()); } - private void showFabDialog(View v){ + private void showFabDialog(View v) { LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); @SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.white_list_fab_modal, null); AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); @@ -230,7 +230,7 @@ public class WhiteList extends AppCompatActivity { userService.addStudentToWhitelist(tutorId, studentIdModel) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::handleAddUser,this::showError) + .subscribe(this::handleAddUser, this::showError) ); } @@ -251,15 +251,16 @@ public class WhiteList extends AppCompatActivity { } else { message = "Network Error !"; } - Log.e("ERR",message); + Log.e("ERR", message); Toast.makeText(this, message, Snackbar.LENGTH_LONG).show(); } private void toggleEmptyNotes() { + if (didFetched && whitelistedUsers.size() == 0) { noNotesView.setText(R.string.list_is_empty); noNotesView.setVisibility(View.VISIBLE); - }else if (whitelistedUsers.size() > 0) { + } else if (whitelistedUsers.size() > 0) { noNotesView.setVisibility(View.GONE); } else { noNotesView.setText(getString(R.string.loading)); @@ -271,10 +272,10 @@ public class WhiteList extends AppCompatActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId()==R.id.action_whitelist_info_popup){ + if (item.getItemId() == R.id.action_whitelist_info_popup) { int layoutID = R.layout.info_popup_whitelist; - View popupView = getLayoutInflater().inflate(layoutID,null); + View popupView = getLayoutInflater().inflate(layoutID, null); PopupWindow popupWindow = new PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); @@ -283,36 +284,36 @@ public class WhiteList extends AppCompatActivity { // If you need the PopupWindow to dismiss when when touched outside popupWindow.setBackgroundDrawable(new ColorDrawable()); // Get the View's(the one that was clicked in the Fragment) location - View anchorView= getWindow().getDecorView().findViewById(android.R.id.content); - popupWindow.showAtLocation(anchorView,Gravity.TOP|Gravity.END, 0, 0); + View anchorView = getWindow().getDecorView().findViewById(android.R.id.content); + popupWindow.showAtLocation(anchorView, Gravity.TOP | Gravity.END, 0, 0); } return super.onOptionsItemSelected(item); } - private void handleSwitch(){ + private void handleSwitch() { aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - if (isChecked){ - aSwitch.setText(getString(R.string.action_white_list) + " "+ getString(R.string.on)); + if (isChecked) { + aSwitch.setText(getString(R.string.action_white_list) + " " + getString(R.string.on)); handleChangeRequest(true); PrefUtils.useWhitelist(this, true); - }else { - aSwitch.setText(getString(R.string.action_white_list) + " "+getString(R.string.off)); + } else { + aSwitch.setText(getString(R.string.action_white_list) + " " + getString(R.string.off)); handleChangeRequest(false); PrefUtils.useWhitelist(this, false); } }); } - private void handleChangeRequest(boolean value){ + private void handleChangeRequest(boolean value) { IsUsingListBool isUsingListBool = new IsUsingListBool(); isUsingListBool.setIsUsing(value); disposable.add( userService.setTutorWhitelist(tutorId, isUsingListBool) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(()->{ - },this::showError) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(() -> { + }, this::showError) ); }