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

View File

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

View File

@ -19,6 +19,13 @@
android:textSize="@dimen/lbl_new_note_title" android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" /> 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 <TextView
android:id="@+id/userRoom" android:id="@+id/userRoom"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

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