Fix blacklists

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-06 23:45:47 +01:00
commit 4bb9452cbc
4 changed files with 78 additions and 75 deletions

View File

@ -29,7 +29,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -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<List<String>, Observable<String>>) 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();
}
}));

View File

@ -123,7 +123,26 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
List<String> predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList();
List<String> 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<Integer> 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()));
@ -215,8 +215,8 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
/** Sharing level list **/
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
if (!predefinedCoordsList.isEmpty()) {
preferenceCategory.addPreference(manualLocationList);

View File

@ -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<User> 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);
}
@ -151,6 +148,7 @@ public class WhiteList extends AppCompatActivity {
whitelistedUsers.clear();
disposable.add(getListOfWhitelistedUsers(tutorId)
.doOnSubscribe(t -> didFetched = false)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable)
@ -164,17 +162,19 @@ public class WhiteList extends AppCompatActivity {
@Override
public void onError(Throwable e) {
showError(e);
didFetched = false;
}
@Override
public void onComplete() {
Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a,b));
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)
.subscribe(() -> {
}, this::showError)
);
}