Search in sources :

Example 16 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.

the class ReportGroupFragment method populateReports.

private void populateReports() {
    db.collection("reports").whereEqualTo("user_created_id", activeUser.getDocumentId()).get().addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            ArrayList<ReportDataModel> temp = new ArrayList<>();
            for (QueryDocumentSnapshot reportDoc : task.getResult()) {
                ReportDataModel reportDataModel = reportDoc.toObject(ReportDataModel.class);
                temp.add(reportDataModel);
            }
            reports.clear();
            reports.addAll(temp);
            checkReportsEmpty();
            reportGroupRecyclerViewAdapter.notifyDataSetChanged();
        } else {
            Log.w(TAG, "onCreateView: get failed in HomeFragment with", task.getException());
        }
    });
}
Also used : ReportDataModel(com.example.first_responder_app.dataModels.ReportDataModel) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 17 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.

the class AnnouncementFragment method populateAnnouncmentList.

private void populateAnnouncmentList() {
    Task getAnnoucementsForGroups = db.collection("announcements").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereIn("intended_group_id", activeUser.getGroup_ids()).orderBy(FirestoreDatabase.FIELD_CREATED_AT, Query.Direction.DESCENDING).get();
    Task getAnnouncementsForAll = db.collection("announcements").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereEqualTo("intended_group_id", null).orderBy(FirestoreDatabase.FIELD_CREATED_AT, Query.Direction.DESCENDING).get();
    Tasks.whenAllSuccess(getAnnoucementsForGroups, getAnnouncementsForAll).addOnSuccessListener(objects -> {
        ArrayList<AnnouncementsDataModel> temp = new ArrayList<>();
        for (Object fakeQuerySnapshot : objects) {
            QuerySnapshot querySnapshot = ((QuerySnapshot) fakeQuerySnapshot);
            for (QueryDocumentSnapshot announcementDoc : querySnapshot) {
                AnnouncementsDataModel announcementDataModel = announcementDoc.toObject(AnnouncementsDataModel.class);
                temp.add(announcementDataModel);
            }
        }
        listOfAnnouncements.clear();
        listOfAnnouncements.addAll(temp);
        checkAnnouncementEmpty();
        announcementAdapter.notifyDataSetChanged();
    }).addOnFailureListener(e -> Log.e(TAG, "populateAnnouncmentList: db get failed in announcement page", e));
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Query(com.google.firebase.firestore.Query) Task(com.google.android.gms.tasks.Task) NavController(androidx.navigation.NavController) ArrayList(java.util.ArrayList) AnnouncementViewModel(com.example.first_responder_app.viewModels.AnnouncementViewModel) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) FragmentAnnouncementBinding(com.example.first_responder_app.databinding.FragmentAnnouncementBinding) RecyclerView(androidx.recyclerview.widget.RecyclerView) TAG(android.content.ContentValues.TAG) Log(android.util.Log) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) AnnouncementRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.AnnouncementRecyclerViewAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) AppUtil(com.example.first_responder_app.AppUtil) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) ViewGroup(android.view.ViewGroup) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) List(java.util.List) Nullable(androidx.annotation.Nullable) Tasks(com.google.android.gms.tasks.Tasks) Navigation(androidx.navigation.Navigation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AnnouncementsDataModel(com.example.first_responder_app.dataModels.AnnouncementsDataModel) Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) AnnouncementsDataModel(com.example.first_responder_app.dataModels.AnnouncementsDataModel) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 18 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.

the class ChatGroupFragment method populateChatList.

private void populateChatList() {
    db.collection("chat").get().addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            ArrayList<Chat> temp = new ArrayList<>();
            for (QueryDocumentSnapshot doc : task.getResult()) {
                ArrayList<String> members = (ArrayList<String>) doc.get("members");
                if (user != null) {
                    String memberName = user.getFirst_name() + " " + user.getLast_name() + "/" + user.getDocumentId();
                    if (members.contains(memberName)) {
                        Timestamp t = (Timestamp) doc.get("most_recent_message_time");
                        Chat chat = new Chat(doc.getId(), (String) doc.get("most_recent_message"), members, (String) doc.get("chat_name"), t);
                        temp.add(chat);
                    }
                }
            }
            listOfChats.clear();
            listOfChats.addAll(temp);
            Collections.sort(listOfChats);
            Collections.reverse(listOfChats);
            chatGroupRecyclerViewAdapter.notifyDataSetChanged();
        } else {
            Log.d(TAG, "db get failed in chat group page " + task.getException());
        }
    });
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Chat(com.example.first_responder_app.messaging.Chat) ArrayList(java.util.ArrayList) Timestamp(com.google.firebase.Timestamp)

Example 19 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project host-me by host-me-app.

the class EmailValidator method getEmailFromDataBase.

/**
 * Fetch emails from the database
 *
 * @return Emails from accounts in the database
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws TimeoutException
 */
private static List<String> getEmailFromDataBase() throws ExecutionException, InterruptedException, TimeoutException {
    List<String> emails = new ArrayList<>();
    Task<QuerySnapshot> task = DB.collection("users").get();
    Tasks.await(task, 5000, TimeUnit.MILLISECONDS);
    for (QueryDocumentSnapshot document : task.getResult()) {
        emails.add(document.getString("email"));
    }
    Log.i("DB", emails.toString());
    return emails;
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 20 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirebaseUI-Android by firebase.

the class FirestoreArray method onDocumentAdded.

private void onDocumentAdded(DocumentChange change) {
    QueryDocumentSnapshot snapshot = change.getDocument();
    mSnapshots.add(change.getNewIndex(), snapshot);
    notifyOnChildChanged(ChangeEventType.ADDED, snapshot, change.getNewIndex(), -1);
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot)

Aggregations

QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)73 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)33 ArrayList (java.util.ArrayList)30 View (android.view.View)22 NonNull (androidx.annotation.NonNull)19 Task (com.google.android.gms.tasks.Task)18 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)17 Intent (android.content.Intent)16 CollectionReference (com.google.firebase.firestore.CollectionReference)13 AdapterView (android.widget.AdapterView)12 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)12 TextView (android.widget.TextView)10 Bundle (android.os.Bundle)9 ListView (android.widget.ListView)9 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)9 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)8 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 FirebaseUser (com.google.firebase.auth.FirebaseUser)6 DocumentReference (com.google.firebase.firestore.DocumentReference)6