white list finished, toogle on/off related to blacklsits

This commit is contained in:
Domagalski 2019-01-03 21:07:32 +01:00
parent aec9eaae19
commit d9ada9319b
20 changed files with 1517 additions and 15 deletions

View File

@ -65,6 +65,11 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />
<activity
android:name=".activity.WhiteList"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />
<activity
android:name=".activity.BlackList"
android:configChanges="keyboardHidden|orientation|screenSize"

View File

@ -0,0 +1,727 @@
{
"features": [
{
"type": "Feature",
"properties": {
"name": "Pokoje profesorskie"
},
"geometry": {
"coordinates": [
[
[
16.926707,
52.46657
],
[
16.92652,
52.466244
],
[
16.926459,
52.466255
],
[
16.926645,
52.466582
],
[
16.926707,
52.46657
]
]
],
"type": "Polygon"
},
"id": "07f45cd94d45bb5ad0b6b285b0f6fbbb"
},
{
"type": "Feature",
"properties": {
"name": "Skrzydło B"
},
"geometry": {
"coordinates": [
[
[
16.926961,
52.467026
],
[
16.92677,
52.466682
],
[
16.92652,
52.466244
],
[
16.926459,
52.466255
],
[
16.926428,
52.466203
],
[
16.926175,
52.46625
],
[
16.92621,
52.466306
],
[
16.926323,
52.466282
],
[
16.926515,
52.466632
],
[
16.926408,
52.466654
],
[
16.92644,
52.466712
],
[
16.926543,
52.46669
],
[
16.926754,
52.467067
],
[
16.926961,
52.467026
]
]
],
"type": "Polygon"
},
"id": "143facf35f322434cfc5776f70f1db36"
},
{
"type": "Feature",
"properties": {
"name": "Winda"
},
"geometry": {
"coordinates": [
[
[
16.92669,
52.467141
],
[
16.92666,
52.467089
],
[
16.926755,
52.46707
],
[
16.926786,
52.467121
],
[
16.92669,
52.467141
]
]
],
"type": "Polygon"
},
"id": "1a35bfafd619b80ffb8b36f03549e9e3"
},
{
"type": "Feature",
"properties": {
"name": "D2"
},
"geometry": {
"coordinates": [
[
[
16.926876,
52.466659
],
[
16.926984,
52.466635
],
[
16.92694,
52.466557
],
[
16.926831,
52.46658
],
[
16.926876,
52.466659
]
]
],
"type": "Polygon"
},
"id": "3e0a32a0583254e9e7c47fea1f402472"
},
{
"type": "Feature",
"properties": {
"name": "Sale A"
},
"geometry": {
"coordinates": [
[
[
16.92714,
52.466489
],
[
16.926925,
52.466127
],
[
16.927027,
52.466106
],
[
16.927232,
52.466472
],
[
16.92714,
52.466489
]
]
],
"type": "Polygon"
},
"id": "3e56cb54baf90049a3ce2f16577c2cd8"
},
{
"type": "Feature",
"properties": {
"name": "D1"
},
"geometry": {
"coordinates": [
[
[
16.926984,
52.466635
],
[
16.927084,
52.466614
],
[
16.92704,
52.466536
],
[
16.92694,
52.466557
],
[
16.926984,
52.466635
]
]
],
"type": "Polygon"
},
"id": "56c2a7ab4e4d2ac14a46448d523470dc"
},
{
"type": "Feature",
"properties": {
"name": "Hol"
},
"geometry": {
"coordinates": [
[
[
16.927104,
52.467081
],
[
16.927039,
52.467095
],
[
16.9268,
52.467145
],
[
16.926754,
52.467067
],
[
16.926961,
52.467026
],
[
16.927277,
52.46696
],
[
16.927272,
52.466951
],
[
16.927451,
52.466918
],
[
16.927494,
52.467002
],
[
16.927278,
52.467047
],
[
16.927144,
52.467073
],
[
16.927104,
52.467081
]
]
],
"type": "Polygon"
},
"id": "6f1db27a4df5a46f7a6913556b01effe"
},
{
"type": "Feature",
"properties": {
"name": "Pokoje profesorskie"
},
"geometry": {
"coordinates": [
[
[
16.92677,
52.466683
],
[
16.926961,
52.467026
],
[
16.926887,
52.467041
],
[
16.926695,
52.466699
],
[
16.92677,
52.466683
]
]
],
"type": "Polygon"
},
"id": "94f310dcaa6cee75d9e7800bf8d94155"
},
{
"type": "Feature",
"properties": {
"name": "Biblioteka"
},
"geometry": {
"coordinates": [
[
[
16.926801,
52.467144
],
[
16.926971,
52.467424
],
[
16.926956,
52.46743
],
[
16.926944,
52.467436
],
[
16.92693,
52.467441
],
[
16.926903,
52.467452
],
[
16.926861,
52.467464
],
[
16.926778,
52.467476
],
[
16.926731,
52.467485
],
[
16.926567,
52.467194
],
[
16.926801,
52.467144
]
]
],
"type": "Polygon"
},
"id": "aadab5775bdeb4eaf82c940255ddadd7"
},
{
"type": "Feature",
"properties": {
"name": "Sale A"
},
"geometry": {
"coordinates": [
[
[
16.927082,
52.466492
],
[
16.926999,
52.466509
],
[
16.926771,
52.466109
],
[
16.926857,
52.466088
],
[
16.927082,
52.466492
]
]
],
"type": "Polygon"
},
"id": "b39857ed605e5794fa6c9cdee5d7d6cf"
},
{
"type": "Feature",
"properties": {
"name": "Pokoje profesorskie"
},
"geometry": {
"coordinates": [
[
[
16.926754,
52.467066
],
[
16.926814,
52.467054
],
[
16.926605,
52.466676
],
[
16.926542,
52.46669
],
[
16.926564,
52.466728
],
[
16.926754,
52.467066
]
]
],
"type": "Polygon"
},
"id": "b754d867fde3826e72fe8c243399ff26"
},
{
"type": "Feature",
"properties": {
"name": "Sale A"
},
"geometry": {
"coordinates": [
[
[
16.927272,
52.46695
],
[
16.927083,
52.466613
],
[
16.927167,
52.466595
],
[
16.92735,
52.466936
],
[
16.927272,
52.46695
]
]
],
"type": "Polygon"
},
"id": "c3726b2a2b3a589995fd3f17eecd1f53"
},
{
"type": "Feature",
"properties": {
"name": "D3"
},
"geometry": {
"coordinates": [
[
[
16.92677,
52.466682
],
[
16.926876,
52.466659
],
[
16.926832,
52.46658
],
[
16.926725,
52.466604
],
[
16.92677,
52.466682
]
]
],
"type": "Polygon"
},
"id": "c73d9bdbccc15d9907e24b8bb731118a"
},
{
"type": "Feature",
"properties": {
"name": "Pokoje profesorskie"
},
"geometry": {
"coordinates": [
[
[
16.926324,
52.466282
],
[
16.926503,
52.46661
],
[
16.926579,
52.466595
],
[
16.926398,
52.466268
],
[
16.926324,
52.466282
]
]
],
"type": "Polygon"
},
"id": "d54475cedfa0a866e13933c56bf35d76"
},
{
"type": "Feature",
"properties": {
"name": "Sale A"
},
"geometry": {
"coordinates": [
[
[
16.927607,
52.466891
],
[
16.92734,
52.466562
],
[
16.927242,
52.466585
],
[
16.927451,
52.466918
],
[
16.927607,
52.466891
]
]
],
"type": "Polygon"
},
"id": "d97989e446002de50bc8844d2d9cdf5c"
},
{
"type": "Feature",
"properties": {
"name": "Winda"
},
"geometry": {
"coordinates": [
[
[
16.92669,
52.467141
],
[
16.92666,
52.467089
],
[
16.926755,
52.46707
],
[
16.926786,
52.467121
],
[
16.92669,
52.467141
]
]
],
"type": "Polygon"
},
"id": "dfdba4ee1ee0c55193b8dd04f8b00f6c"
},
{
"type": "Feature",
"properties": {
"name": "Skrzydło A"
},
"geometry": {
"coordinates": [
[
[
16.927606,
52.466891
],
[
16.927339,
52.466562
],
[
16.927242,
52.466585
],
[
16.92718,
52.466482
],
[
16.927232,
52.466473
],
[
16.927025,
52.466105
],
[
16.926924,
52.466126
],
[
16.926896,
52.466078
],
[
16.92677,
52.466108
],
[
16.926998,
52.466509
],
[
16.927041,
52.466537
],
[
16.927075,
52.466595
],
[
16.927082,
52.466614
],
[
16.927277,
52.46696
],
[
16.927358,
52.466942
],
[
16.927354,
52.466935
],
[
16.92745,
52.466918
],
[
16.927606,
52.466891
]
]
],
"type": "Polygon"
},
"id": "faaa569e3642a741f70a77071f19f131"
}
],
"type": "FeatureCollection"
}

