Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MongoDB functionality #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
multiDexEnabled true
applicationId "com.nsh.getintoclub"
minSdkVersion 19
targetSdkVersion 27
Expand Down Expand Up @@ -35,5 +36,8 @@ dependencies {
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
compile 'com.itextpdf:itextg:5.5.10'
compile 'com.amitshekhar.android:android-networking:1.0.2'
compile 'com.amitshekhar.android:jackson-android-networking:1.0.2'
compile 'com.facebook.stetho:stetho-okhttp:1.2.0'
}
apply plugin: 'com.google.gms.google-services'
8 changes: 8 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
"certificate_hash": "2a2fb86c6cfb270c38d649175e3a5c7ba058c83c"
}
},
{
"client_id": "198631292821-orbo0ma46e360n0flcmmt50aeoijued2.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.nsh.getintoclub",
"certificate_hash": "f41996ad3e46772ad7d2ca87b4a0f04c82e8aaea"
}
},
{
"client_id": "198631292821-4orc9sjvbml29cj18591up7fjljucc6c.apps.googleusercontent.com",
"client_type": 3
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
15 changes: 11 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,32 @@
<activity android:name=".activity.MainActivity" />
<activity
android:name=".activity.ContactDetail"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent1"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".activity.SkillDetail"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent1" />
<activity
android:name=".activity.QuestionDetail"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent1" />
<activity
android:name=".activity.Database"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent" />
<activity
android:name=".activity.DashActivity"
android:theme="@style/Theme.Transparent">
</activity>
android:name=".activity.OtpGenerator"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent"/>
<activity
android:name=".activity.AboutAppteam"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent" />
<activity android:name=".activity.OtpGenerator" >
<activity
android:name=".activity.DashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
77 changes: 76 additions & 1 deletion app/src/main/java/com/nsh/getintoclub/activity/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.renderscript.RenderScript;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.common.Priority;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.JSONArrayRequestListener;
import com.facebook.stetho.okhttp.StethoInterceptor;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.itextpdf.text.DocListener;
Expand All @@ -23,14 +29,27 @@
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfWriter;
import com.jacksonandroidnetworking.JacksonParserFactory;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import okhttp3.OkHttpClient;

import static com.nsh.getintoclub.activity.ContactDetail.branch;
import static com.nsh.getintoclub.activity.ContactDetail.email;
import static com.nsh.getintoclub.activity.ContactDetail.mobile;
Expand All @@ -54,6 +73,12 @@ public class Database extends AppCompatActivity {
public static String c;
final private int REQUEST_CODE_ASK_PERMISSIONS = 111;
protected void onCreate(Bundle savedInstanceState) {

//Android Networking config by utkarshsingh99
AndroidNetworking.initialize(getApplicationContext());
AndroidNetworking.setParserFactory(new JacksonParserFactory());
//End of AndroidNetworking config

super.onCreate(savedInstanceState);
initUI();
try {
Expand All @@ -70,8 +95,58 @@ public void initUI() {
if (ContactDetail.RollLength == 0 || SkillDetail.skillet.length() == 0)
Toast.makeText(this, "Please Enter Your Roll Number And At Least One Skill", Toast.LENGTH_SHORT).show();
else
writeNewUser(ContactDetail.roll);
// writeNewUser(ContactDetail.roll);
System.out.println("About to send request");
sendRequest(); // Function called by utkarshsingh99
}

// Code for MongoDB POST request - by utkarshsingh99
public void sendRequest(){

JSONObject jsonObject = null;
try {
jsonObject = buidJsonObject();
} catch(JSONException e) {
jsonObject = new JSONObject();
}
System.out.println(jsonObject);
AndroidNetworking.post("http://clubcoming.herokuapp.com/postcandidate")
.addJSONObjectBody(jsonObject) // posting json
.setTag("test")
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
System.out.println("POST Successful");
}
@Override
public void onError(ANError error) {
System.out.println("POST Failure"+error);
}
});
}

private JSONObject buidJsonObject() throws JSONException {

JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", ContactDetail.name);
jsonObject.accumulate("mobile", "12345");
jsonObject.accumulate("rollNumber", ContactDetail.rollNo);
jsonObject.accumulate("club", c);
jsonObject.accumulate("branch", ContactDetail.branch);
jsonObject.accumulate("email", ContactDetail.email);
jsonObject.accumulate("interviewStatus", "Applied");
jsonObject.accumulate("skills", SkillDetail.skill);
jsonObject.accumulate("Achievements", SkillDetail.achievments);
jsonObject.accumulate("AreasOfInt", SkillDetail.interset);
jsonObject.accumulate("ques1", QuestionDetail.q1);
jsonObject.accumulate("ques2", QuestionDetail.q2);
jsonObject.accumulate("ques3", QuestionDetail.q3);
jsonObject.accumulate("ques4", QuestionDetail.q4);
return jsonObject;
}
//End of Code by utkarshsingh99

private void writeNewUser(String roll) {
mDatabase.child(c).child(roll).child("Name").setValue(ContactDetail.name);
Expand Down
87 changes: 61 additions & 26 deletions app/src/main/java/com/nsh/getintoclub/activity/OtpGenerator.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.nsh.getintoclub.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

Expand All @@ -15,7 +17,6 @@
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.nsh.getintoclub.R;
Expand All @@ -27,84 +28,118 @@ public class OtpGenerator extends AppCompatActivity {
String phoneNumber, otp;
EditText etPhoneNumber, etOTP;
FirebaseAuth auth;
public static String phone;
public static String phone = "";
private String verificationCode;
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallback;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_otp_generator);
SharedPreferences prefs = getSharedPreferences("number", Context.MODE_PRIVATE);
String check = prefs.getString("mobile", "nullaaa");
if (!check.equals("nullaaa")) {
phone = check;
startActivity(new Intent(OtpGenerator.this, DashActivity.class));
}
findViews();
StartFirebaseLogin();
}

private void findViews() {
btnGenerateOTP=findViewById(R.id.btn_generate_otp);
btnSignIn=findViewById(R.id.btn_sign_in);
btnGenerateOTP = findViewById(R.id.btn_generate_otp);
btnSignIn = findViewById(R.id.btn_sign_in);

etPhoneNumber=findViewById(R.id.et_phone_number);
etOTP=findViewById(R.id.et_otp);
etPhoneNumber = findViewById(R.id.et_phone_number);
etOTP = findViewById(R.id.et_otp);
setupdata();
}
public void setupdata()
{

public void setupdata() {
phoneNumber = String.valueOf(etPhoneNumber.getText());
btnGenerateOTP.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
phoneNumber=String.valueOf(etPhoneNumber.getText());
phone = phoneNumber;
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
OtpGenerator.this, // Activity (for callback binding)
mCallback); // OnVerificationStateChangedCallbacks
phoneNumber = String.valueOf(etPhoneNumber.getText());
if (phoneNumber.length() == 0) {
Toast.makeText(OtpGenerator.this, "Seems you have not enter phone number", Toast.LENGTH_SHORT).show();

} else {
String final_number = phoneNumber.replaceAll("\\+91", "");
String final_number1 = final_number.replaceAll(" ", "");
String final_number2 = "+91 " + final_number1;
phoneNumber = final_number2;
phone = phoneNumber;

SharedPreferences sharedpreferences = getSharedPreferences("number", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("mobile", phoneNumber);
editor.commit();


// etOTP.setText(phone);
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
OtpGenerator.this, // Activity (for callback binding)
mCallback); // OnVerificationStateChangedCallbacks
}
}
});
btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
otp=etOTP.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationCode, otp);
SigninWithPhone(credential);
otp = etOTP.getText().toString();
if (otp.length() == 0) {
Toast.makeText(OtpGenerator.this, "Seems you have not enter OTP", Toast.LENGTH_SHORT).show();
} else {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationCode, otp);
SigninWithPhone(credential);
}
}
});
}

