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 f7958da..33603bf 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 @@ -49,10 +49,14 @@ import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.RecyclerTouchListener; import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.SharingLevel; +import com.uam.wmi.findmytutor.utils.WrapContentLinearLayoutManager; +import java.text.Collator; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import butterknife.BindView; @@ -82,10 +86,10 @@ public class BlackList extends AppCompatActivity { Switch aSwitch; @BindView(R.id.add_to_black_list_fab) FloatingActionButton addToBlackListFab; - + private Integer prevSize; private BlackListAdapter mAdapter; private List blacklistedUsers = new ArrayList<>(); - private HashSet blacklistedUsersIDs = new HashSet<>(); + private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL")); @Override protected void onCreate(Bundle savedInstanceState) { @@ -112,12 +116,12 @@ public class BlackList extends AppCompatActivity { setSupportActionBar(toolbar); mAdapter = new BlackListAdapter(this, blacklistedUsers); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); - recyclerView.setLayoutManager(mLayoutManager); + recyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getApplicationContext())); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16)); recyclerView.setAdapter(mAdapter); + fetchBlackListedUsers(); /** * On long press on RecyclerView item, open alert dialog * with options to choose @@ -136,32 +140,9 @@ public class BlackList extends AppCompatActivity { addToBlackListFab.setOnClickListener(this::showFabDialog); - fetchBlackListedUsersIDs(PrefUtils.getUserId(getApplicationContext())); handleSwitch(); } - private void fetchBlackListedUsersIDs(String userId) { - disposable.add( - userService.getTutorBlacklistedByID(userId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver>() { - @Override - public void onSuccess(List users) { - blacklistedUsersIDs.addAll(users); - didFetched = true; - fetchBlackListedUsers(); - toggleEmptyNotes(); - } - - @Override - public void onError(Throwable e) { - showError(e); - } - }) - ); - } - private Observable> getListOfBlacklistedUsers(String userId) { return userService.getTutorBlacklistedByID(userId) .toObservable() @@ -178,7 +159,11 @@ public class BlackList extends AppCompatActivity { } private void fetchBlackListedUsers() { - disposable.add(getListOfBlacklistedUsers(PrefUtils.getUserId(getApplicationContext())) + prevSize = blacklistedUsers.size(); + + blacklistedUsers.clear(); + + disposable.add(getListOfBlacklistedUsers(tutorId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .flatMap((Function, Observable>) Observable::fromIterable) @@ -196,12 +181,21 @@ public class BlackList extends AppCompatActivity { @Override public void onComplete() { - toggleEmptyNotes(); - mAdapter.notifyDataSetChanged(); + Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b)); + refreshUI(); } })); } + private void refreshUI(){ + toggleEmptyNotes(); + mAdapter.notifyItemRangeInserted(prevSize, blacklistedUsers.size() - prevSize); + mAdapter.notifyDataSetChanged(); + } + + private int sortByUserName(User t1, User t2) { + return plCollator.compare(t1.getLastName(), t2.getLastName()); + } private void showFabDialog(View v){ LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); @@ -256,9 +250,7 @@ public class BlackList extends AppCompatActivity { private void handleAddUser(User user) { Toast.makeText(this, R.string.add_user_to_list, Snackbar.LENGTH_LONG).show(); - blacklistedUsersIDs.clear(); blacklistedUsers.clear(); - blacklistedUsersIDs.addAll(user.getBlacklist()); fetchBlackListedUsers(); } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java index 1bf6765..fda30bf 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java @@ -148,10 +148,10 @@ public class LoginActivity extends AppCompatActivity { } private void loginProcess(String email, String password) { - //ValidateUser user = new ValidateUser(email, password); - LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email); - //disposable.add(ldapService.validate(user) - disposable.add(ldapService.fakeValidate(fakeUser) + ValidateUser user = new ValidateUser(email, password); + // LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email); + disposable.add(ldapService.validate(user) + //disposable.add(ldapService.fakeValidate(fakeUser) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::handleResponse, this::handleError)); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java index 47e63a3..3ba50f3 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java @@ -68,7 +68,6 @@ public class UsersListFragment extends Fragment { private CompositeDisposable disposable = new CompositeDisposable(); private TutorsListAdapter mAdapter; private List tutorsList = new ArrayList<>(); - private List tutorsFiltered = new ArrayList<>(); private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL")); private Boolean fetchOnlyOnlineUsers = PrefUtils.getShowOnlyOnlineUsers(getApplicationContext()); @@ -80,7 +79,7 @@ public class UsersListFragment extends Fragment { } public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mAdapter = new TutorsListAdapter(getActivity().getApplicationContext(), tutorsFiltered); + mAdapter = new TutorsListAdapter(getActivity().getApplicationContext(), tutorsList); View view = inflater.inflate(R.layout.users_list, container, false); view.setBackgroundColor(getResources().getColor(android.R.color.white)); setHasOptionsMenu(true); @@ -109,7 +108,7 @@ public class UsersListFragment extends Fragment { recyclerView, new RecyclerTouchListener.ClickListener() { @Override public void onClick(View view, final int position) { - showNoteDialog(tutorsFiltered.get(position)); + showNoteDialog(tutorsList.get(position)); } @Override @@ -236,12 +235,9 @@ public class UsersListFragment extends Fragment { .observeOn(AndroidSchedulers.mainThread()) .map(tutors -> { List tutorsList = new ArrayList<>(tutors); - List onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList(); - List activeNotOnlineTutors = Stream.of(tutorsList) .filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList(); - List notActiveTutors = Stream.of(tutorsList) .filterNot(User::isIsActive).toList(); @@ -259,9 +255,7 @@ public class UsersListFragment extends Fragment { @Override public void onSuccess(List users) { tutorsList.clear(); - tutorsFiltered.clear(); tutorsList.addAll(users); - tutorsFiltered.addAll(users); mAdapter.notifyDataSetChanged(); toggleEmptyNotes(); } @@ -282,8 +276,8 @@ public class UsersListFragment extends Fragment { .subscribeWith(new DisposableSingleObserver>() { @Override public void onSuccess(List users) { - tutorsFiltered.clear(); - tutorsFiltered.addAll(users); + tutorsList.clear(); + tutorsList.addAll(users); mAdapter.notifyDataSetChanged(); } 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 afdd102..262070a 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 @@ -39,10 +39,14 @@ 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 com.uam.wmi.findmytutor.utils.WrapContentLinearLayoutManager; +import java.text.Collator; import java.util.ArrayList; -import java.util.HashSet; +import java.util.Collections; + import java.util.List; +import java.util.Locale; import butterknife.BindView; import butterknife.ButterKnife; @@ -56,6 +60,8 @@ import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; + + public class WhiteList extends AppCompatActivity { private CompositeDisposable disposable = new CompositeDisposable(); @@ -72,8 +78,10 @@ public class WhiteList extends AppCompatActivity { @BindView(R.id.add_to_white_list_fab) FloatingActionButton addToWhiteListFab; private WhiteListAdapter mAdapter; + private Integer prevSize; private List whitelistedUsers = new ArrayList<>(); - private HashSet whitelistedUsersIDs = new HashSet<>(); + private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL")); + @Override protected void onCreate(Bundle savedInstanceState) { @@ -100,8 +108,7 @@ public class WhiteList extends AppCompatActivity { setSupportActionBar(toolbar); mAdapter = new WhiteListAdapter(this, whitelistedUsers); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); - recyclerView.setLayoutManager(mLayoutManager); + recyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getApplicationContext())); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16)); recyclerView.setAdapter(mAdapter); @@ -123,33 +130,10 @@ public class WhiteList extends AppCompatActivity { })); addToWhiteListFab.setOnClickListener(this::showFabDialog); - - fetchWhiteListedUsersIDs(PrefUtils.getUserId(getApplicationContext())); + fetchWhiteListedUsers(); 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 Observable> getListOfWhitelistedUsers(String userId) { return userService.getTutorWhitelistedByID(userId) .toObservable() @@ -166,7 +150,10 @@ public class WhiteList extends AppCompatActivity { } private void fetchWhiteListedUsers() { - disposable.add(getListOfWhitelistedUsers(PrefUtils.getUserId(getApplicationContext())) + prevSize = whitelistedUsers.size(); + whitelistedUsers.clear(); + + disposable.add(getListOfWhitelistedUsers(tutorId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .flatMap((Function, Observable>) Observable::fromIterable) @@ -184,12 +171,22 @@ public class WhiteList extends AppCompatActivity { @Override public void onComplete() { - toggleEmptyNotes(); - mAdapter.notifyDataSetChanged(); + Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a,b)); + refreshUI(); } })); } + private void refreshUI(){ + toggleEmptyNotes(); + mAdapter.notifyItemRangeInserted(prevSize, whitelistedUsers.size() - prevSize); + mAdapter.notifyDataSetChanged(); + } + + private int sortByUserName(User t1, User t2) { + return plCollator.compare(t1.getLastName(), t2.getLastName()); + } + private void showFabDialog(View v){ LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); @SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.white_list_fab_modal, null); @@ -241,16 +238,11 @@ public class WhiteList extends AppCompatActivity { private void handleAddUser(User user) { Toast.makeText(this, R.string.add_user_to_list, Snackbar.LENGTH_LONG).show(); - - whitelistedUsersIDs.clear(); - whitelistedUsers.clear(); - whitelistedUsersIDs.addAll(user.getWhitelist()); fetchWhiteListedUsers(); } private void showError(Throwable e) { String message; - Log.e("ERR", String.valueOf(e)); if (e instanceof HttpException) { ResponseBody responseBody = ((HttpException) e).response().errorBody(); @@ -266,7 +258,6 @@ public class WhiteList extends AppCompatActivity { } private void toggleEmptyNotes() { - if (didFetched && whitelistedUsers.size() == 0) { noNotesView.setText(R.string.list_is_empty); noNotesView.setVisibility(View.VISIBLE); @@ -301,7 +292,6 @@ public class WhiteList extends AppCompatActivity { @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; } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/adapters/BlackListAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/adapters/BlackListAdapter.java index 3fd9043..f42c9a7 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/adapters/BlackListAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/adapters/BlackListAdapter.java @@ -41,11 +41,11 @@ public class BlackListAdapter extends RecyclerView.Adapter tutors) { this.context = context; this.tutorsList = tutors; } + @NonNull @Override public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -73,25 +73,12 @@ public class BlackListAdapter extends RecyclerView.Adapter{ - Toast.makeText(getApplicationContext(), "User removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(), R.string.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 @@ -107,8 +94,6 @@ public class BlackListAdapter extends RecyclerView.Adapter hours) { this.context = context; - this.hours = new ArrayList(hours); + this.hours = new ArrayList<>(hours); } 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 index 45d2671..2800dc0 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/adapters/WhiteListAdapter.java @@ -39,7 +39,6 @@ public class WhiteListAdapter extends RecyclerView.Adapter tutors) { this.context = context; this.tutorsList = tutors; @@ -61,8 +60,8 @@ public class WhiteListAdapter extends RecyclerView.Adapter{ StudentIdModel studentIdModel = new StudentIdModel(tutor.getLdapLogin()); String tutorId = PrefUtils.getUserId(getApplicationContext()); @@ -71,25 +70,13 @@ public class WhiteListAdapter extends RecyclerView.Adapter{ - Toast.makeText(getApplicationContext(), "User removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(), R.string.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 @@ -105,8 +92,6 @@ public class WhiteListAdapter extends RecyclerView.Adapter Użytkownik został dodany! + Użytkownik usunięty! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 507177c..50667e5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,12 +54,10 @@ - Sharing - Sharing Location sharing Status settings @@ -87,14 +85,10 @@ Add custom status - Descrition + Description Save Edit your note. It will be shown in the users list. - - key_description - - Manual location Choose manual location Add custom location @@ -302,96 +296,6 @@ Whitelist 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." - "The material is grounded in tactile reality, inspired by the study of paper and ink, yet " - "technologically advanced and open to imagination and magic.\n" - "Surfaces and edges of the material provide visual cues that are grounded in reality. The " - "use of familiar tactile attributes helps users quickly understand affordances. Yet the " - "flexibility of the material creates new affordances that supercede those in the physical " - "world, without breaking the rules of physics.\n" - "The fundamentals of light, surface, and movement are key to conveying how objects move, " - "interact, and exist in space and in relation to each other. Realistic lighting shows " - "seams, divides space, and indicates moving parts.\n\n" - - "Bold, graphic, intentional.\n\n" - - "The foundational elements of print based design typography, grids, space, scale, color, " - "and use of imagery guide visual treatments. These elements do far more than please the " - "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge " - "imagery, large scale typography, and intentional white space create a bold and graphic " - "interface that immerse the user in the experience.\n" - "An emphasis on user actions makes core functionality immediately apparent and provides " - "waypoints for the user.\n\n" - - "Motion provides meaning.\n\n" - - "Motion respects and reinforces the user as the prime mover. Primary user actions are " - "inflection points that initiate motion, transforming the whole design.\n" - "All action takes place in a single environment. Objects are presented to the user without " - "breaking the continuity of experience even as they transform and reorganize.\n" - "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. " - "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n" - - "3D world.\n\n" - - "The material environment is a 3D space, which means all objects have x, y, and z " - "dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the " - "positive z-axis extending towards the viewer. Every sheet of material occupies a single " - "position along the z-axis and has a standard 1dp thickness.\n" - "On the web, the z-axis is used for layering and not for perspective. The 3D world is " - "emulated by manipulating the y-axis.\n\n" - - "Light and shadow.\n\n" - - "Within the material environment, virtual lights illuminate the scene. Key lights create " - "directional shadows, while ambient light creates soft shadows from all angles.\n" - "Shadows in the material environment are cast by these two light sources. In Android " - "development, shadows occur when light sources are blocked by sheets of material at " - "various positions along the z-axis. On the web, shadows are depicted by manipulating the " - "y-axis only. The following example shows the card with a height of 6dp.\n\n" - - "Resting elevation.\n\n" - - "All material objects, regardless of size, have a resting elevation, or default elevation " - "that does not change. If an object changes elevation, it should return to its resting " - "elevation as soon as possible.\n\n" - - "Component elevations.\n\n" - - "The resting elevation for a component type is consistent across apps (e.g., FAB elevation " - "does not vary from 6dp in one app to 16dp in another app).\n" - "Components may have different resting elevations across platforms, depending on the depth " - "of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n" - - "Responsive elevation and dynamic elevation offsets.\n\n" - - "Some component types have responsive elevation, meaning they change elevation in response " - "to user input (e.g., normal, focused, and pressed) or system events. These elevation " - "changes are consistently implemented using dynamic elevation offsets.\n" - "Dynamic elevation offsets are the goal elevation that a component moves towards, relative " - "to the component’s resting state. They ensure that elevation changes are consistent " - "across actions and component types. For example, all components that lift on press have " - "the same elevation change relative to their resting elevation.\n" - "Once the input event is completed or cancelled, the component will return to its resting " - "elevation.\n\n" - - "Avoiding elevation interference.\n\n" - - "Components with responsive elevations may encounter other components as they move between " - "their resting elevations and dynamic elevation offsets. Because material cannot pass " - "through other material, components avoid interfering with one another any number of ways, " - "whether on a per component basis or using the entire app layout.\n" - "On a component level, components can move or be removed before they cause interference. " - "For example, a floating action button (FAB) can disappear or move off screen before a " - "user picks up a card, or it can move if a snackbar appears.\n" - "On the layout level, design your app layout to minimize opportunities for interference. " - "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere " - "when a user tries to pick up one of cards.\n\n" - - After clicking on a name, the tutor tab will pop up, containing details about selected tutor.\n\nYou can search for any tutor on the map by entering his name and surname in the search field.\n\nBy default, only active users are shown. You can change that in menu (three dots icon).\n\nYou can also search for a tutor directly, by entering name and surname of person that you look for. @@ -439,5 +343,6 @@ User has been added! + User removed!