Skip to content
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
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures{
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand Down
39 changes: 17 additions & 22 deletions app/src/main/java/com/example/notesapptutorial/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.notesapptutorial.databinding.ActivityMainBinding;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
Expand All @@ -20,58 +22,51 @@

public class MainActivity extends AppCompatActivity {

private EditText mloginemail,mloginpassword;
private RelativeLayout mlogin,mgotosignup;
private TextView mgotoforgotpassword;
private ActivityMainBinding binding;

private FirebaseAuth firebaseAuth;

ProgressBar mprogressbarofmainactivity;


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

getSupportActionBar().hide();
binding = ActivityMainBinding.inflate(getLayoutInflater());

mloginemail=findViewById(R.id.loginemail);
mloginpassword=findViewById(R.id.loginpassword);
mlogin=findViewById(R.id.login);
mgotoforgotpassword=findViewById(R.id.gotoforgotpassword);
mgotosignup=findViewById(R.id.gotosignup);
mprogressbarofmainactivity=findViewById(R.id.progressbarofmainactivity);
setContentView(binding.getRoot());

getSupportActionBar().hide();

firebaseAuth=FirebaseAuth.getInstance();
FirebaseUser firebaseUser=firebaseAuth.getCurrentUser();

binding.loginpassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

if(firebaseUser!=null)
{
finish();
startActivity(new Intent(MainActivity.this,notesactivity.class));
}

mgotosignup.setOnClickListener(new View.OnClickListener() {
binding.gotosignup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,signup.class));
}
});

mgotoforgotpassword.setOnClickListener(new View.OnClickListener() {
binding.gotoforgotpassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,fogotpassword.class));
}
});


mlogin.setOnClickListener(new View.OnClickListener() {
binding.login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String mail=mloginemail.getText().toString().trim();
String password=mloginpassword.getText().toString().trim();
String mail=binding.loginemail.getText().toString().trim();
String password=binding.loginpassword.getText().toString().trim();

if(mail.isEmpty()|| password.isEmpty())
{
Expand All @@ -81,7 +76,7 @@ public void onClick(View v) {
else
{
// login the user
mprogressbarofmainactivity.setVisibility(View.VISIBLE);
binding.progressbarofmainactivity.setVisibility(View.VISIBLE);

firebaseAuth.signInWithEmailAndPassword(mail,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
Expand All @@ -95,7 +90,7 @@ public void onComplete(@NonNull Task<AuthResult> task) {
else
{
Toast.makeText(getApplicationContext(),"Account Doesn't Exist",Toast.LENGTH_SHORT).show();
mprogressbarofmainactivity.setVisibility(View.INVISIBLE);
binding.progressbarofmainactivity.setVisibility(View.INVISIBLE);
}


Expand All @@ -120,7 +115,7 @@ private void checkmailverfication()
}
else
{
mprogressbarofmainactivity.setVisibility(View.INVISIBLE);
binding.progressbarofmainactivity.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(),"Verify your mail first",Toast.LENGTH_SHORT).show();
firebaseAuth.signOut();
}
Expand Down
65 changes: 25 additions & 40 deletions app/src/main/java/com/example/notesapptutorial/createnote.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import androidx.appcompat.widget.Toolbar;

import com.example.notesapptutorial.databinding.ActivityCreatenoteBinding;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
Expand All @@ -27,85 +28,69 @@

public class createnote extends AppCompatActivity {

EditText mcreatetitleofnote,mcreatecontentofnote;
FloatingActionButton msavenote;
private ActivityCreatenoteBinding binding;

FirebaseAuth firebaseAuth;
FirebaseUser firebaseUser;
FirebaseFirestore firebaseFirestore;

ProgressBar mprogressbarofcreatenote;

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


binding = ActivityCreatenoteBinding.inflate(getLayoutInflater());

msavenote=findViewById(R.id.savenote);
mcreatecontentofnote=findViewById(R.id.createcontentofnote);
mcreatetitleofnote=findViewById(R.id.createtitleofnote);
setContentView(binding.getRoot());

mprogressbarofcreatenote=findViewById(R.id.progressbarofcreatenote);
Toolbar toolbar=findViewById(R.id.toolbarofcreatenote);
setSupportActionBar(toolbar);
setSupportActionBar(binding.toolbarofcreatenote);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

firebaseAuth=FirebaseAuth.getInstance();
firebaseFirestore=FirebaseFirestore.getInstance();
firebaseUser=FirebaseAuth.getInstance().getCurrentUser();

firebaseAuth = FirebaseAuth.getInstance();
firebaseFirestore = FirebaseFirestore.getInstance();
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();


msavenote.setOnClickListener(new View.OnClickListener() {
binding.savenote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String title=mcreatetitleofnote.getText().toString().trim();
String content=mcreatecontentofnote.getText().toString().trim();
if(title.isEmpty() || content.isEmpty())
{
Toast.makeText(getApplicationContext(),"Both field are Require",Toast.LENGTH_SHORT).show();
}
else
{
String title = binding.createtitleofnote.getText().toString().trim();
String content = binding.createcontentofnote.getText().toString().trim();
if (title.isEmpty() || content.isEmpty()) {
Toast.makeText(getApplicationContext(), "Both field are Require", Toast.LENGTH_SHORT).show();
} else {

mprogressbarofcreatenote.setVisibility(View.VISIBLE);
binding.progressbarofcreatenote.setVisibility(View.VISIBLE);

DocumentReference documentReference=firebaseFirestore.collection("notes").document(firebaseUser.getUid()).collection("myNotes").document();
Map<String ,Object> note= new HashMap<>();
note.put("title",title);
note.put("content",content);
DocumentReference documentReference = firebaseFirestore.collection("notes").document(firebaseUser.getUid()).collection("myNotes").document();
Map<String, Object> note = new HashMap<>();
note.put("title", title);
note.put("content", content);

documentReference.set(note).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(),"Note Created Succesffuly",Toast.LENGTH_SHORT).show();
startActivity(new Intent(createnote.this,notesactivity.class));
Toast.makeText(getApplicationContext(), "Note Created Succesffuly", Toast.LENGTH_SHORT).show();
startActivity(new Intent(createnote.this, notesactivity.class));
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(),"Failed To Create Note",Toast.LENGTH_SHORT).show();
mprogressbarofcreatenote.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "Failed To Create Note", Toast.LENGTH_SHORT).show();
binding.progressbarofcreatenote.setVisibility(View.INVISIBLE);
}
});
}
}
});






}