View File

@ -99,8 +99,8 @@ public abstract class BaseActivity
String itemName = (String) item.getTitle();
Intent launchIntent;
if (itemName.equals(getResources().getString(R.string.navigation_item_whitelist))) {
/* launchIntent = new Intent(getApplicationContext(), WhitelistActivity.class);
startActivity(launchIntent);*/
launchIntent = new Intent(getApplicationContext(), WhiteList.class);
startActivity(launchIntent);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
launchIntent = new Intent(getApplicationContext(),BlackList.class);
startActivity(launchIntent);

View File

@ -70,7 +70,7 @@ public class BlackList extends AppCompatActivity {
private boolean didFetched = false;
private String tutorId;
@BindView(R.id.recycler_view)
@BindView(R.id.recycler_view_blacklist)
RecyclerView recyclerView;
@BindView(R.id.black_list_empty_text_view)
TextView noNotesView;
@ -89,16 +89,24 @@ public class BlackList extends AppCompatActivity {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
setContentView(R.layout.activity_black_list);
ButterKnife.bind(this);
aSwitch.setText(getString(R.string.action_black_list) +" ON");
tutorId = PrefUtils.getUserId(getApplicationContext());
userService = ApiClient.getClient(getApplicationContext())
.create(UserService.class);
if (PrefUtils.isBlackListing(this)){
aSwitch.setText(getString(R.string.action_black_list) +" ON");
aSwitch.setChecked(true);
handleChangeRequest(true);
}else{
aSwitch.setText(getString(R.string.action_black_list) +" OFF");
aSwitch.setChecked(false);
handleChangeRequest(false);
}
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.activity_title_blacklist));
setSupportActionBar(toolbar);
userService = ApiClient.getClient(getApplicationContext())
.create(UserService.class);
mAdapter = new BlackListAdapter(this, blacklistedUsers);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
@ -314,9 +322,11 @@ public class BlackList extends AppCompatActivity {
if (isChecked){
aSwitch.setText(getString(R.string.action_black_list) + " "+ getString(R.string.on));
handleChangeRequest(true);
PrefUtils.useBlacklist(this,true);
}else {
aSwitch.setText(getString(R.string.action_black_list) + " "+getString(R.string.off));
handleChangeRequest(false);
PrefUtils.useBlacklist(this,false);
}
});
}

