Skip to content

Commit

Permalink
the last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SFaaiz committed May 2, 2024
1 parent 55f06f3 commit 954e145
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,46 +61,58 @@ protected void onCreate(Bundle savedInstanceState) {
user_id = getUserId();
firebaseUser = auth.getCurrentUser();

binding.proceedBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});

binding.sendOtp.setOnClickListener(new View.OnClickListener() {
// binding.sendOtp.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// if(!isCodeSent){
// binding.progressBar.setVisibility(View.VISIBLE);
// }
// mobile = binding.etMobile.getText().toString();
// if(mobile.length() == 10){
//
// PhoneAuthOptions options =
// PhoneAuthOptions.newBuilder(auth)
// .setPhoneNumber("+91" + mobile) // Phone number to verify
// .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
// .setActivity(MobileVerificationActivity.this) // (optional) Activity for callback binding
// // If no activity is passed, reCAPTCHA verification can not be used.
// .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks
// .build();
// PhoneAuthProvider.verifyPhoneNumber(options);
// }else{
// binding.etMobile.setError("Mobile Number should be 10 digit");
// binding.etMobile.requestFocus();
// }
// }
// });

binding.proceedBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!isCodeSent){
binding.progressBar.setVisibility(View.VISIBLE);
}
mobile = binding.etMobile.getText().toString();
if(mobile.length() == 10){

PhoneAuthOptions options =
PhoneAuthOptions.newBuilder(auth)
.setPhoneNumber("+91" + mobile) // Phone number to verify
.setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
.setActivity(MobileVerificationActivity.this) // (optional) Activity for callback binding
// If no activity is passed, reCAPTCHA verification can not be used.
.setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks
.build();
PhoneAuthProvider.verifyPhoneNumber(options);
String mobileNo = binding.etMobile.getText().toString();
if(isValidMobileNum(mobileNo)){
proceedUser(mobileNo);
}else{
binding.etMobile.setError("Mobile Number should be 10 digit");
binding.etMobile.requestFocus();
Toast.makeText(MobileVerificationActivity.this, "Please enter a valid mobile number", Toast.LENGTH_SHORT).show();
}
// verifyOTP(mVerificationId, otp);
}
});

binding.proceedBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String otp = binding.etOtp.getText().toString();
verifyOTP(mVerificationId, otp);
}
});

}

private boolean isValidMobileNum(String number){
if(number.length() != 10){
return false;
}
for(char c : number.toCharArray()){
if(!Character.isDigit(c)){
return false;
}
}
return true;
}

private CompletableFuture<String> getMobile() {
Expand Down Expand Up @@ -150,7 +162,7 @@ public void onVerificationCompleted(@NonNull PhoneAuthCredential credential) {
Log.d(TAG, "onVerificationCompleted:" + credential);
binding.progressBar.setVisibility(View.GONE);

signInWithPhoneAuthCredential(credential);
// signInWithPhoneAuthCredential(credential);
}

@Override
Expand Down Expand Up @@ -191,60 +203,51 @@ public void onCodeSent(@NonNull String verificationId,
}
};

private void verifyOTP(String verificationId, String otp) {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, otp);
signInWithPhoneAuthCredential(credential);
}
// private void verifyOTP(String verificationId, String otp) {
// PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, otp);
// signInWithPhoneAuthCredential(credential);
// }

private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
auth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
private void proceedUser(String mobileNo) {

Map<String, Object> updates = new HashMap<>();
updates.put("mobileVerified", true);
updates.put("mobile", mobileNo);

// update phone verification status
reference.child(user_id).updateChildren(updates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
Toast.makeText(MobileVerificationActivity.this, "Phone Verified Successfully", Toast.LENGTH_SHORT).show();
FirebaseUser user = task.getResult().getUser();
String mobileNo = user.getPhoneNumber().substring(3);

auth.updateCurrentUser(firebaseUser);

Map<String, Object> updates = new HashMap<>();
updates.put("mobileVerified", true);
updates.put("mobile", mobileNo);

// update phone verification status
reference.child(user_id).updateChildren(updates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
MySharedPreferences sp = new MySharedPreferences(MobileVerificationActivity.this);
sp.saveUserProgress("companyDetailsActivity");
Log.d(TAG, "onComplete: Data has been updated");
} else {
Log.d(TAG, "onComplete: Failure " + task.getException());
}
}
});

// Update UI
Intent i = new Intent(MobileVerificationActivity.this, CompanyDetailsActivity.class);
startActivity(i);
finish();
MySharedPreferences sp = new MySharedPreferences(MobileVerificationActivity.this);
sp.saveUserProgress("companyDetailsActivity");
Log.d(TAG, "onComplete: Data has been updated");
} else {
// Sign in failed, display a message and update the UI
Log.w(TAG, "signInWithCredential:failure", task.getException());
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// The verification code entered was invalid
Toast.makeText(MobileVerificationActivity.this, "The verification code entered was invalid", Toast.LENGTH_SHORT).show();
}
Log.d(TAG, "onComplete: Failure " + task.getException());
}
}
});

// Update UI
Intent i = new Intent(MobileVerificationActivity.this, CompanyDetailsActivity.class);
startActivity(i);
finish();
}