private void SigninWithPhone(PhoneAuthCredential credential) {

auth.signInWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(OtpGenerator.this,DashActivity.class));
startActivity(new Intent(OtpGenerator.this, DashActivity.class));
finish();
} else {
Toast.makeText(OtpGenerator.this,"Incorrect OTP",Toast.LENGTH_SHORT).show();
Toast.makeText(OtpGenerator.this, "Incorrect OTP", Toast.LENGTH_SHORT).show();
}
}
});
}

private void StartFirebaseLogin() {

auth = FirebaseAuth.getInstance();
mCallback = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(OtpGenerator.this,"verification completed",Toast.LENGTH_SHORT).show();
Toast.makeText(OtpGenerator.this, "verification completed", Toast.LENGTH_SHORT).show();
}

@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(OtpGenerator.this,"verification fialed",Toast.LENGTH_SHORT).show();
Toast.makeText(OtpGenerator.this, "verification failed", Toast.LENGTH_SHORT).show();
}

@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationCode = s;
Toast.makeText(OtpGenerator.this,"Code sent",Toast.LENGTH_SHORT).show();
Toast.makeText(OtpGenerator.this, "Code sent", Toast.LENGTH_SHORT).show();
btnSignIn.setVisibility(View.VISIBLE);
btnGenerateOTP.setVisibility(View.GONE);
}
};
}
Expand Down
Loading