From 78b7d28d2124c5e44266b17d417541297f2bd925 Mon Sep 17 00:00:00 2001 From: yashtomar31 Date: Wed, 6 Nov 2019 10:11:33 +0530 Subject: [PATCH 1/3] Adding code to remove the proposals whose time has expired --- .../sahayak/JavaClasses/ProposalLab.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java index c7e60c8..3864b7f 100644 --- a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java +++ b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java @@ -8,21 +8,29 @@ import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.database.ChildEventListener; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.ValueEventListener; +import com.google.gson.internal.bind.DateTypeAdapter; +import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import static com.mobilecomputing.sahayak.Fragments.proposalShowFragment.TAG; + public class ProposalLab { private static ProposalLab sproposalLab; private List mProposals = new ArrayList<>(); private DatabaseReference mDatabase; private ProgressBar progressBar; + DatabaseReference mRef; + FirebaseDatabase mFirebaseDatabase; private ProposalLab(final Context context) { mDatabase = FirebaseDatabase.getInstance().getReference("active_proposals"); @@ -62,9 +70,30 @@ public void AddProposal(Proposal proposal) { // TODO: Handle Duplicates dref.setValue(proposal); } + public void deleteProposals(){ + mDatabase = FirebaseDatabase.getInstance().getReference("active_proposals"); + mDatabase.orderByChild("startDate").addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + for (DataSnapshot proposalSnapshot: dataSnapshot.getChildren()) { + Proposal proposal=proposalSnapshot.getValue(Proposal.class); + Log.d(TAG,new Date().toString()+ " -----"+ proposal.getStartDate().toString()); + if(proposal.getStartDate().before(new Date())){ + Log.d(TAG,"before"); + proposalSnapshot.getRef().removeValue(); + } + } + } @Override + public void onCancelled(DatabaseError databaseError) { + + } + + }); + } public List getProposals() { Log.d("ProposalLab", "Getting " + mProposals.size() + " Proposals " + mProposals.getClass().getSimpleName()); + this.deleteProposals(); return mProposals; } From 0e6a8bc1bd1465fdcfcb982588bf4a0909324dd6 Mon Sep 17 00:00:00 2001 From: yashtomar31 Date: Wed, 6 Nov 2019 10:29:12 +0530 Subject: [PATCH 2/3] Adding code to remove the propsals of the currentUser --- .../mobilecomputing/sahayak/JavaClasses/ProposalLab.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java index 3864b7f..1ee9d95 100644 --- a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java +++ b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java @@ -3,6 +3,7 @@ import android.content.Context; import android.util.Log; import android.widget.ProgressBar; +import android.widget.TableLayout; import androidx.annotation.NonNull; @@ -40,8 +41,12 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) { mProposals.clear(); if (dataSnapshot.exists()) { for (DataSnapshot ds : dataSnapshot.getChildren()) { + FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser(); Proposal p = ds.getValue(Proposal.class); - mProposals.add(p); + Log.d(TAG,p.getMentorName()+"----"+ currentUser.getEmail()); + if(!p.getMentorName().equals(currentUser.getEmail())){ + mProposals.add(p); + } } } } @@ -89,8 +94,8 @@ public void onCancelled(DatabaseError databaseError) { } }); - } + } public List getProposals() { Log.d("ProposalLab", "Getting " + mProposals.size() + " Proposals " + mProposals.getClass().getSimpleName()); this.deleteProposals(); From e636e58ccbf7c6d7fb7b828e8f612d3a972023fd Mon Sep 17 00:00:00 2001 From: yashtomar31 Date: Wed, 6 Nov 2019 10:51:16 +0530 Subject: [PATCH 3/3] Adding duration factor --- .../mobilecomputing/sahayak/JavaClasses/ProposalLab.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java index 1ee9d95..09bf618 100644 --- a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java +++ b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java @@ -19,6 +19,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -82,8 +83,11 @@ public void deleteProposals(){ public void onDataChange(DataSnapshot dataSnapshot) { for (DataSnapshot proposalSnapshot: dataSnapshot.getChildren()) { Proposal proposal=proposalSnapshot.getValue(Proposal.class); - Log.d(TAG,new Date().toString()+ " -----"+ proposal.getStartDate().toString()); - if(proposal.getStartDate().before(new Date())){ + Calendar endCalendar = Calendar.getInstance(); + endCalendar.setTime(proposal.getStartDate()); + endCalendar.add(Calendar.MINUTE, proposal.getDuration()); + Log.d(TAG,new Date().toString()+ " -----"+ endCalendar.getTime()); + if(endCalendar.getTime().before(new Date())){ Log.d(TAG,"before"); proposalSnapshot.getRef().removeValue(); }