Tutorial 8 - Reset Password

 


This is Sample Project Which you can improve UI design & Coding skills .

*******Important********
I moved profile info to Another Activity Called Profile

If you get any trouble. Please Contact me on WhatsApp!!

Now You can download source code until 8 tutorial. 

activity_Profile

ProfileActivity

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProfileActivity"
android:orientation="vertical">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/top_gradient" />

<TextView

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Covid Tracker"
android:textStyle="bold"
android:layout_marginTop="-40dp"
android:height="30dp"
android:fontFamily="sans-serif-smallcaps"
android:textAlignment="center"
android:textSize="25dp"
android:textColor="@color/white"
android:gravity="center_horizontal" />

<ScrollView

android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Your Profile"
android:fontFamily="@font/baloo"
android:textAlignment="center"
android:textSize="20dp"
android:gravity="center_horizontal" />

<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:src="@drawable/ic_user"
android:scaleType="centerCrop"
/>

<!-- <Button-->
<!-- android:id="@+id/changeProfile"-->
<!-- android:layout_width="200dp"-->
<!-- android:layout_height="45dp"-->
<!-- android:background="@drawable/button_style"-->
<!-- android:text="Reset Profile"-->
<!-- android:textColor="@color/white"-->
<!-- android:layout_gravity="center"-->
<!-- android:textStyle="bold"-->
<!-- android:fontFamily="@font/baloo"-->
<!-- android:textSize="15sp"-->
<!-- />-->

<EditText
android:id="@+id/profileName"
android:layout_width="350dp"
android:layout_height="45dp"
android:editable="false"
android:textColor="@color/textcolor"
android:background="@drawable/input_style"
android:drawableRight="@drawable/ic_user"
android:hint="Your Name"
android:layout_gravity="center"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/baloo"
/>

<EditText
android:id="@+id/profileEmail"
android:layout_width="350dp"
android:layout_height="45dp"
android:editable="false"
android:background="@drawable/input_style"
android:drawableRight="@drawable/ic_email"
android:hint="Your Email Address"
android:textColor="@color/textcolor"
android:layout_gravity="center"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/baloo"
/>

<EditText
android:id="@+id/profilePhone"
android:layout_width="350dp"
android:layout_height="45dp"
android:editable="false"
android:background="@drawable/input_style"
android:drawableRight="@drawable/ic_phone"
android:hint="Your Phone"
android:textColor="@color/textcolor"
android:layout_gravity="center"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/baloo"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="vertical">

<Button
android:id="@+id/resetPasswordLocal"
android:layout_width="350dp"
android:layout_height="45dp"
android:background="@drawable/button_style"
android:text="Reset Password"
android:textColor="@color/white"
android:layout_gravity="center"
android:textStyle="bold"
android:fontFamily="@font/baloo"
android:textSize="18sp"
/>

</LinearLayout>

</LinearLayout>


</ScrollView>

</LinearLayout>

package com.rrmchathura.myfirstapp;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;

public class ProfileActivity extends AppCompatActivity {

private EditText fullName,email,phone;
FirebaseAuth fAuth;
FirebaseFirestore fStore;
String userID;
Button resetPassLocal;
FirebaseUser user;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);

fullName = findViewById(R.id.profileName);
email = findViewById(R.id.profileEmail);
phone = findViewById(R.id.profilePhone);
resetPassLocal = findViewById(R.id.resetPasswordLocal);


fAuth = FirebaseAuth.getInstance();
fStore = FirebaseFirestore.getInstance();

userID = fAuth.getCurrentUser().getUid();
user = fAuth.getCurrentUser();

DocumentReference documentReference = fStore.
collection("users").document(userID);
documentReference.
addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot,
@Nullable FirebaseFirestoreException error) {
phone.setText(documentSnapshot.getString("phone"));
fullName.setText(documentSnapshot.getString("fName"));
email.setText(documentSnapshot.getString("email"));
}
});
//////////////Reset Password Button Clicked

resetPassLocal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText resetPassword = new EditText(v.getContext());
AlertDialog.Builder passwordResetDialog = new
AlertDialog.Builder(v.getContext());

passwordResetDialog.setTitle("Reset Password ?");
passwordResetDialog.setMessage("Enter New Password > 6 Characters long.");

passwordResetDialog.setView(resetPassword);

passwordResetDialog.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//extract the email and send reset link

String newPassword = resetPassword.getText().toString();
user.updatePassword(newPassword).
addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Toast.makeText(ProfileActivity.this,
"Password Reset Successfully",Toast.LENGTH_SHORT)
.show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(ProfileActivity.
this,"Password Reset Failed",Toast.LENGTH_SHORT)
.show();
}
});

}
});
passwordResetDialog.setNegativeButton("No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//close the dialog box
}
});
passwordResetDialog.create().show();

}
});
}





}


Post a Comment

0 Comments

Youtube Channel Image
Coding With Chathura Subscribe To watch more Project Tutorials
Subscribe
Do you have any doubts? chat with us on WhatsApp
Hello, How can I help you? ...
Click me to start the chat...

Welcome to freesourcecodelk

X