Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AppUserSearchActivity extends AppCompatActivity {
- private static final String TAG = "AppUserSearchActivityTag";
- RecyclerView recyclerView;
- EditText searchEt;
- UserDetails myUser;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_app_user_search);
- _init();
- SearchAction();
- }
- private void SearchAction() {
- searchEt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- String str = searchEt.getText().toString().trim();
- Log.d(TAG, "onEditorAction: " + str);
- Log.d(TAG, "onEditorAction: Action: " + actionId);
- if (actionId == EditorInfo.IME_ACTION_DONE ) {
- str = str.toLowerCase();
- Log.d(TAG, "onEditorAction: Done!!");
- FirebaseFirestore.getInstance().collection(Constants.FIRESTORE_USERS)
- .whereEqualTo("username", str)
- .get()
- .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
- @Override
- public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
- ArrayList<UserDetails> userDetails = new ArrayList<>();
- Log.d(TAG, "onSuccess: SearchSize: " + queryDocumentSnapshots.size());
- for (QueryDocumentSnapshot snapshot : queryDocumentSnapshots) {
- UserDetails userDetail = snapshot.toObject(UserDetails.class);
- if(!userDetail.getPhone().equalsIgnoreCase(myUser.getPhone())) {
- userDetails.add(userDetail);
- }
- }
- AppUserSearchAdapter adapter = new AppUserSearchAdapter(AppUserSearchActivity.this, userDetails);
- recyclerView.setAdapter(adapter);
- }
- });
- return true;
- }
- return false;
- }
- });
- searchEt.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- ArrayList<UserDetails> userDetails = new ArrayList<>();
- AppUserSearchAdapter adapter = new AppUserSearchAdapter(AppUserSearchActivity.this, userDetails);
- recyclerView.setAdapter(adapter);
- }
- });
- }
- private void _init() {
- recyclerView = findViewById(R.id.app_user_search_rcv);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
- searchEt = findViewById(R.id.app_user_search_username);
- myUser = Constants.getUser(this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment