0

I have a model class which looks like this:

public class ListModel {
    private String listName;
    @ServerTimestamp
    private Date date;

    public ListModel() {}    
    public ListModel(String listName) {this.listName = listName;}

    //setters and getters
}

This is how I add a list to database:

 ListModel listModel = new ListModel(listName);
 listsRef.document(listId).set(listModel);

When I look into the database, my date looks like this:

enter image description here

To display the name and the date of the list, I'm using a FirestoreRecyclerAdapter and a RecyclerView. The problem is when I add a list, the name is displayed instantly but the date is displayed first as null and only after one or two seconds is displayed correctly.

I know that the date is generated server side, but how can I display the date correctly from the first time?

Joan P.
  • 2,368
  • 6
  • 30
  • 63

1 Answers1

2

There currently is no way to immediately show the timestamp. The server-side timestamp is only generated on the server, and is null until the response from the server comes back.

There is work under way to make the client estimate the timestamp straight away. Once that is released, you'll get two events (similar to how the Firebase Realtime Database works): the first event contains a local estimate of the timestamp, the second event contains the actual confirmed timestamp from the server.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807