Improve searching

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-02 16:08:11 +01:00
parent aa3dbfb185
commit 44b84fef0e
4 changed files with 27 additions and 22 deletions

View File

@ -1,6 +1,5 @@
package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
@ -63,15 +62,12 @@ public class UsersListActivity extends Fragment {
private List<User> tutorsList = new ArrayList<>();
private List<User> tutorsFiltered = new ArrayList<>();
public static UsersListActivity newInstance() {
return new UsersListActivity();
}
public UsersListActivity() {
}
public static UsersListActivity newInstance() {
return new UsersListActivity();
}
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mAdapter = new TutorsAdapter(getActivity().getApplicationContext(), tutorsFiltered);
@ -113,11 +109,13 @@ public class UsersListActivity extends Fragment {
}
public void searchUser( String textToSearch){
Log.e("SEARCH","textToSearch");
public void searchUser(String textToSearch) {
Log.e("SEARCH", textToSearch);
tutorsList.toString();
tutorsFiltered.clear();
tutorsFiltered.addAll(Stream.of(tutorsList).filter(t -> t.toSearchString().contains(textToSearch)).toList());
tutorsFiltered.addAll(Stream.of(tutorsList).filter(t ->
t.toSearchString().toLowerCase().contains(textToSearch.toLowerCase())).toList());
mAdapter.notifyDataSetChanged();
}
@ -137,6 +135,7 @@ public class UsersListActivity extends Fragment {
TextView userNote = view.findViewById(R.id.userNote);
TextView userRoom = view.findViewById(R.id.userRoom);
TextView userEmail = view.findViewById(R.id.userEmail);
TextView department = view.findViewById(R.id.userDepartment);
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
@ -145,18 +144,16 @@ public class UsersListActivity extends Fragment {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
@SuppressLint("SetTextI18n")
@Override
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
.map(DutyHourViewModel::getSummary).toList();
Log.e("DUTY",dutyHoursList.toString());
userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom()));
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote()));
department.setText(String.format("%s: %s", getString(R.string.userDepartment), user.getDepartment()));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_list_item_activated_1, dutyHoursList);
@ -255,20 +252,20 @@ public class UsersListActivity extends Fragment {
public void onResume() {
super.onResume();
fetchAllTutors();
Log.e(TAG,"onResume");
Log.e(TAG, "onResume");
}
@Override
public void onPause() {
super.onPause();
Log.e(TAG,"onPause");
Log.e(TAG, "onPause");
}
@Override
public void onStop() {
super.onStop();
Log.e(TAG,"onStop");
Log.e(TAG, "onStop");
}
public void onSaveInstanceState(Bundle outState) {

View File

@ -704,10 +704,10 @@ public class User extends BaseResponse {
public String toSearchString() {
StringBuilder sb = new StringBuilder();
sb.append(userName);
sb.append(lastName);
sb.append(department);
sb.append(email);
sb.append(getFirstName()).append(" ");
sb.append(getLastName()).append(" ");
sb.append(getDepartment()).append(" ");
sb.append(getEmail());
return sb.toString();
}

View File

@ -19,6 +19,13 @@
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<TextView
android:id="@+id/userDepartment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text"
/>
<TextView
android:id="@+id/userRoom"
android:layout_width="match_parent"

View File

@ -202,7 +202,8 @@ functionality.</string>
<string name="userRoom">Pokój</string>
<string name="userEmail">Email</string>
<string name="userNote">Notatka</string>
<string name="userDutyHoursHeader">Dyżury:</string>
<string name="dutyHours">Dyżury:</string>
<string name="userDutyHoursHeader">Dyżury</string>
<string name="dutyHours">Dyżury</string>
<string name="error_invalid_login_name">Invalid format of login. Use s11111 format</string>
<string name="userDepartment">Zakład</string>
</resources>