Search in sources :

Example 6 with TripEntry

use of garbagecollectors.com.unipool.models.TripEntry in project UniPool by divya21raj.

the class HomeActivityTEA method filter.

public void filter(String text) {
    list.clear();
    if (text.isEmpty())
        list.addAll(listCopy);
    else {
        text = text.toLowerCase();
        for (TripEntry tripEntry : listCopy) {
            String name = tripEntry.getName().toLowerCase();
            String destination = tripEntry.getDestination().getName().toLowerCase();
            String source = tripEntry.getSource().getName().toLowerCase();
            String time = tripEntry.getTime();
            String date = tripEntry.getDate();
            if (name.contains(text) || destination.contains(text) || source.contains(text) || time.contains(text) || date.contains(text))
                list.add(tripEntry);
        }
    }
    notifyDataSetChanged();
}
Also used : TripEntry(garbagecollectors.com.unipool.models.TripEntry)

Example 7 with TripEntry

use of garbagecollectors.com.unipool.models.TripEntry in project UniPool by divya21raj.

the class SentRequestsTEA method onBindViewHolder.

// Replace the contents of a view (invoked by the layout manager)
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onBindViewHolder(MyHolder holder, int position) {
    TripEntry tripEntry = list.get(position);
    UtilityMethods.fillTripEntryHolder(holder, tripEntry);
    holder.cardArrow.setOnClickListener(v -> {
        if (holder.tripEntryExpand.isExpanded()) {
            holder.tripEntryExpand.collapse();
            holder.cardArrow.setImageResource(R.drawable.ic_arrow_left_24px);
        } else {
            holder.tripEntryExpand.expand();
            holder.cardArrow.setImageResource(R.drawable.ic_arrow_drop_down_circle_24px);
        }
    });
    holder.requestButton.setVisibility(View.INVISIBLE);
}
Also used : TripEntry(garbagecollectors.com.unipool.models.TripEntry) RequiresApi(android.support.annotation.RequiresApi)

Example 8 with TripEntry

use of garbagecollectors.com.unipool.models.TripEntry in project UniPool by divya21raj.

the class HomeActivityTEA method onRequestClick.

private void onRequestClick(View view, int position) {
    TripEntry tripEntry = list.get(position);
    if (tripEntry.isNotFromApp())
        if (tripEntry.getPhone() != null && !tripEntry.getPhone().isEmpty())
            addToContacts(tripEntry);
        else
            writeMail(tripEntry);
    else {
        if (tripEntry.getUser_id().equals(BaseActivity.getFinalCurrentUser().getUserId()))
            deleteEntry(view, position);
        else
            sendRequest(view, position);
    }
}
Also used : TripEntry(garbagecollectors.com.unipool.models.TripEntry)

Example 9 with TripEntry

use of garbagecollectors.com.unipool.models.TripEntry 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);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Task(com.google.android.gms.tasks.Task) MessageDBTask(garbagecollectors.com.unipool.activities.SplashActivity.MessageDBTask) User(garbagecollectors.com.unipool.models.User) DatabaseReference(com.google.firebase.database.DatabaseReference) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RequestActivity(garbagecollectors.com.unipool.activities.RequestActivity.RequestActivity) BaseActivity(garbagecollectors.com.unipool.activities.BaseActivity) Activity(android.app.Activity) TripEntry(garbagecollectors.com.unipool.models.TripEntry) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) DataSnapshot(com.google.firebase.database.DataSnapshot) PairUp(garbagecollectors.com.unipool.models.PairUp)

Example 10 with TripEntry

use of garbagecollectors.com.unipool.models.TripEntry 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);
    });
}
Also used : User(garbagecollectors.com.unipool.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) BaseActivity.finalCurrentUser(garbagecollectors.com.unipool.activities.BaseActivity.finalCurrentUser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PairUp(garbagecollectors.com.unipool.models.PairUp) TripEntry(garbagecollectors.com.unipool.models.TripEntry) GenLocation(garbagecollectors.com.unipool.models.GenLocation) Uri(android.net.Uri)

Aggregations

TripEntry (garbagecollectors.com.unipool.models.TripEntry)11 Task (com.google.android.gms.tasks.Task)5 DataSnapshot (com.google.firebase.database.DataSnapshot)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 User (garbagecollectors.com.unipool.models.User)4 ProgressDialog (android.app.ProgressDialog)3 AlertDialog (android.support.v7.app.AlertDialog)3 Intent (android.content.Intent)2 FirebaseUser (com.google.firebase.auth.FirebaseUser)2 DatabaseError (com.google.firebase.database.DatabaseError)2 DatabaseReference (com.google.firebase.database.DatabaseReference)2 ValueEventListener (com.google.firebase.database.ValueEventListener)2 PairUp (garbagecollectors.com.unipool.models.PairUp)2 Map (java.util.Map)2 Activity (android.app.Activity)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 RequiresApi (android.support.annotation.RequiresApi)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1