Search in sources :

Example 1 with TripEntry

use of garbagecollectors.com.unipool.models.TripEntry 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;
}
Also used : Task(com.google.android.gms.tasks.Task) User(garbagecollectors.com.unipool.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) ArrayList(java.util.ArrayList) TripEntry(garbagecollectors.com.unipool.models.TripEntry) DataSnapshot(com.google.firebase.database.DataSnapshot) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 2 with TripEntry

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

the class NewEntryDialog method finalSave.

public void finalSave() {
    String entryId = Globals.entryDatabaseReference.push().getKey();
    String name = UtilityMethods.sanitizeName(finalCurrentUser.getName());
    System.currentTimeMillis();
    message = messageText.getText().toString();
    if (message.isEmpty())
        message = null;
    TripEntry tripEntry = new TripEntry(name, entryId, finalCurrentUser.getUserId(), time, date, source, destination, message, "", finalCurrentUser.getEmail(), false);
    finalCurrentUser.getUserTripEntries().put(tripEntry.getEntry_id(), tripEntry);
    Globals.entryDatabaseReference.child(entryId).setValue(tripEntry);
    Globals.userDatabaseReference.child("userTripEntries").setValue(finalCurrentUser.getUserTripEntries());
    Toast.makeText(getActivity(), "Trip entry created!", Toast.LENGTH_SHORT).show();
    dismiss();
}
Also used : TripEntry(garbagecollectors.com.unipool.models.TripEntry)

Example 3 with TripEntry

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

the class SplashActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    ImageView splashLogo = findViewById(R.id.splashLogo);
    splashLogo.setBackgroundResource(R.drawable.loading_animation);
    loadingAnimation = (AnimationDrawable) splashLogo.getBackground();
    loadingAnimation.start();
    // check if update required
    ForceUpdateChecker.with(this).onUpdateNeeded(this).check();
    mAuth = FirebaseAuth.getInstance();
    currentUser = mAuth.getCurrentUser();
    // For Oreo and above
    createNotificationChannel();
    UtilityMethods.fillGlobalVariables(getApplicationContext());
    BaseActivity.setCurrentUser(currentUser);
    Globals.userDatabaseReference = FirebaseDatabase.getInstance().getReference(Globals.UNI + "users/" + currentUser.getUid());
    Globals.messageDatabaseReference = FirebaseDatabase.getInstance().getReference(Globals.UNI + "messages/" + currentUser.getUid());
    Handler handler = new Handler();
    handler.postDelayed(() -> timerSource.setResult(null), 12345);
    Globals.userDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            UserDBSource.setResult(dataSnapshot);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            UserDBSource.setException(databaseError.toException());
            Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
        }
    });
    Globals.entryDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            EntryDBSource.setResult(dataSnapshot);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            EntryDBSource.setException(databaseError.toException());
            Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
        }
    });
    Task<Void> allTask = Tasks.whenAll(UserDBTask, EntryDBTask);
    allTask.addOnSuccessListener(aVoid -> {
        handler.removeCallbacksAndMessages(null);
        DataSnapshot userData = (DataSnapshot) UserDBTask.getResult();
        DataSnapshot entryData = (DataSnapshot) EntryDBTask.getResult();
        for (DataSnapshot dataSnapshot : entryData.getChildren()) {
            TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
            UtilityMethods.updateTripList(tripEntryList, tripEntry, true);
        }
        if (!(LoginActivity.userNewOnDatabase))
            BaseActivity.setFinalCurrentUser(userData.getValue(User.class));
        Task chatListTask = UtilityMethods.populateChatMap(userData.child("pairUps"));
        Globals.messageDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                try {
                    MessageDBSource.setResult(dataSnapshot);
                } catch (IllegalStateException ignored) {
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                MessageDBSource.setException(databaseError.toException());
                Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
            }
        });
        chatListTask.addOnCompleteListener(task1 -> {
            if (canProceed) {
                finish();
                startActivity(new Intent(getApplicationContext(), HomeActivity.class));
            }
        });
    });
    allTask.addOnFailureListener(e -> {
        // apologize profusely to the user!
        Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
    });
    timerTask.addOnCompleteListener(task -> {
        if (timerTask.getResult() == null)
            Toast.makeText(this, "Network not that good, I'm trying...", Toast.LENGTH_LONG).show();
    });
}
Also used : Task(com.google.android.gms.tasks.Task) Handler(android.os.Handler) TripEntry(garbagecollectors.com.unipool.models.TripEntry) Intent(android.content.Intent) DataSnapshot(com.google.firebase.database.DataSnapshot) DatabaseError(com.google.firebase.database.DatabaseError) ImageView(android.widget.ImageView) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 4 with TripEntry

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

the class SentRequestsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_sent_requests, container, false);
    finalCurrentUser = RequestActivity.getFinalCurrentUser();
    sentRequests = finalCurrentUser.getRequestSent();
    recycle = view.findViewById(R.id.recycle_requests);
    if (sentRequests.size() >= 1) {
        ArrayList<TripEntry> sentRequestsList = new ArrayList<>();
        for (Map.Entry<String, TripEntry> entry : sentRequests.entrySet()) {
            if (!entry.getKey().equals("dummyId"))
                sentRequestsList.add(entry.getValue());
        }
        recyclerAdapter = new SentRequestsTEA(sentRequestsList, getContext());
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 1);
        recycle.setLayoutManager(layoutManager);
        recycle.setItemAnimator(new DefaultItemAnimator());
        recycle.setAdapter(recyclerAdapter);
    }
    return view;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SentRequestsTEA(garbagecollectors.com.unipool.adapters.SentRequestsTEA) ArrayList(java.util.ArrayList) TripEntry(garbagecollectors.com.unipool.models.TripEntry) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) HashMap(java.util.HashMap) Map(java.util.Map) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 5 with TripEntry

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

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