0

Revisied Qustion:

[Firestore database structure screenshot][2]

Mr.Alex,

#1. Indexing done via Logcat

#2. date format is

 '2021-08-20 15:25:34.888 30176-30176/com.kasthu.prkeng D/TAG: Date is: Fri Aug 20 05:30:00 GMT+05:30 2021'

and my Firestore Timestamp format is

Firestore Timestamp format

Note: date is in "GMT" format and Timestamp is in "UTC" format--kindly advise on this and my simplified code code is -i am using "FirestoreRecyclerAdapter"

'FirestoreRecyclerOptions<model> options = new FirestoreRecyclerOptions.Builder<model>() 
.setQuery(df.orderBy("FullName", Query.Direction.ASCENDING) 
.whereEqualTo("TimeIn", date), model.class)
.build(); 
adapter = new fsattadapter(options); 
review.setAdapter(adapter); 

if i include whereEqualTo("TimeIn", date) in query, Recyclerview doesn't show anything.Kindly advise

3 Answers3

0

There is a possibility for the existence of several problems in your code, but I found the two major ones.

The problems is that the following query:

 df.orderBy("FullName", Query.Direction.ASCENDING)
      .whereEqualTo("TimeIn",date)

Requires an index. Even if you create the corresponding index, the query will not work because you pass to the .whereEqualTo() method a date which is in String format (15-08-2021), while in the database is a Firestore timestamp. So you cannot use a String when querying the database instead of a Timestamp and expect to behave correctly. To solve this, you should pass instead of a String a Date object and your query will work perfectly fine.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
0

i thing your filtering criteria is not working,


df.orderBy("FullName", Query.Direction.ASCENDING)
                               .whereEqualTo("TimeIn",edDatePick.getText().toString)
                                .get()                               
                            .addOnSuccessListener(newOnSuccessListener<QuerySnapshot>() {
viranga LH
  • 38
  • 2
  • 10
0

Hey Finaly i solved this filtering by date. But by storing Date as string in firestore as additional field.

 TVdatepick.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) {

            filter(s.toString());
        }
 private void filter(String text)
{
    List<model> filteredList = new ArrayList<>();

    for (model item : datalist) {
        if (item.getPunchDate().toLowerCase().contains(text.toLowerCase())) {
            filteredList.add(item);
        }
    }

    adapter.filterList(filteredList);
}

Adapter class:

  public void filterList(List<model> filteredList) {
    this.datalist=filteredList;
    notifyDataSetChanged();
}