diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index da2d313..d209b5a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -65,6 +65,11 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />
+
whitelistedUsers = new ArrayList<>();
+ private HashSet whitelistedUsersIDs = new HashSet<>();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ setContentView(R.layout.activity_white_list);
+ ButterKnife.bind(this);
+ tutorId = PrefUtils.getUserId(getApplicationContext());
+ userService = ApiClient.getClient(getApplicationContext())
+ .create(UserService.class);
+
+ 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");
+ aSwitch.setChecked(false);
+ handleChangeRequest(false);
+ }
+
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setTitle(getString(R.string.activity_title_whitelist));
+ setSupportActionBar(toolbar);
+
+ mAdapter = new WhiteListAdapter(this, whitelistedUsers);
+ RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
+ recyclerView.setLayoutManager(mLayoutManager);
+ recyclerView.setItemAnimator(new DefaultItemAnimator());
+ recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
+ recyclerView.setAdapter(mAdapter);
+
+ /**
+ * On long press on RecyclerView item, open alert dialog
+ * with options to choose
+ * Edit and Delete
+ * */
+ recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this,
+ recyclerView, new RecyclerTouchListener.ClickListener() {
+ @Override
+ public void onClick(View view, final int position) {
+ }
+
+ @Override
+ public void onLongClick(View view, int position) {
+ }
+ }));
+
+ addToWhiteListFab.setOnClickListener(this::showFabDialog);
+
+ fetchWhiteListedUsersIDs(PrefUtils.getUserId(getApplicationContext()));
+ handleSwitch();
+ }
+
+ private void fetchWhiteListedUsersIDs(String userId) {
+ disposable.add(
+ userService.getTutorWhitelistedByID(userId)
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribeWith(new DisposableSingleObserver>() {
+ @Override
+ public void onSuccess(List users) {
+ whitelistedUsersIDs.addAll(users);
+ didFetched = true;
+ fetchWhiteListedUsers();
+ toggleEmptyNotes();
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ showError(e);
+ }
+ })
+ );
+ }
+
+ private void fetchWhiteListedUsers() {
+ for (String GUID : whitelistedUsersIDs){
+ disposable.add(
+ userService.getUserById(GUID)
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribeWith(new DisposableSingleObserver() {
+ @Override
+ public void onSuccess(User user) {
+ whitelistedUsers.add(user);
+ Snackbar.make(getWindow().getDecorView().getRootView(), "user fetch OK! success", Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show();
+ toggleEmptyNotes();
+ if (whitelistedUsers.size() == whitelistedUsersIDs.size()) {
+ mAdapter.notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ showError(e);
+ }
+ })
+ );
+ }
+ }
+
+
+ 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);
+
+ alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null);
+
+ alertDialogBuilderUserInput
+ .setPositiveButton(R.string.add, null)
+ .setNegativeButton(R.string.cancel, null);
+
+ final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
+ alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+
+ EditText modalUserInput = view.findViewById(R.id.white_list_modal_input);
+
+ alertDialog.setOnShowListener(dialogInterface -> {
+ Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+
+ Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
+
+ dismissButton.setOnClickListener(view1 -> alertDialog.dismiss());
+
+ sendButton.setOnClickListener(view1 -> {
+ String body = modalUserInput.getText().toString();
+
+ if (TextUtils.isEmpty(body)) {
+ Toast.makeText(getApplicationContext(), R.string.can_not_be_empty, Toast.LENGTH_SHORT).show();
+ modalUserInput.requestFocus();
+ } else {
+ sendUserToWhitelist(body);
+ alertDialog.dismiss();
+ }
+ });
+ });
+
+ alertDialog.show();
+ }
+
+ private void sendUserToWhitelist(String body) {
+ StudentIdModel studentIdModel = new StudentIdModel(body);
+ disposable.add(
+ 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)
+ );
+ }
+
+ private void showError(Throwable e) {
+ String message;
+
+ if (e instanceof HttpException) {
+ ResponseBody responseBody = ((HttpException) e).response().errorBody();
+ message = RestApiHelper.getErrorMessage(responseBody);
+ } else {
+ message = "Network Error !";
+ }
+ Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
+
+
+ Snackbar.make(getWindow().getDecorView().getRootView(), message, Snackbar.LENGTH_LONG)
+ .setAction("Action", null).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) {
+ noNotesView.setVisibility(View.GONE);
+ } else {
+ noNotesView.setText(getString(R.string.loading));
+ noNotesView.setVisibility(View.VISIBLE);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ disposable.dispose();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_white_list, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ if (item.getItemId()==R.id.action_whitelist_info_popup){
+ int layoutID = R.layout.info_popup_whitelist;
+
+ View popupView = getLayoutInflater().inflate(layoutID,null);
+
+ PopupWindow popupWindow = new PopupWindow(popupView,
+ LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
+ // If the PopupWindow should be focusable
+ popupWindow.setFocusable(true);
+ // 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);
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void handleSwitch(){
+ aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ 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));
+ handleChangeRequest(false);
+ PrefUtils.useWhitelist(this, false);
+ }
+ });
+ }
+
+ 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)
+ );
+ }
+}
diff --git a/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java
new file mode 100644
index 0000000..45d2671
--- /dev/null
+++ b/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java
@@ -0,0 +1,132 @@
+package com.uam.wmi.findmytutor.adapters;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.support.annotation.NonNull;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageButton;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
+import com.uam.wmi.findmytutor.R;
+import com.uam.wmi.findmytutor.model.StudentIdModel;
+import com.uam.wmi.findmytutor.model.User;
+import com.uam.wmi.findmytutor.network.ApiClient;
+import com.uam.wmi.findmytutor.service.UserService;
+import com.uam.wmi.findmytutor.utils.PrefUtils;
+import com.uam.wmi.findmytutor.utils.RestApiHelper;
+
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.disposables.CompositeDisposable;
+import io.reactivex.schedulers.Schedulers;
+import okhttp3.ResponseBody;
+
+import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
+
+
+public class WhiteListAdapter extends RecyclerView.Adapter {
+
+ private Context context;
+ private List tutorsList;
+ private CompositeDisposable disposable = new CompositeDisposable();
+ private UserService userService;
+
+
+ public WhiteListAdapter(Context context, List tutors) {
+ this.context = context;
+ this.tutorsList = tutors;
+ }
+ @NonNull
+ @Override
+ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ userService = ApiClient.getClient(getApplicationContext())
+ .create(UserService.class);
+ View itemView = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.white_list_row, parent, false);
+
+ return new MyViewHolder(itemView);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
+ Drawable image = null;
+ User tutor = tutorsList.get(position);
+
+ holder.firstName.setText(tutor.getFirstName() + " " + tutor.getLastName());
+ holder.lastName.setText("Index: " + tutor.getLdapLogin() + " Email: " + tutor.getEmail());
+//"s416196"
+ holder.imageButton.setOnClickListener(l ->{
+ StudentIdModel studentIdModel = new StudentIdModel(tutor.getLdapLogin());
+ String tutorId = PrefUtils.getUserId(getApplicationContext());
+ disposable.add(
+ userService.removeStudentFromWhitelist(tutorId, studentIdModel)
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe(()->{
+ Toast.makeText(getApplicationContext(), "User removed", Toast.LENGTH_SHORT).show();
+ tutorsList.remove(position);
+ notifyDataSetChanged();
+ },this::showError)
+ );
+ });
+//
+// if (tutor.isIsOnline()) {
+// image = context.getResources().getDrawable(R.drawable.user_list_online);
+// } else {
+// image = context.getResources().getDrawable(R.drawable.user_list_offline);
+// }
+//
+// if (!tutor.isIsActive()) {
+// image = context.getResources().getDrawable(R.drawable.user_list_off);
+// }
+
+// image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
+// holder.isOnline.setCompoundDrawables(image, null, null, null);
+ }
+
+ @Override
+ public int getItemCount() {
+ return tutorsList.size();
+ }
+
+ class MyViewHolder extends RecyclerView.ViewHolder {
+
+ @BindView(R.id.firstName)
+ TextView firstName;
+
+ @BindView(R.id.lastName)
+ TextView lastName;
+
+// @BindView(R.id.isOnline)
+// TextView isOnline;
+ @BindView(R.id.removeUserImageButton)
+ ImageButton imageButton;
+
+ MyViewHolder(View view) {
+ super(view);
+ ButterKnife.bind(this, view);
+ }
+ }
+
+ private void showError(Throwable e) {
+ String message;
+
+ if (e instanceof HttpException) {
+ ResponseBody responseBody = ((HttpException) e).response().errorBody();
+ message = RestApiHelper.getErrorMessage(responseBody);
+ } else {
+ message = "Network Error !";
+ }
+ Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
+
+ }
+
+}
\ No newline at end of file
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 8915cfa..393e20d 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,14 +81,15 @@ public interface UserService {
Completable removeStudentFromBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
@GET("api/users/whitelist/{tutorID}")
- Single> getTutorwhitelistedByID(@Path("tutorID") String tutorID);
+ Single> getTutorWhitelistedByID(@Path("tutorID") String tutorID);
@PUT("api/users/whitelist/{tutorID}")
Completable setTutorWhitelist(@Path("tutorID") String tutorID, @Body IsUsingListBool isUsing);
@POST("api/users/whitelist/{tutorID}")
- Completable addStudentTowhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
+ Completable addStudentToWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
- @DELETE("api/users/whitelist/{tutorID}")
+// @DELETE("api/users/whitelist/{tutorID}")
+ @HTTP(method = "DELETE", path = "api/users/whitelist/{tutorID}", hasBody = true)
Completable removeStudentFromWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
}
diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java
index a630b83..be3e350 100644
--- a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java
+++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java
@@ -207,5 +207,25 @@ public class PrefUtils {
return getSharedPreferences(context).getBoolean("show_only_online_users_in_list", true);
}
+ public static void useBlacklist(Context context, Boolean flag) {
+ SharedPreferences.Editor editor = getSharedPreferences(context).edit();
+ editor.putBoolean("blacklisting", flag);
+ editor.putBoolean("whitelisting", false);
+ editor.apply();
+ }
+
+ public static void useWhitelist(Context context, Boolean flag) {
+ SharedPreferences.Editor editor = getSharedPreferences(context).edit();
+ editor.putBoolean("whitelisting", flag);
+ editor.putBoolean("blacklisting", false);
+ editor.apply();
+ }
+
+ public static Boolean isBlackListing(Context context) {
+ return getSharedPreferences(context).getBoolean("blacklisting", false);
+ }
+ public static Boolean isWhiteListing(Context context) {
+ return getSharedPreferences(context).getBoolean("whitelisting", false);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_black_list.xml b/app/src/main/res/layout/activity_black_list.xml
index 7b69662..903ec62 100644
--- a/app/src/main/res/layout/activity_black_list.xml
+++ b/app/src/main/res/layout/activity_black_list.xml
@@ -48,7 +48,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumbTextPadding="45dp"
- android:checked="true"
android:text="BLACKLIST TEXT SWITCH" />
diff --git a/app/src/main/res/layout/activity_white_list.xml b/app/src/main/res/layout/activity_white_list.xml
new file mode 100644
index 0000000..0654405
--- /dev/null
+++ b/app/src/main/res/layout/activity_white_list.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/content_black_list.xml b/app/src/main/res/layout/content_black_list.xml
index a252726..e7cc148 100644
--- a/app/src/main/res/layout/content_black_list.xml
+++ b/app/src/main/res/layout/content_black_list.xml
@@ -13,7 +13,7 @@
diff --git a/app/src/main/res/layout/content_white_list.xml b/app/src/main/res/layout/content_white_list.xml
new file mode 100644
index 0000000..3ac2670
--- /dev/null
+++ b/app/src/main/res/layout/content_white_list.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/info_popup_whitelist.xml b/app/src/main/res/layout/info_popup_whitelist.xml
new file mode 100644
index 0000000..b61cb8f
--- /dev/null
+++ b/app/src/main/res/layout/info_popup_whitelist.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/white_list_fab_modal.xml b/app/src/main/res/layout/white_list_fab_modal.xml
new file mode 100644
index 0000000..f0380e6
--- /dev/null
+++ b/app/src/main/res/layout/white_list_fab_modal.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
\ 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
new file mode 100644
index 0000000..d2efd45
--- /dev/null
+++ b/app/src/main/res/layout/white_list_row.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml
index c149fc1..90a85ef 100644
--- a/app/src/main/res/menu/activity_main_drawer.xml
+++ b/app/src/main/res/menu/activity_main_drawer.xml
@@ -1,10 +1,10 @@
diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index 07e6ed9..65df81d 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -256,6 +256,10 @@
Brak użytkowników online.
Brak użytkowników offline.
Tylko użytkownicy online
+ Czarna lista
+ Biała lista
+ Biała lista
+ Dodaj użytkownika do białej listy
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7f42f4d..69d392b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -33,6 +33,7 @@
Settings
Blacklist
+ Whitelist
Password
Sign in or register
Sign out
@@ -298,9 +299,12 @@
- user is inactive
(didn’t share any localization data since 7 days)
BlackList
+ Whitelist
User index
Add user to Blacklist
-
+ Add user to Whitelist
+
+
"Material is the metaphor.\n\n"
"A material metaphor is the unifying theory of a rationalized space and a system of motion."