View File

@ -199,6 +199,7 @@ public class MapActivity extends BaseActivity
private void createMarkerModalView(User user) {
String cordStatus = coordsMap.get(user.getId()).getLabel();
String sharingLevel = coordsMap.get(user.getId()).getDisplayMode();
user.statu
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.marker_modal, null);

View File

@ -0,0 +1,332 @@
package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Switch;
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.adapters.WhiteListAdapter;
import com.uam.wmi.findmytutor.model.IsUsingListBool;
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.MyDividerItemDecoration;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
import com.uam.wmi.findmytutor.utils.RestApiHelper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
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)
TextView noNotesView;
@BindView(R.id.switch_whitelist_toggle)
Switch aSwitch;
@BindView(R.id.add_to_white_list_fab)
FloatingActionButton addToWhiteListFab;
private WhiteListAdapter mAdapter;
private List<User> whitelistedUsers = new ArrayList<>();
private HashSet<String> 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<List<String>>() {
@Override
public void onSuccess(List<String> 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<User>() {
@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)
);
}
}

View File

@ -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<WhiteListAdapter.MyViewHolder> {
private Context context;
private List<User> tutorsList;
private CompositeDisposable disposable = new CompositeDisposable();
private UserService userService;
public WhiteListAdapter(Context context, List<User> 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();
}
}

View File

@ -81,14 +81,15 @@ public interface UserService {
Completable removeStudentFromBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
@GET("api/users/whitelist/{tutorID}")
Single<List<User>> getTutorwhitelistedByID(@Path("tutorID") String tutorID);
Single<List<String>> 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);
}

View File

@ -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);
}
}

View File

@ -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" />
</LinearLayout>

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/activity_whitelist_container"
tools:context=".activity.WhiteList">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleGravity="top|right"
app:toolbarId="@+id/toolbar"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left|bottom"
android:orientation="vertical"
android:padding="10dp"
android:layout_marginBottom="20dp"
app:layout_collapseMode="parallax">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Be visible for these users"
android:textSize="15sp"/>
<Switch
android:id="@+id/switch_whitelist_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumbTextPadding="45dp"
android:text="WHITELIST TEXT SWITCH" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_white_list" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_to_white_list_fab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:layout_marginTop="-322dp"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@android:drawable/ic_input_add"
app:useCompatPadding="true"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<!-- A RecyclerView with some commonly used attributes -->
</android.support.design.widget.CoordinatorLayout>

View File

