use of garbagecollectors.com.unipool.models.User in project UniPool by divya21raj.
the class UtilityMethods method populateChatMap.
public static Task populateChatMap(DataSnapshot pairUpSnapshot) {
final String[] userId = new String[1];
ArrayList<PairUp> pairUps = new ArrayList<>();
for (DataSnapshot dataSnapshot : pairUpSnapshot.getChildren()) pairUps.add(dataSnapshot.getValue(PairUp.class));
Task task = accessUserDatabase("users");
HashMap<String, User> finalChatMap = new HashMap<>();
task.addOnCompleteListener(aTask -> {
DataSnapshot snapshot = (DataSnapshot) task.getResult();
for (PairUp pairUp : pairUps) {
if (!(pairUp.getCreatorId().equals("dummy"))) {
if (pairUp.getCreatorId().equals(BaseActivity.getFinalCurrentUser().getUserId()))
userId[0] = pairUp.getRequesterId();
else
userId[0] = pairUp.getCreatorId();
User user = snapshot.child(userId[0]).getValue(User.class);
if (user != null) {
finalChatMap.put(user.getUserId(), user);
}
}
}
BaseActivity.setChatMap(finalChatMap);
});
return task;
}
use of garbagecollectors.com.unipool.models.User in project UniPool by divya21raj.
the class UtilityMethods method populateReceivedRequestsList.
public static Task populateReceivedRequestsList(ArrayList<TripEntry> receivedRequestsList, HashMap<String, ArrayList<String>> receivedRequestsMap, ArrayList<TripEntry> tripEntries) {
final TripEntry[] temp = new TripEntry[1];
// all users
Task userTask = accessUserDatabase("users");
userTask.addOnSuccessListener(aVoid -> {
DataSnapshot snapshot = (DataSnapshot) userTask.getResult();
for (Map.Entry<String, ArrayList<String>> entry : receivedRequestsMap.entrySet()) {
if (!(entry.getKey().equals("dummy"))) {
TripEntry tripEntry = getTripEntryFromList(entry.getKey(), tripEntries);
if (tripEntry != null) {
for (String userId : entry.getValue()) {
final User[] user = new User[1];
user[0] = snapshot.child(userId).getValue(User.class);
if (user[0] != null) {
temp[0] = new TripEntry(tripEntry);
temp[0].setName(user[0].getName());
temp[0].setUser_id(user[0].getUserId());
receivedRequestsList.add(temp[0]);
}
}
}
}
}
});
return userTask;
}
use of garbagecollectors.com.unipool.models.User in project UniPool by divya21raj.
the class HomeActivityTEA method sendRequest.
private void sendRequest(View view, int position) {
alertDialogBuilder.setMessage("Send request to " + list.get(position).getName() + " ?");
alertDialogBuilder.setPositiveButton("YES", (dialog, which) -> {
progressDialog = new ProgressDialog(view.getContext());
progressDialog.setMessage("Please wait...");
User user = BaseActivity.getFinalCurrentUser();
TripEntry tripEntry = list.get(position);
if (tripEntry.getUser_id().equals(user.getUserId())) {
Toast.makeText(view.getContext(), "Can't pool with yourself, that feature isn't ready yet...", Toast.LENGTH_SHORT).show();
return;
}
progressDialog.show();
final User[] tripEntryUser = new User[1];
// the user that created the clicked tripEntry
Task userTask = accessUserDatabase("users/" + tripEntry.getUser_id());
userTask.addOnSuccessListener(aVoid -> {
DataSnapshot snapshot = (DataSnapshot) userTask.getResult();
tripEntryUser[0] = snapshot.getValue(User.class);
DatabaseReference userDatabaseReference = FirebaseDatabase.getInstance().getReference(Globals.UNI + "users");
HashMap<String, TripEntry> requestSent = user.getRequestSent();
HashMap<String, ArrayList<String>> requestsReceived = tripEntryUser[0].getRequestsReceived();
isAlreadyRequested = addRequestInList(requestSent, user.getPairUps(), tripEntry);
if (!isAlreadyRequested) {
isRequestAlreadyInMap = putInMap(requestsReceived, tripEntry.getEntry_id(), user.getUserId());
}
user.setRequestSent(requestSent);
tripEntryUser[0].setRequestsReceived(requestsReceived);
if (!isAlreadyRequested && !isRequestAlreadyInMap) {
// update firebase database to include arrayList that contains name of the item_trip_entry clicked in requests sent...
Task<Void> task1 = userDatabaseReference.child(user.getUserId()).child("requestSent").setValue(requestSent);
Task<Void> task2 = userDatabaseReference.child(tripEntryUser[0].getUserId()).child("requestsReceived").setValue(requestsReceived);
HashMap<String, String> notificationObject = new HashMap<>();
notificationObject.put("from", user.getUserId());
notificationObject.put("type", "requestCreated");
Task<Void> task3 = Globals.notificationDatabaseReference.child(tripEntryUser[0].getUserId()).push().setValue(notificationObject);
Task<Void> allTask = Tasks.whenAll(task1, task2, task3);
allTask.addOnSuccessListener(bVoid -> {
progressDialog.dismiss();
BaseActivity.setFinalCurrentUser(user);
Toast.makeText(view.getContext(), "Request Sent!", Toast.LENGTH_LONG).show();
});
allTask.addOnFailureListener(e -> {
progressDialog.dismiss();
// apologize profusely to the user!
Toast.makeText(view.getContext(), "FAIL", Toast.LENGTH_LONG).show();
});
} else {
progressDialog.dismiss();
Toast.makeText(view.getContext(), "You two are already paired up!", Toast.LENGTH_LONG).show();
}
});
});
alertDialogBuilder.setNegativeButton("NO", (dialog, which) -> dialog.dismiss());
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
use of garbagecollectors.com.unipool.models.User in project UniPool by divya21raj.
the class UserAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull MyHolder holder, int position) {
User user = userList.get(position);
UtilityMethods.fillUserHolder(holder, user);
holder.itemView.setOnClickListener(view -> {
// TreeMap<Long, Message> messageMap = UtilityMethods.getPersonalMessageMap(BaseActivity.getMessages(), user.getUserId());
MessageListActivity.setChatUser(user);
MessageListActivity.setName(UtilityMethods.sanitizeName(user.getName()));
// MessageListActivity.setPersonalMessageMap(messageMap);
MessageListActivity.setPairUp(UtilityMethods.getPairUp(user, BaseActivity.getFinalCurrentUser().getPairUps()));
context.startActivity(new Intent(context, MessageListActivity.class));
});
}
use of garbagecollectors.com.unipool.models.User in project UniPool by divya21raj.
the class ReceivedRequestsTEA method onBindViewHolder.
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(@NonNull MyHolder holder, int position) {
requestsProgressDialog = new ProgressDialog(context);
requestsProgressDialog.setMessage("Please wait...");
requestsProgressDialog.show();
holder.cardArrow.setVisibility(View.GONE);
holder.messageCard.setVisibility(View.GONE);
MessageDBTask.addOnCompleteListener(o -> requestsProgressDialog.dismiss());
MessageDBTask.addOnFailureListener(o -> requestsProgressDialog.dismiss());
holder.requestButton.setOnClickListener(view -> {
DatabaseReference userDatabaseReference = FirebaseDatabase.getInstance().getReference(Globals.UNI + "users");
DatabaseReference pairUpDatabaseReference = Globals.pairUpDatabaseReference;
DatabaseReference notificationDatabaseReference = Globals.notificationDatabaseReference;
TripEntry tripEntry = list.get(position);
User finalCurrentUser = BaseActivity.getFinalCurrentUser();
HashMap<String, PairUp> currentUserPairUps = finalCurrentUser.getPairUps();
HashMap<String, ArrayList<String>> finalCurrentUserReceivedRequests = finalCurrentUser.getRequestsReceived();
ReceivedRequestsFragment.alertDialogBuilder.setPositiveButton("YES", (dialog, which) -> {
requestsProgressDialog.show();
final User[] tripEntryUser = new User[1];
// the user that created the clicked tripEntry
Task userTask = accessUserDatabase("users/" + tripEntry.getUser_id());
userTask.addOnSuccessListener(aVoid -> {
DataSnapshot snapshot = (DataSnapshot) userTask.getResult();
tripEntryUser[0] = snapshot.getValue(User.class);
HashMap<String, PairUp> tripEntryUserPairUps = null;
if (tripEntryUser[0] != null)
tripEntryUserPairUps = tripEntryUser[0].getPairUps();
else
Toast.makeText(context, "Problems! Please try again...", Toast.LENGTH_LONG);
HashMap<String, TripEntry> tripEntryUserSentRequests = tripEntryUser[0].getRequestSent();
String pairUpId = finalCurrentUser.getUserId() + tripEntryUser[0].getUserId();
String[] timeParts = tripEntry.getTime().split(":");
// give them 4 hours
timeParts[0] = String.valueOf((Integer.parseInt(timeParts[0]) + 4) % 24);
String expiryDate = tripEntry.getDate() + "/" + timeParts[0] + "/" + timeParts[1];
PairUp pairUp = new PairUp(pairUpId, finalCurrentUser.getUserId(), tripEntryUser[0].getUserId(), expiryDate, new ArrayList<>());
pairUp.getMessages().add("def@ult");
isAlreadyInList = UtilityMethods.addPairUpInMap(currentUserPairUps, pairUp);
if (!isAlreadyInList) {
UtilityMethods.addPairUpInMap(tripEntryUserPairUps, pairUp);
UtilityMethods.removeFromMap(finalCurrentUserReceivedRequests, tripEntry.getEntry_id(), tripEntryUser[0].getUserId());
tripEntryUserSentRequests.remove(tripEntry.getEntry_id());
finalCurrentUser.setRequestsReceived(finalCurrentUserReceivedRequests);
finalCurrentUser.setPairUps(currentUserPairUps);
BaseActivity.setFinalCurrentUser(finalCurrentUser);
HashMap<String, String> notificationObject = new HashMap<>();
notificationObject.put("from", finalCurrentUser.getUserId());
notificationObject.put("type", "requestAccepted");
Task<Void> task1 = userDatabaseReference.child(finalCurrentUser.getUserId()).child("pairUps").setValue(currentUserPairUps);
Task<Void> task2 = userDatabaseReference.child(tripEntryUser[0].getUserId()).child("pairUps").setValue(tripEntryUserPairUps);
Task<Void> task3 = userDatabaseReference.child(finalCurrentUser.getUserId()).child("requestsReceived").setValue(finalCurrentUserReceivedRequests);
Task<Void> task4 = userDatabaseReference.child(tripEntryUser[0].getUserId()).child("requestSent").setValue(tripEntryUserSentRequests);
Task<Void> task5 = pairUpDatabaseReference.child(pairUpId).setValue(pairUp);
Task<Void> task6 = notificationDatabaseReference.child(tripEntryUser[0].getUserId()).push().setValue(notificationObject);
Task<Void> allTask = Tasks.whenAll(task1, task2, task3, task4, task5, task6);
allTask.addOnSuccessListener(bVoid -> {
tripEntry.setEntry_id("dummyId");
userDatabaseReference.child((tripEntryUser[0]).getUserId()).child("requestSent").child("dummyId").setValue(tripEntry);
BaseActivity.getChatMap().put(tripEntryUser[0].getUserId(), tripEntryUser[0]);
requestsProgressDialog.dismiss();
// RequestActivity.refreshRequests(context);
Intent intent = new Intent(context, RequestActivity.class);
intent.putExtra("openingTab", 2);
((Activity) context).finish();
context.startActivity(intent);
((Activity) context).overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
});
allTask.addOnFailureListener(e -> {
requestsProgressDialog.dismiss();
// apologize profusely to the user!
Toast.makeText(view.getContext(), "FAIL", Toast.LENGTH_LONG).show();
});
}
dialog.dismiss();
});
});
ReceivedRequestsFragment.alertDialogBuilder.setNegativeButton("NO", (dialog, which) -> dialog.dismiss());
AlertDialog alert = ReceivedRequestsFragment.alertDialogBuilder.create();
alert.show();
});
TripEntry tripEntry = list.get(position);
UtilityMethods.fillTripEntryHolder(holder, tripEntry);
}
Aggregations