-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mohamed Kamal El Shazly
committed
Feb 8, 2018
1 parent
10ab5f8
commit cf9e671
Showing
25 changed files
with
477 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
package com.example.shazly.piazyapp.Activity; | ||
|
||
import android.app.ProgressDialog; | ||
import android.content.Intent; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
@@ -18,6 +17,7 @@ | |
import com.example.shazly.piazyapp.Model.UserManger; | ||
import com.example.shazly.piazyapp.Model.User; | ||
import com.example.shazly.piazyapp.Notifications.AddToCourseNotification; | ||
import com.example.shazly.piazyapp.Notifications.RetreiveFeedTask; | ||
import com.example.shazly.piazyapp.R; | ||
import com.google.firebase.auth.FirebaseAuth; | ||
import com.google.firebase.auth.FirebaseUser; | ||
|
@@ -28,6 +28,11 @@ | |
import com.google.firebase.database.ValueEventListener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Properties; | ||
|
||
import javax.mail.Authenticator; | ||
import javax.mail.PasswordAuthentication; | ||
import javax.mail.Session; | ||
|
||
public class AddCourseActivity extends AppCompatActivity { | ||
|
||
|
@@ -41,11 +46,11 @@ public class AddCourseActivity extends AppCompatActivity { | |
ArrayList<String> instructors = new ArrayList<>(); | ||
|
||
ImageButton addStudentButton; | ||
ImageButton addInstructorbutton; | ||
ImageButton addInstructorButton; | ||
TextView addingInstructorState; | ||
TextView addingStudentState; | ||
boolean firstUpdate = true; | ||
boolean xx = true; | ||
ProgressDialog wait; | ||
Session session; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
@@ -54,29 +59,32 @@ protected void onCreate(Bundle savedInstanceState) { | |
courseNameField = findViewById(R.id.courseName); | ||
facultyField = findViewById(R.id.faculty); | ||
courseCodeField = findViewById(R.id.courseCode); | ||
addInstructorbutton = findViewById(R.id.addInstructor); | ||
addInstructorButton = findViewById(R.id.addInstructor); | ||
addStudentButton = findViewById( R.id.addStudent); | ||
addingInstructorState = findViewById(R.id.addingInstructorState); | ||
addingStudentState = findViewById(R.id.addingStudentState); | ||
wait = new ProgressDialog(AddCourseActivity.this);; | ||
instructors.add(UserManger.currentUser.getUserId()); | ||
addStudentButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
addingStudentState.setText("Waiting"); | ||
try { | ||
addFollower(((EditText) (findViewById(R.id.studentEmail))), students, addingStudentState); | ||
addStudentButton.setEnabled(false); | ||
addFollower(((EditText) (findViewById(R.id.studentEmail))), students, addingStudentState, addStudentButton); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
addingInstructorState.setText(""); | ||
} | ||
}); | ||
addInstructorbutton.setOnClickListener(new View.OnClickListener() { | ||
addInstructorButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
addingInstructorState.setText("Waiting"); | ||
try { | ||
addFollower(((EditText) (findViewById(R.id.instructorEmail))), instructors, addingInstructorState); | ||
addInstructorButton.setEnabled(false); | ||
addFollower(((EditText) (findViewById(R.id.instructorEmail))), instructors, addingInstructorState, addInstructorButton); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
@@ -85,10 +93,10 @@ public void onClick(View v) { | |
}); | ||
} | ||
|
||
private void addFollower(EditText email, ArrayList<String> followers, TextView state) throws InterruptedException { | ||
private void addFollower(EditText email, ArrayList<String> followers, TextView state, ImageButton addButton) throws InterruptedException { | ||
email.setEnabled(false); | ||
UserManger userManger = new UserManger(); | ||
userManger.FindUserByEmail(email, followers, state); | ||
userManger.FindUserByEmail(email, followers, state, addButton); | ||
} | ||
|
||
|
||
|
@@ -103,16 +111,20 @@ public boolean onOptionsItemSelected(MenuItem item) { | |
|
||
int id = item.getItemId(); | ||
if (id == R.id.done_action) { | ||
if (name == "" || faculty == "" || code == "") { | ||
name = courseNameField.getText().toString(); | ||
code = courseCodeField.getText().toString(); | ||
faculty = facultyField.getText().toString(); | ||
if (name.equals("")|| faculty.equals( "") || code .equals( "")) { | ||
Toast.makeText(AddCourseActivity.this, "You Should Fill All Data", | ||
Toast.LENGTH_SHORT).show(); | ||
|
||
} else { | ||
name = courseNameField.getText().toString(); | ||
code = courseCodeField.getText().toString(); | ||
faculty = facultyField.getText().toString(); | ||
|
||
CourseBuilder builder = new CourseBuilder(name, code, students, instructors); | ||
Course course = builder.buildCourse(); | ||
wait.setTitle("Please Wait"); | ||
wait.setMessage("Loading..."); | ||
wait.show(); | ||
findCourseID(course); | ||
return true; | ||
} | ||
|
@@ -132,12 +144,10 @@ public void AddCourseToFollowers(final Course course) { | |
mAuth = FirebaseAuth.getInstance(); | ||
final FirebaseUser user1 = mAuth.getCurrentUser(); | ||
mFirebaseDatabase = FirebaseDatabase.getInstance(); | ||
xx = true; | ||
final DatabaseReference myRef = mFirebaseDatabase.getReference().child("users"); | ||
myRef.addValueEventListener(new ValueEventListener() { | ||
@Override | ||
public void onDataChange(DataSnapshot dataSnapshot) { | ||
if (xx) { | ||
for (DataSnapshot ds : dataSnapshot.getChildren()) { | ||
User user = (ds.getValue(User.class)); | ||
for(int i = 0; i < students.size(); i++) { | ||
|
@@ -152,9 +162,13 @@ public void onDataChange(DataSnapshot dataSnapshot) { | |
} | ||
|
||
} | ||
xx = false; | ||
} | ||
} | ||
wait.dismiss(); | ||
|
||
Intent intent = new Intent(AddCourseActivity.this, HomeActivity.class); | ||
startActivity(intent); | ||
myRef.removeEventListener(this); | ||
|
||
|
||
} | ||
@Override | ||
|
@@ -166,10 +180,24 @@ public void onCancelled(DatabaseError databaseError) { | |
public void updateAndSendNotification(User user, Course course) { | ||
|
||
user.getCourses().add(0,course); | ||
user.getNotifications().add(0,new AddToCourseNotification(UserManger.currentUser.getName(), course, UserManger.currentUser.getUserId())); | ||
AddToCourseNotification addToCourseNotification = new AddToCourseNotification(UserManger.currentUser.getName(), course, UserManger.currentUser.getUserId()); | ||
user.getNotifications().add(0, addToCourseNotification); | ||
user.update(); | ||
Toast.makeText(AddCourseActivity.this, "AddNotifications", | ||
Toast.LENGTH_SHORT).show(); | ||
Properties props = new Properties(); | ||
props.put("mail.smtp.host", "smtp.gmail.com"); | ||
props.put("mail.smtp.socketFactory.port", "465"); | ||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); | ||
props.put("mail.smtp.auth", "true"); | ||
props.put("mail.smtp.port", "465"); | ||
|
||
session = Session.getDefaultInstance(props, new Authenticator() { | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication("[email protected]", "57712150a"); | ||
} | ||
}); | ||
RetreiveFeedTask task = new RetreiveFeedTask(session, UserManger.currentCourse.getName(),addToCourseNotification.getContent(), user.getEmail(), AddCourseActivity.this); | ||
task.execute(); | ||
|
||
} | ||
public void findCourseID(final Course course) { | ||
|
||
|
@@ -180,22 +208,18 @@ public void findCourseID(final Course course) { | |
mAuth = FirebaseAuth.getInstance(); | ||
final FirebaseUser user1 = mAuth.getCurrentUser(); | ||
mFirebaseDatabase = FirebaseDatabase.getInstance(); | ||
firstUpdate = true; | ||
final DatabaseReference myRef = mFirebaseDatabase.getReference().child("LastCourseId"); | ||
myRef.addValueEventListener(new ValueEventListener() { | ||
@Override | ||
public void onDataChange(DataSnapshot dataSnapshot) { | ||
if (firstUpdate) { | ||
course.id = dataSnapshot.getValue(int.class); | ||
mDatabase.child("LastCourseId").setValue(course.id + 1); | ||
firstUpdate = false; | ||
UserManger.currentUser.getCourses().add(course); | ||
AddCourseToFollowers(course); | ||
UserManger.currentCourse = course; | ||
Intent intent = new Intent(AddCourseActivity.this, HomeActivity.class); | ||
startActivity(intent); | ||
|
||
} | ||
|
||
myRef.removeEventListener(this); | ||
|
||
} | ||
@Override | ||
|
Oops, something went wrong.