@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {

if(item.getItemId()==android.R.id.home)
{
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import androidx.appcompat.widget.Toolbar;

import com.example.notesapptutorial.databinding.ActivityEditnoteactivityBinding;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
Expand All @@ -25,9 +26,9 @@

public class editnoteactivity extends AppCompatActivity {

private ActivityEditnoteactivityBinding binding;

Intent data;
EditText medittitleofnote,meditcontentofnote;
FloatingActionButton msaveeditnote;

FirebaseAuth firebaseAuth;
FirebaseFirestore firebaseFirestore;
Expand All @@ -37,30 +38,30 @@ public class editnoteactivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editnoteactivity);
medittitleofnote=findViewById(R.id.edittitleofnote);
meditcontentofnote=findViewById(R.id.editcontentofnote);
msaveeditnote=findViewById(R.id.saveeditnote);

binding = ActivityEditnoteactivityBinding.inflate(getLayoutInflater());

setContentView(binding.getRoot());


data=getIntent();

firebaseFirestore=FirebaseFirestore.getInstance();
firebaseUser=FirebaseAuth.getInstance().getCurrentUser();

setSupportActionBar(binding.toolbarofeditnote);

Toolbar toolbar=findViewById(R.id.toolbarofeditnote);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);



msaveeditnote.setOnClickListener(new View.OnClickListener() {
binding.saveeditnote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(getApplicationContext(),"savebuton click",Toast.LENGTH_SHORT).show();

String newtitle=medittitleofnote.getText().toString();
String newcontent=meditcontentofnote.getText().toString();
String newtitle=binding.edittitleofnote.getText().toString();
String newcontent=binding.editcontentofnote.getText().toString();

if(newtitle.isEmpty()||newcontent.isEmpty())
{
Expand Down Expand Up @@ -93,8 +94,8 @@ public void onFailure(@NonNull Exception e) {

String notetitle=data.getStringExtra("title");
String notecontent=data.getStringExtra("content");
meditcontentofnote.setText(notecontent);
medittitleofnote.setText(notetitle);
binding.editcontentofnote.setText(notecontent);
binding.edittitleofnote.setText(notetitle);
}

@Override
Expand Down
46 changes: 20 additions & 26 deletions app/src/main/java/com/example/notesapptutorial/fogotpassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,59 @@
import android.widget.TextView;
import android.widget.Toast;

import com.example.notesapptutorial.databinding.ActivityFogotpasswordBinding;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;

public class fogotpassword extends AppCompatActivity {

private EditText mforgotpassword;
private Button mpasswordrecoverbutton;
private TextView mgobacktologin;
private ActivityFogotpasswordBinding binding;


FirebaseAuth firebaseAuth;

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

binding = ActivityFogotpasswordBinding.inflate(getLayoutInflater());

setContentView(binding.getRoot());

getSupportActionBar().hide();

mforgotpassword=findViewById(R.id.forgotpassword);
mpasswordrecoverbutton=findViewById(R.id.passwordrecoverbutton);
mgobacktologin=findViewById(R.id.gobacktologin);

firebaseAuth= FirebaseAuth.getInstance();
firebaseAuth = FirebaseAuth.getInstance();


mgobacktologin.setOnClickListener(new View.OnClickListener() {
binding.gobacktologin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(fogotpassword.this,MainActivity.class);
Intent intent = new Intent(fogotpassword.this, MainActivity.class);
startActivity(intent);
}
});

mpasswordrecoverbutton.setOnClickListener(new View.OnClickListener() {
binding.passwordrecoverbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String mail=mforgotpassword.getText().toString().trim();
if(mail.isEmpty())
{
Toast.makeText(getApplicationContext(),"Enter your mail first",Toast.LENGTH_SHORT).show();
}
else
{
String mail = binding.forgotpassword.getText().toString().trim();
if (mail.isEmpty()) {
Toast.makeText(getApplicationContext(), "Enter your mail first", Toast.LENGTH_SHORT).show();
} else {
//we have to send password recover email

firebaseAuth.sendPasswordResetEmail(mail).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {

if (task.isSuccessful())
{
Toast.makeText(getApplicationContext(),"Mail Sent , You can recover your password using mail",Toast.LENGTH_SHORT).show();
if (task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Mail Sent , You can recover your password using mail", Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(fogotpassword.this,MainActivity.class));
}
else
{
Toast.makeText(getApplicationContext(),"Email is Wrong or Account Not Exist",Toast.LENGTH_SHORT).show();
startActivity(new Intent(fogotpassword.this, MainActivity.class));
} else {
Toast.makeText(getApplicationContext(), "Email is Wrong or Account Not Exist", Toast.LENGTH_SHORT).show();
}


Expand Down
Loading