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..09bf618 100644 --- a/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java +++ b/app/src/main/java/com/mobilecomputing/sahayak/JavaClasses/ProposalLab.java @@ -3,26 +3,36 @@ import android.content.Context; import android.util.Log; import android.widget.ProgressBar; +import android.widget.TableLayout; import androidx.annotation.NonNull; 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.Calendar; +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"); @@ -32,8 +42,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); + } } } } @@ -62,9 +76,33 @@ 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); + 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(); + } + } + } @Override + public void onCancelled(DatabaseError databaseError) { + } + + }); + + } public List getProposals() { Log.d("ProposalLab", "Getting " + mProposals.size() + " Proposals " + mProposals.getClass().getSimpleName()); + this.deleteProposals(); return mProposals; }