use of com.google.firebase.firestore.QueryDocumentSnapshot in project turtleparties by CMPUT301W22T21.
the class PlayerController method getLeaderboardStatsFromFireBase.
public HashMap<String, Integer> getLeaderboardStatsFromFireBase(String find) {
HashMap<String, Integer> qrscore = new HashMap<>();
HashMap<String, Integer> score = new HashMap<>();
HashMap<String, Integer> sum = new HashMap<>();
db.collection("Users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot doc : task.getResult()) {
String name = doc.getId();
db.collection("Users").document(name).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot doc = task.getResult();
Integer highestqr = null;
Integer qrcount = null;
Integer qrsum = null;
// Highest sum
try {
qrsum = ((Number) doc.getData().get("qrSum")).intValue();
sum.put(name, qrsum);
} catch (Exception e) {
sum.put(name, 0);
}
// Highest score
try {
highestqr = ((Number) doc.getData().get("qrHighest")).intValue();
score.put(name, highestqr);
} catch (Exception e) {
score.put(name, 0);
}
// Highest scan amount
try {
qrcount = ((Number) doc.getData().get("qrCount")).intValue();
qrscore.put(name, qrcount);
} catch (Exception e) {
qrscore.put(name, 0);
}
Log.d("LEADERBOARD_DEBUG", highestqr + " " + qrcount + " " + qrsum);
// personAdapter.notifyDataSetChanged();
}
}
});
}
}
}
});
if (find == "score") {
return score;
} else if (find == "sum") {
return sum;
} else if (find == "qr") {
return qrscore;
} else {
return null;
}
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project turtleparties by CMPUT301W22T21.
the class QRInfo method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qrinfo);
view = this.findViewById(android.R.id.content);
Intent intent = getIntent();
Bundle qrBundle = intent.getBundleExtra(MainActivity.EXTRA_QR);
thisQr = (ScoreQrcode) qrBundle.getSerializable("qrcode");
user = (Player) qrBundle.getSerializable("user");
showDeleteButton = (boolean) qrBundle.getSerializable("showDeleteButton");
Double lat = (Double) qrBundle.getSerializable("lat");
Double lon = (Double) qrBundle.getSerializable("lon");
String qrname = thisQr.getCode();
thisQr.generateQRimage();
db = FirebaseFirestore.getInstance();
final CollectionReference collectionReference = db.collection("QR codes");
qrImage = view.findViewById(R.id.qr_imageView);
scoreView = view.findViewById(R.id.score_info_view);
locationView = view.findViewById(R.id.location_view);
deleteButton = view.findViewById(R.id.deleteQrButton);
if (thisQr.isToShow()) {
qrImage.setImageBitmap(thisQr.getMyBitmap());
} else {
qrImage.setImageResource(R.drawable.ic_baseline_qr_code_24);
}
scoreView.setText(String.valueOf(thisQr.getScore()));
if (lat != 0.0) {
locationView.setText(String.valueOf(lat + "° N " + lon + "° W"));
} else {
locationView.setText("n/a");
}
if (!showDeleteButton) {
deleteButton.setVisibility(view.INVISIBLE);
}
commentList = findViewById(R.id.comment_list);
commentDataList = new ArrayList<>();
commentAdapter = new QRCommentList(this, commentDataList);
commentList.setAdapter(commentAdapter);
collectionReference.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException error) {
db.collection("QR codes").document(qrname).collection("comments").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot doc : task.getResult()) {
String username = doc.getId();
Log.d(TAG, username);
db.collection("QR codes").document(qrname).collection("comments").document(username).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot doc = task.getResult();
String userComment = (String) doc.getData().get("comment");
commentDataList.add((new Comment(userComment, username)));
Log.d(TAG, userComment + " " + username);
commentAdapter.notifyDataSetChanged();
}
}
});
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
commentAdapter.notifyDataSetChanged();
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class EventFragment method populateParticipantList.
private void populateParticipantList(int startIdx, int endIdx) {
Log.d(TAG, "populateParticipantList: ");
participants.clear();
db.collection("users").whereIn(FieldPath.documentId(), eventInfo.getParticipants().subList(startIdx, endIdx)).get().addOnCompleteListener(participantTask -> {
Log.d(TAG, "READ DATABASE - EVENT FRAGMENT");
if (participantTask.isSuccessful()) {
List<UsersDataModel> tempList = new ArrayList<>();
for (QueryDocumentSnapshot userDoc : participantTask.getResult()) {
UsersDataModel userData = userDoc.toObject(UsersDataModel.class);
tempList.add(userData);
}
participants.addAll(tempList);
checkParticipantsEmpty();
Log.d(TAG, "populateParticipantList: " + participants.size());
eventRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.w(TAG, "populateParticipantList: Participant data failed to query", participantTask.getException());
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class EventGroupFragment method populateEventList.
private void populateEventList() {
db.collection("events").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).orderBy("event_time", Query.Direction.ASCENDING).whereGreaterThanOrEqualTo("event_time", Timestamp.now()).get().addOnCompleteListener(eventTask -> {
Log.d(TAG, "READ DATABASE - EVENT GROUP FRAGMENT");
if (eventTask.isSuccessful()) {
ArrayList<EventsDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot eventDoc : eventTask.getResult()) {
EventsDataModel eventDataModel = eventDoc.toObject(EventsDataModel.class);
temp.add(eventDataModel);
}
Log.d(TAG, "populateEventList: " + temp.size());
listOfEvents.clear();
listOfEvents.addAll(temp);
checkEventsEmpty();
eventGroupRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.d(TAG, "db get failed in event page " + eventTask.getException());
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class HomeFragment method populateIncidents.
/**
* Displays the active incidents
*/
private void populateIncidents() {
db.collection("incident").whereArrayContains(FirestoreDatabase.FIELD_FIRE_DEPARTMENTS, activeUser.getFire_department_id()).whereEqualTo("incident_complete", false).get().addOnCompleteListener(incidentTask -> {
Log.d(TAG, "READ DATABASE - HOME FRAGMENT (populateIncidents)");
if (incidentTask.isSuccessful()) {
ArrayList<IncidentDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot incidentDoc : incidentTask.getResult()) {
IncidentDataModel incidentDataModel = incidentDoc.toObject(IncidentDataModel.class);
temp.add(incidentDataModel);
}
listOfIncidentDataModel.clear();
listOfIncidentDataModel.addAll(temp);
incidentRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.d(TAG, "get failed in HomeFragment with " + incidentTask.getException());
}
});
}
Aggregations