use of garbagecollectors.com.unipool.models.PairUp in project UniPool by divya21raj.
the class UtilityMethods method getMessageList.
public static List<Message> getMessageList(HashMap<String, ArrayList<Message>> messages, String userId) {
ArrayList<Message> personalMessageList;
HashMap<String, PairUp> pairUpList = BaseActivity.getFinalCurrentUser().getPairUps();
String pairUpId = null;
for (Map.Entry<String, PairUp> entry : pairUpList.entrySet()) {
PairUp pairUp = entry.getValue();
if (pairUp.getCreatorId().equals(userId) || pairUp.getRequesterId().equals(userId)) {
pairUpId = pairUp.getPairUpId();
break;
}
}
List messageList = messages.get(pairUpId);
if (messageList != null)
personalMessageList = new ArrayList<>(messages.get(pairUpId));
else {
personalMessageList = new ArrayList<>();
messages.put(pairUpId, personalMessageList);
}
return personalMessageList;
}
use of garbagecollectors.com.unipool.models.PairUp 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.PairUp 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);
}
use of garbagecollectors.com.unipool.models.PairUp in project UniPool by divya21raj.
the class LoginActivity method dummyInitFinalCurrentUser.
private void dummyInitFinalCurrentUser(FirebaseUser user) {
GenLocation dummyGenLocation = new GenLocation("dummy", "dummy", 0d, 0d);
TripEntry dummyTripEntry = new TripEntry("dummy", "dummyId", "DummyUser", "12:00", "1/11/12", dummyGenLocation, dummyGenLocation, "dummyMessage", "", "", true);
HashMap<String, TripEntry> dummyUserEntries = new HashMap<>();
dummyUserEntries.put("dummy", dummyTripEntry);
HashMap<String, TripEntry> dummyRequestSent = new HashMap<>();
dummyRequestSent.put(dummyTripEntry.getEntry_id(), dummyTripEntry);
ArrayList<String> dummyUserIdList = new ArrayList<>();
dummyUserIdList.add("dummy");
HashMap<String, ArrayList<String>> dummyRequestReceived = new HashMap<>();
dummyRequestReceived.put("dummy", dummyUserIdList);
PairUp dummyPairUp = new PairUp("dummydummy", "dummy", "dummy", "dummy", dummyUserIdList);
HashMap<String, PairUp> dummyPairUps = new HashMap<>();
dummyPairUps.put("dummy", dummyPairUp);
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(instanceIdResult -> {
String deviceToken = instanceIdResult.getToken();
String url = "";
Uri photoUrl = user.getPhotoUrl();
if (photoUrl != null)
url = photoUrl.toString();
finalCurrentUser = new User(user.getUid(), user.getDisplayName(), url, user.getEmail(), dummyUserEntries, dummyRequestSent, dummyRequestReceived, deviceToken, true, dummyPairUps);
});
}
Aggregations