@ -13,7 +13,7 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:id="@+id/recycler_view_blacklist"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.UsersListFragment"
android:fontFamily="@font/lato_regular"
tools:showIn="@layout/users_list_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_whitelist"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/white_list_empty_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/margin_top_no_notes"
android:fontFamily="sans-serif-light"
android:text="@string/loading"
android:textColor="@color/msg_no_notes"
android:textSize="@dimen/msg_no_notes" />
</RelativeLayout>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/layout_bg"
android:orientation="vertical"
android:padding="10dp"
android:textColor="@color/half_black">
<TextView
android:id="@+id/textViewP1_info_icon_whitelist_p1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="@string/info_icon_whitelist_p1"
android:textColor="@color/half_black" />
<TextView
android:id="@+id/textViewP2_info_icon_whitelist_p2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/info_icon_whitelist_p2"
android:textColor="@color/half_black" />
<TextView
android:id="@+id/textViewP3_info_icon_whitelist_p3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/info_icon_whitelist_p3"
android:textColor="@color/half_black" />
</LinearLayout>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/lato_regular"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/white_list_modal_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/white_list_modal_input"
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:text="@string/white_list_title"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<EditText
android:id="@+id/white_list_modal_input"
android:layout_width="315dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="@string/index_user"
android:maxLength="30"
android:maxLines="1"
android:requiresFadingEdge="vertical"
android:scrollbars="vertical"
android:textColor="@color/note_list_text" />
</RelativeLayout>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="90dp"
android:clickable="true"
android:focusable="true"
android:paddingLeft="10dp"
android:paddingTop="@dimen/dimen_10"
android:paddingRight="10dp"
android:fontFamily="@font/lato_regular"
android:paddingBottom="@dimen/dimen_10">
<TextView
android:id="@+id/firstName"
android:layout_width="271dp"
android:layout_height="22dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:textColor="@color/note_list_text"
android:textSize="15sp" />
<TextView
android:id="@+id/lastName"
android:layout_width="270dp"
android:layout_height="22dp"
android:layout_below="@+id/firstName"
android:layout_alignEnd="@+id/firstName"
android:layout_marginTop="10dp"
android:layout_marginEnd="0dp"
android:textColor="@color/note_list_text"
android:textSize="15sp" />
<!--<TextView-->
<!--android:id="@+id/isOnline"-->
<!--android:layout_width="48dp"-->
<!--android:layout_height="30dp"-->
<!--android:layout_below="@+id/firstName"-->
<!--android:layout_marginStart="7dp"-->
<!--android:layout_marginTop="-10dp"-->
<!--android:layout_toEndOf="@+id/firstName"-->
<!--android:textColor="@color/note_list_text"-->
<!--android:textSize="@dimen/note_list_text" />-->
<ImageButton
android:id="@+id/removeUserImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/firstName"
android:layout_toEndOf="@+id/firstName"
android:background="@null"
app:srcCompat="@drawable/abc_ic_clear_material" />
</RelativeLayout>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/drawer_group_tutor">
<!-- <item
<item
android:id="@+id/nav_item_one"
android:icon="@drawable/ic_people_white"
android:title="@string/navigation_item_whitelist" />-->
android:title="@string/navigation_item_whitelist" />
<item
android:id="@+id/nav_item_two"
android:icon="@drawable/ic_people_black"

View File

@ -0,0 +1,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.uam.wmi.findmytutor.activity.BlackList">
<item
android:id="@+id/action_whitelist_info_popup"
android:orderInCategory="100"
android:title="Popup info icon"
android:icon="@drawable/outline_info_24"
app:showAsAction="ifRoom" />
</menu>

View File

@ -256,6 +256,10 @@
<string name="no_online_users">Brak użytkowników online.</string>
<string name="no_offline_users">Brak użytkowników offline.</string>
<string name="only_online_users">Tylko użytkownicy online</string>
<string name="activity_title_blacklist">Czarna lista</string>
<string name="activity_title_whitelist">Biała lista</string>
<string name="title_activity_white_list">Biała lista</string>
<string name="white_list_title">Dodaj użytkownika do białej listy</string>
</resources>

View File

@ -33,6 +33,7 @@
<!-- Tutors list -->
<string name="action_settings">Settings</string>
<string name="activity_title_blacklist">Blacklist</string>
<string name="activity_title_whitelist">Whitelist</string>
<string name="prompt_password">Password</string>
<string name="action_sign_in">Sign in or register</string>
<string name="action_sign_out">Sign out</string>
@ -298,9 +299,12 @@
<string name="info_icon_userlist_tab_level_status_inactive">- user is inactive </string>
<string name="info_icon_userlist_tab_level_status_inactive_tip">(didnt share any localization data since 7 days)</string>
<string name="title_activity_black_list">BlackList</string>
<string name="title_activity_white_list">Whitelist</string>
<string name="index_user">User index</string>
<string name="black_list_title">Add user to Blacklist</string>
<string name="large_text">
<string name="white_list_title">Add user to Whitelist</string>
<string name="large_text" translatable="false">
"Material is the metaphor.\n\n"
"A material metaphor is the unifying theory of a rationalized space and a system of motion."