From 4fceb4195f5b411d261639666a06086e6df5ebb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Thu, 3 Jan 2019 23:41:24 +0100 Subject: [PATCH] Fix blacklists --- .../uam/wmi/findmytutor/activity/BlackList.java | 13 +++++++++---- .../uam/wmi/findmytutor/activity/WhiteList.java | 14 ++++++++++---- .../uam/wmi/findmytutor/service/UserService.java | 4 ++-- app/src/main/res/layout/black_list_row.xml | 15 ++------------- app/src/main/res/layout/white_list_row.xml | 13 ------------- 5 files changed, 23 insertions(+), 36 deletions(-) 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 bc4fbca..766bf8b 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 @@ -229,13 +229,18 @@ public class BlackList extends AppCompatActivity { userService.addStudentToBlacklist(PrefUtils.getUserId(getApplicationContext()), studentIdModel) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(()->{ - fetchBlackListedUsersIDs(PrefUtils.getUserId(getApplicationContext())); - Toast.makeText(getApplicationContext(), R.string.user_added, Toast.LENGTH_SHORT).show(); - },this::showError) + .subscribe(this::handleAddUser,this::showError) ); } + + private void handleAddUser(User user) { + blacklistedUsersIDs.clear(); + blacklistedUsers.clear(); + blacklistedUsersIDs.addAll(user.getBlacklist()); + fetchBlackListedUsers(); + } + private void showError(Throwable e) { String message; 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 a51793b..d251307 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 @@ -12,6 +12,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.text.TextUtils; +import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -156,6 +157,7 @@ public class WhiteList extends AppCompatActivity { public void onSuccess(User user) { whitelistedUsers.add(user); toggleEmptyNotes(); + if (whitelistedUsers.size() == whitelistedUsersIDs.size()) { mAdapter.notifyDataSetChanged(); } @@ -216,13 +218,17 @@ public class WhiteList extends AppCompatActivity { userService.addStudentToWhitelist(PrefUtils.getUserId(getApplicationContext()), studentIdModel) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(()->{ - fetchWhiteListedUsersIDs(PrefUtils.getUserId(getApplicationContext())); - Toast.makeText(getApplicationContext(), R.string.user_added, Toast.LENGTH_SHORT).show(); - },this::showError) + .subscribe(this::handleAddUser,this::showError) ); } + private void handleAddUser(User user) { + whitelistedUsersIDs.clear(); + whitelistedUsers.clear(); + whitelistedUsersIDs.addAll(user.getWhitelist()); + fetchWhiteListedUsers(); + } + private void showError(Throwable e) { String message; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java index 9bad144..6fb51d6 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/UserService.java @@ -81,7 +81,7 @@ public interface UserService { Completable setTutorBlacklist(@Path("tutorID") String tutorID, @Body IsUsingListBool isUsing); @POST("api/users/blacklist/{tutorID}") - Completable addStudentToBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student); + Observable addStudentToBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student); // @DELETE("api/users/blacklist/{tutorID}") @HTTP(method = "DELETE", path = "api/users/blacklist/{tutorID}", hasBody = true) @@ -94,7 +94,7 @@ public interface UserService { Completable setTutorWhitelist(@Path("tutorID") String tutorID, @Body IsUsingListBool isUsing); @POST("api/users/whitelist/{tutorID}") - Completable addStudentToWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student); + Observable addStudentToWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student); // @DELETE("api/users/whitelist/{tutorID}") @HTTP(method = "DELETE", path = "api/users/whitelist/{tutorID}", hasBody = true) diff --git a/app/src/main/res/layout/black_list_row.xml b/app/src/main/res/layout/black_list_row.xml index d2efd45..ded676c 100644 --- a/app/src/main/res/layout/black_list_row.xml +++ b/app/src/main/res/layout/black_list_row.xml @@ -33,19 +33,7 @@ android:layout_marginEnd="0dp" android:textColor="@color/note_list_text" android:textSize="15sp" /> - - - - - - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/white_list_row.xml b/app/src/main/res/layout/white_list_row.xml index 45655db..35dad88 100644 --- a/app/src/main/res/layout/white_list_row.xml +++ b/app/src/main/res/layout/white_list_row.xml @@ -34,19 +34,6 @@ android:textColor="@color/note_list_text" android:textSize="15sp" /> - - - - - - - - - - - - -