// auth.signInWithCredential(credential)
// .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
// @Override
// public void onComplete(@NonNull Task<AuthResult> task) {
// if (task.isSuccessful()) {
// // Sign in success, update UI with the signed-in user's information
// Log.d(TAG, "signInWithCredential:success");
// Toast.makeText(MobileVerificationActivity.this, "Phone Verified Successfully", Toast.LENGTH_SHORT).show();
//
// }
// }
// });
}



}
9 changes: 9 additions & 0 deletions app/src/main/java/com/faaiz/placementfinder/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
appliedJobs = new ArrayList<>();
}

List<JobPost> existingJobPosts = roomDB.dao().getAllJobPosts();
System.out.println("existing jobs = " + existingJobPosts.size());
for(JobPost jobPost : existingJobPosts){
System.out.println(jobPost.getJobId() + " - " + jobPost.getRoleToHire());
}

// Insert each job post into Room database
for (JobPost jobPost : jobPosts) {
// Insert jobPost into Room database using your DAO method
Expand All @@ -248,6 +254,9 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
System.out.println("applied job id = " + jobPost.getJobId());
jobPost.setJobApplied(true);
}
// jobPost.setId(0);
System.out.println("jobId = "+ jobPost.getId());
jobPost.setId(0);
roomDB.dao().insertJob(jobPost);
}
}
Expand Down
72 changes: 36 additions & 36 deletions app/src/main/res/layout/activity_mobile_verification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="phone"
android:hint=" Enter your mobile number"
android:hint=" Enter your mobile number"
android:textColor="@color/black"
android:textColorHint="@color/grey"
android:maxLength="10"
Expand All @@ -64,40 +64,40 @@

</LinearLayout>

<LinearLayout
android:id="@+id/otpContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_below="@id/mobileContainer">


<EditText
android:id="@+id/etOtp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:textColor="@color/black"
android:textColorHint="@color/grey"
android:hint="Enter your OTP"
android:maxLength="10"
android:padding="12dp"/>

<TextView
android:id="@+id/sendOtp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send OTP"
android:textColor="@color/white"
android:paddingVertical="8dp"
android:paddingHorizontal="14dp"
android:background="@color/royalBlue"
android:layout_marginLeft="10dp"
android:textSize="18sp"/>

</LinearLayout>
<!-- <LinearLayout-->
<!-- android:id="@+id/otpContainer"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="horizontal"-->
<!-- android:gravity="center"-->
<!-- android:layout_below="@id/mobileContainer">-->


<!-- <EditText-->
<!-- android:id="@+id/etOtp"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:inputType="number"-->
<!-- android:textColor="@color/black"-->
<!-- android:textColorHint="@color/grey"-->
<!-- android:hint="Enter your OTP"-->
<!-- android:maxLength="10"-->
<!-- android:padding="12dp"/>-->

<!-- <TextView-->
<!-- android:id="@+id/sendOtp"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="Send OTP"-->
<!-- android:textColor="@color/white"-->
<!-- android:paddingVertical="8dp"-->
<!-- android:paddingHorizontal="14dp"-->
<!-- android:background="@color/royalBlue"-->
<!-- android:layout_marginLeft="10dp"-->
<!-- android:textSize="18sp"/>-->

<!-- </LinearLayout>-->


<!-- Proceed Button -->
Expand All @@ -112,7 +112,7 @@
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:padding="12dp"
android:layout_below="@id/otpContainer"
android:layout_below="@id/mobileContainer"
/>

<!-- Progress Bar -->
Expand Down
11 changes: 3 additions & 8 deletions app/src/main/res/layout/activity_view_job.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@
android:id="@+id/tvQualification"
android:layout_width="wrap_content"
android:layout_marginLeft="24dp"
android:layout_height="wrap_content"
android:text="Graduation" />
android:layout_height="wrap_content"/>

</LinearLayout>

Expand Down Expand Up @@ -255,7 +254,6 @@
android:id="@+id/tvDesc"
android:layout_width="wrap_content"
android:layout_marginLeft="24dp"
android:lines="2"
android:layout_height="wrap_content"
android:text="Description" />

Expand Down Expand Up @@ -311,8 +309,7 @@
android:id="@+id/tvCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="Google" />
android:layout_marginLeft="30dp"/>

</LinearLayout>

Expand Down Expand Up @@ -350,8 +347,7 @@
android:id="@+id/tvContact"
android:layout_width="wrap_content"
android:layout_marginLeft="30dp"
android:layout_height="wrap_content"
android:text="Faaiz Sorathiya" />
android:layout_height="wrap_content"/>

</LinearLayout>
</LinearLayout>
Expand Down Expand Up @@ -386,7 +382,6 @@
android:id="@+id/textCompanyDescription"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:lines="2"
android:layout_height="wrap_content"
android:text="Company Description" />

Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="Phone Number" />

</com.google.android.material.textfield.TextInputLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/layout_job_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_height="200dp"
android:layout_margin="10dp"
android:id="@+id/jobItem"
app:cardCornerRadius="8dp">
Expand Down

0 comments on commit 954e145

Please sign in to comment.