Skip to content

Commit

Permalink
Finish Sending Emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Kamal El Shazly committed Feb 8, 2018
1 parent 10ab5f8 commit cf9e671
Show file tree
Hide file tree
Showing 25 changed files with 477 additions and 147 deletions.
11 changes: 7 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true

}

buildTypes {
release {
minifyEnabled false
Expand All @@ -20,21 +23,21 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.github.bumptech.glide:glide:3.7.0'
// compile fileTree(include: '*.jar', dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-storage:11.8.0'
testImplementation 'junit:junit:4.12'
compile 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:design:26.1.0'
compile 'com.google.firebase:firebase-storage:11.8.0'

implementation files('libs/activation.jar')
}


Expand Down
Binary file added app/libs/activation.jar
Binary file not shown.
Binary file added app/libs/additionnal.jar
Binary file not shown.
Binary file added app/libs/mail.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/board"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@drawable/board"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".Activity.LoginActivity"
android:label="LogIn">
android:label="Piazy">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
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;
Expand All @@ -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;
Expand All @@ -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 {

Expand All @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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);
}


Expand All @@ -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;
}
Expand All @@ -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++) {
Expand All @@ -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
Expand All @@ -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) {

Expand All @@ -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
Expand Down
Loading

0 comments on commit cf9e671

Please sign in to comment.