-
Notifications
You must be signed in to change notification settings - Fork 4
Information Sources
Jacob Wong edited this page Oct 27, 2019
·
33 revisions
[TBD]
- Basically, the Date object is a [redacted] to use so they made it better.
- For documentation purposes, the main reason for choosing the Java 8 Date/Time API is it's Ease of use and Ease of Understanding over the previous Date object.
Examples of Use:
LocalDate localDate = LocalDate.now();
LocalDate.of(2015, 02, 20);
LocalDate.parse("2015-02-20");
LocalDate tomorrow = LocalDate.now().plusDays(1);
localDateTime.minusHours(2);
DayOfWeek sunday = LocalDate.parse("2016-06-12").getDayOfWeek();
boolean leapYear = LocalDate.now().isLeapYear();
localDateTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
String localDateString = localDateTime.format(DateTimeFormatter.ISO_DATE);Steps to connect to Firestore and query the tables:
- Add the following line of code as an attribute for the class:
Also need to add import statement for Firestore
FirebaseFirestore db = FirebaseFirestore.getInstance();
import com.google.firebase.firestore.FirebaseFirestore;
- (Optional) If we are referencing the same collection can add the following:
final CollectionReference collectionReference = db.collection(collectionName);
- Then need to define a Hashmap to be used as the data to be saved/added to the Database
HashMap<String, Object> data = new HashMap<>(); data.put("integer", 123); data.put("string", "hello world"); data.put("date", localdate);
- See the list of example queires below. Can also add OnSuccess/Failure Listeners
collectionReference .document(documentName) .set(data);
collectionReference .document(documentName) .delete();
- Whenever there is an update to the Database, add the following event listener to get the up to date information:
collectionReference.addSnapshotListener(this, new EventListener<QuerySnapshot>() { @Override public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) { for (QueryDocumentSnapshot doc : queryDocumentSnapshots){ // doc.getId() is the name/ID of the document // doc.getData().get(field_name) } } });
Mohammad's Ridebook
- Firebase Firestore
- Emoji Set