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

Edit Note and View Note functionality Updated #14

Merged
merged 1 commit into from
May 27, 2024
Merged
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
74 changes: 74 additions & 0 deletions app/src/main/java/com/example/notemania/editnoteactivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
package com.example.notemania;

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

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap;
import java.util.Map;

public class editnoteactivity extends AppCompatActivity {

Intent data;
EditText medittitleofnote,meditcontentofnote;
FloatingActionButton msaveeditnote;
FirebaseAuth firebaseAuth;
FirebaseFirestore firebaseFirestore;
FirebaseUser firebaseUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -20,5 +44,55 @@ protected void onCreate(Bundle savedInstanceState) {
// v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
// return insets;
// });
medittitleofnote=findViewById(R.id.edittitleofnote);
meditcontentofnote=findViewById(R.id.editcontentofnote);
msaveeditnote=findViewById(R.id.saveeditnote);
data=getIntent();

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

Toolbar toolbar=findViewById(R.id.toolbarforeditnote);

setSupportActionBar(toolbar);//Lookout
getSupportActionBar().setDisplayHomeAsUpEnabled(true);//lookout

msaveeditnote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(getApplicationContext(),"Saved Button Clicked",Toast.LENGTH_SHORT).show();

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

if(newtitle.isEmpty() || newcontent.isEmpty()){
Toast.makeText(getApplicationContext(),"Something is empty",Toast.LENGTH_SHORT).show();
return;
}
else{
DocumentReference documentReference=firebaseFirestore.collection("notes").document(firebaseUser.getUid()).collection("myNotes").document(data.getStringExtra("noteId"));
Map<String,Object> note=new HashMap<>();
note.put("title",newtitle);
note.put("content",newcontent);
documentReference.set(note).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(),"Note is updated",Toast.LENGTH_SHORT).show();
startActivity(new Intent(editnoteactivity.this,notesActivity.class));
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(),"Failed to update",Toast.LENGTH_SHORT).show();
}
});
}
}
});

String notetitle=data.getStringExtra("title");
String notecontent=data.getStringExtra("content");
meditcontentofnote.setText(notecontent);
medittitleofnote.setText(notetitle);
}
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/notemania/notedetails.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.example.notemania;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
Expand All @@ -28,5 +33,31 @@ protected void onCreate(Bundle savedInstanceState) {
mtitleofnotedetail=findViewById(R.id.titleofnotedetail);
mcontentofnotedetail=findViewById(R.id.contentofnotedetail);
mgotoeditnote=findViewById(R.id.gotoeditnote);
Toolbar toolbar=findViewById(R.id.toolbarfornotedetail);
setSupportActionBar(toolbar);//lookout
getSupportActionBar().setDisplayHomeAsUpEnabled(true);//lookout
Intent data=getIntent();

mgotoeditnote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(v.getContext(),editnoteactivity.class);
intent.putExtra("title",data.getStringExtra("title"));
intent.putExtra("content",data.getStringExtra("content"));
intent.putExtra("noteId",data.getStringExtra("noteId"));
v.getContext().startActivity(intent);
}
});

mcontentofnotedetail.setText(data.getStringExtra("content"));
mtitleofnotedetail.setText(data.getStringExtra("title"));
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if(item.getItemId()==android.R.id.home){
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_editnoteactivity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
android:layout_alignParentEnd="true"
android:layout_marginBottom="30dp"
android:layout_marginEnd="30dp"
android:layout_gravity="bottom|end"
android:id="@+id/saveeditnote"
android:src="@drawable/baseline_arrow_circle_up_24"
app:backgroundTint="#A1F4FB"
app:backgroundTint="#A1F4AB"
app:maxImageSize="40dp" />

</RelativeLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_notedetails.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
android:layout_alignParentEnd="true"
android:layout_marginBottom="30dp"
android:layout_marginEnd="30dp"
android:layout_gravity="bottom|end"
android:id="@+id/gotoeditnote"
android:src="@drawable/baseline_edit_24"
app:backgroundTint="#A1F4FB"
app:backgroundTint="#A1F4AB"
app:maxImageSize="40dp" />

</RelativeLayout>
Loading