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> </value>
</option> </option>
</component> </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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -162,10 +162,10 @@ public class BlackList extends AppCompatActivity {
private void fetchBlackListedUsers() { private void fetchBlackListedUsers() {
prevSize = blacklistedUsers.size(); prevSize = blacklistedUsers.size();
blacklistedUsers.clear(); blacklistedUsers.clear();
disposable.add(getListOfBlacklistedUsers(tutorId) disposable.add(getListOfBlacklistedUsers(tutorId)
.doOnSubscribe(t -> didFetched = false)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable) .flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable)
@ -179,11 +179,13 @@ public class BlackList extends AppCompatActivity {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
showError(e); showError(e);
didFetched = false;
} }
@Override @Override
public void onComplete() { public void onComplete() {
Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b)); Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b));
didFetched = true;
refreshUI(); 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> predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList();
List<String> predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList(); List<String> predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList();
predefinedCoordsList.addAll(coords); 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]); String[] stringnames = predefinedLocationsNames.toArray(new String[0]);
predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames)); predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames));
List<Integer> activesId = Stream.of(coords).indexed() List<Integer> activesId = Stream.of(coords).indexed()
@ -180,26 +199,7 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
statusMapping.put(0, "available"); statusMapping.put(0, "available");
statusMapping.put(1, "consultation"); statusMapping.put(1, "consultation");
statusMapping.put(2, "busy"); 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())); statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext())); manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
@ -215,8 +215,8 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
/** Sharing level list **/ /** Sharing level list **/
locationMode.setOnPreferenceChangeListener((preference, newValue) -> { 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 (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
if (!predefinedCoordsList.isEmpty()) { if (!predefinedCoordsList.isEmpty()) {
preferenceCategory.addPreference(manualLocationList); preferenceCategory.addPreference(manualLocationList);

View File

@ -44,7 +44,6 @@ import com.uam.wmi.findmytutor.utils.WrapContentLinearLayoutManager;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -61,11 +60,6 @@ import okhttp3.ResponseBody;
public class WhiteList extends AppCompatActivity { 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) @BindView(R.id.recycler_view_whitelist)
RecyclerView recyclerView; RecyclerView recyclerView;
@BindView(R.id.white_list_empty_text_view) @BindView(R.id.white_list_empty_text_view)
@ -74,7 +68,10 @@ 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 CompositeDisposable disposable = new CompositeDisposable();
private UserService userService;
private boolean didFetched = false;
private String tutorId;
private WhiteListAdapter mAdapter; private WhiteListAdapter mAdapter;
private Integer prevSize; private Integer prevSize;
private List<User> whitelistedUsers = new ArrayList<>(); private List<User> whitelistedUsers = new ArrayList<>();
@ -151,6 +148,7 @@ public class WhiteList extends AppCompatActivity {
whitelistedUsers.clear(); whitelistedUsers.clear();
disposable.add(getListOfWhitelistedUsers(tutorId) disposable.add(getListOfWhitelistedUsers(tutorId)
.doOnSubscribe(t -> didFetched = false)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable) .flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable)
@ -164,11 +162,13 @@ public class WhiteList extends AppCompatActivity {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
showError(e); showError(e);
didFetched = false;
} }
@Override @Override
public void onComplete() { public void onComplete() {
Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a, b)); Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a, b));
didFetched = true;
refreshUI(); refreshUI();
} }
})); }));
@ -256,6 +256,7 @@ public class WhiteList extends AppCompatActivity {
} }
private void toggleEmptyNotes() { private void toggleEmptyNotes() {
if (didFetched && whitelistedUsers.size() == 0) { if (didFetched && whitelistedUsers.size() == 0) {
noNotesView.setText(R.string.list_is_empty); noNotesView.setText(R.string.list_is_empty);
noNotesView.setVisibility(View.VISIBLE); noNotesView.setVisibility(View.VISIBLE);