diff --git a/app/src/main/java/com/darshanbshah/odsystem/MainActivity.java b/app/src/main/java/com/darshanbshah/odsystem/MainActivity.java index 15a71b65cebb5edd5e8e8b51e6ff5b4353cecfec..7586e34f47a0e866b33f5fb9508d4f528145c01c 100644 --- a/app/src/main/java/com/darshanbshah/odsystem/MainActivity.java +++ b/app/src/main/java/com/darshanbshah/odsystem/MainActivity.java @@ -11,10 +11,18 @@ import android.widget.DatePicker; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.TextView; +import android.widget.Toast; import com.google.firebase.auth.FirebaseAuth; +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 java.util.ArrayList; import java.util.Calendar; +import java.util.List; public class MainActivity extends AppCompatActivity { @@ -27,22 +35,80 @@ public class MainActivity extends AppCompatActivity { String reasonString, fromDate, toDate, full; Boolean fullDay = false; + FirebaseDatabase database = FirebaseDatabase.getInstance(); + DatabaseReference root; + DatabaseReference student; + DatabaseReference adv; + DatabaseReference id; + DatabaseReference roll_no; + DatabaseReference email; + DatabaseReference advisor; + + String recepient = ""; + + List<String> list1 = new ArrayList<String>(); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAuth = FirebaseAuth.getInstance(); + + root = database.getReference(); + student = root.child("Student"); + adv = root.child("Advisors"); + id = student.child(mAuth.getCurrentUser().getUid()); + roll_no = id.child("RollNumber"); + email = id.child("Email"); + advisor = id.child("Advisor"); + + welcomeText = (TextView)findViewById(R.id.welcomeText); welcomeText.setText("Welcome " + mAuth.getCurrentUser().getEmail()); from = (TextView)findViewById(R.id.fromDateTV); to = (TextView)findViewById(R.id.toDateTV); frameLayout = (FrameLayout) findViewById(R.id.hours_frame_layout); reason = (EditText)findViewById(R.id.reasonEditText); + + student.addChildEventListener(new ChildEventListener() { + @Override + public void onChildAdded(DataSnapshot dataSnapshot, String s) { + for(DataSnapshot dsp : dataSnapshot.getChildren()){ + if (dsp.getKey().toString().equals("Advisor")) { + list1.add(String.valueOf(dsp.getValue())); + Log.e("E-MAIL ", String.valueOf(dsp.getValue())); + } + } + } + + @Override + public void onChildChanged(DataSnapshot dataSnapshot, String s) { + + } + + @Override + public void onChildRemoved(DataSnapshot dataSnapshot) { + + } + + @Override + public void onChildMoved(DataSnapshot dataSnapshot, String s) { + + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + } + public void onClickFromDatePicker(View view) { new DatePickerDialog(this, fromListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show(); } @@ -95,8 +161,10 @@ public class MainActivity extends AppCompatActivity { Intent intent = new Intent(Intent.ACTION_SEND); intent.setData(Uri.parse("mailto:")); - String []recepients = {""}; - intent.putExtra(Intent.EXTRA_EMAIL, recepients); + + +// Log.e("Recepient", recepient); + intent.putExtra(Intent.EXTRA_EMAIL, recepient); intent.putExtra(Intent.EXTRA_SUBJECT, "OD Request"); intent.putExtra(Intent.EXTRA_TEXT, "Reason: " + reasonString + '\n' + "From: " + fromDate + '\n' + "To: " + toDate + '\n' + "Full day: " + full); intent.setType("message/rfc822"); diff --git a/app/src/main/java/com/darshanbshah/odsystem/RollNumber.java b/app/src/main/java/com/darshanbshah/odsystem/RollNumber.java index d38c3fe7f67189e97eb29eb47ae1e7fd31ab2899..db9bfea690d1b0f8d9be6791e24512674e3a2185 100644 --- a/app/src/main/java/com/darshanbshah/odsystem/RollNumber.java +++ b/app/src/main/java/com/darshanbshah/odsystem/RollNumber.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.support.annotation.MainThread; +import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.TextUtils; @@ -36,19 +37,28 @@ public class RollNumber extends AppCompatActivity implements AdapterView.OnItemS FirebaseDatabase database = FirebaseDatabase.getInstance(); - DatabaseReference root = database.getReference(); - DatabaseReference student = root.child("Student"); - DatabaseReference adv = root.child("Advisors"); - DatabaseReference id = student.child(mAuth.getCurrentUser().getUid()); - DatabaseReference roll_no = id.child("RollNumber"); - DatabaseReference email = id.child("Email"); - DatabaseReference advisor = id.child("Advisor"); + DatabaseReference root; + DatabaseReference student; + DatabaseReference adv; + DatabaseReference id; + DatabaseReference roll_no; + DatabaseReference email; + DatabaseReference advisor; List<String> list = new ArrayList<String>(); List<String> lst = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { + + root = database.getReference(); + student = root.child("Student"); + adv = root.child("Advisors"); + id = student.child(mAuth.getCurrentUser().getUid()); + roll_no = id.child("RollNumber"); + email = id.child("Email"); + advisor = id.child("Advisor"); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_roll_number); rollNumber = (EditText)findViewById(R.id.rollNumberEditText); @@ -108,6 +118,8 @@ public class RollNumber extends AppCompatActivity implements AdapterView.OnItemS }); + + // SharedPreferences preferences = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE); // // if(preferences.getBoolean("activity_executed", false)){