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

Note Delete Functionality Updated #13

Merged
merged 1 commit into from
May 25, 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
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
tools:targetApi="31">
<activity
android:name=".notedetails"
android:exported="false" />
android:exported="false"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"/>
<activity
android:name=".editnoteactivity"
android:exported="false" />
android:exported="false"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"/>
<activity
android:name=".createnote"
android:exported="false"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/example/notemania/editnoteactivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class editnoteactivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
// EdgeToEdge.enable(this);
setContentView(R.layout.activity_editnoteactivity);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
// ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
// Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
// v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
// return insets;
// });
}
}
20 changes: 14 additions & 6 deletions app/src/main/java/com/example/notemania/notedetails.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package com.example.notemania;

import android.os.Bundle;
import android.widget.TextView;

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.material.floatingactionbutton.FloatingActionButton;

public class notedetails extends AppCompatActivity {

private TextView mtitleofnotedetail,mcontentofnotedetail;
FloatingActionButton mgotoeditnote;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
// EdgeToEdge.enable(this);
setContentView(R.layout.activity_notedetails);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
// ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
// Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
// v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
// return insets;
// });
mtitleofnotedetail=findViewById(R.id.titleofnotedetail);
mcontentofnotedetail=findViewById(R.id.contentofnotedetail);
mgotoeditnote=findViewById(R.id.gotoeditnote);
}
}
27 changes: 25 additions & 2 deletions app/src/main/java/com/example/notemania/notesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@

import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
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 com.google.firebase.firestore.Query;

Expand Down Expand Up @@ -79,12 +82,17 @@ protected void onBindViewHolder(@NonNull NoteViewHolder noteViewHolder,int i,@No
noteViewHolder.notetitle.setText(firebasemodel.getTitle());
noteViewHolder.notecontent.setText(firebasemodel.getContent());

String docId=noteAdapter.getSnapshots().getSnapshot(i).getId();

noteViewHolder.itemView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v){
//we have to open note detail activity
Intent intent=new Intent(v.getContext(),notedetails.class);
intent.putExtra("title",firebasemodel.getTitle());
intent.putExtra("content",firebasemodel.getContent());
intent.putExtra("noteId",docId);
v.getContext().startActivity(intent);
//Toast.makeText(getApplicationContext(),"This is Clicked",Toast.LENGTH_SHORT).show();
}
Expand All @@ -99,14 +107,29 @@ public void onClick(View v){
@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
Intent intent=new Intent(v.getContext(),editnoteactivity.class);
intent.putExtra("title",firebasemodel.getTitle());
intent.putExtra("content",firebasemodel.getContent());
intent.putExtra("noteId",docId);
v.getContext().startActivity(intent);
return false;
}
});
popupMenu.getMenu().add("Delete").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
@Override
public boolean onMenuItemClick(MenuItem item){
Toast.makeText(v.getContext(),"This Note is Deleted",Toast.LENGTH_SHORT).show();
// Toast.makeText(v.getContext(),"This Note is Deleted",Toast.LENGTH_SHORT).show();
DocumentReference documentReference= firebaseFirestore.collection("notes").document(firebaseUser.getUid()).collection("myNotes").document(docId);
documentReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Toast.makeText(v.getContext(),"This Note is Deleted",Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(v.getContext(),"Failed to Delete",Toast.LENGTH_SHORT).show();
}
});
return false;
}
});
Expand Down Expand Up @@ -176,7 +199,7 @@ protected void onStart() {
protected void onStop() {
super.onStop();
if(noteAdapter!=null){
noteAdapter.startListening();
noteAdapter.stopListening();
}
}
private int getRandomcolor()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_arrow_circle_up_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8s8,3.59 8,8S16.41,20 12,20M12,22c5.52,0 10,-4.48 10,-10c0,-5.52 -4.48,-10 -10,-10C6.48,2 2,6.48 2,12C2,17.52 6.48,22 12,22L12,22zM11,12l0,4h2l0,-4h3l-4,-4l-4,4H11z"/>

</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_edit_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>

</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_editnoteactivity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
android:layout_marginBottom="30dp"
android:layout_marginEnd="30dp"
android:id="@+id/saveeditnote"
android:src="@drawable/update"
android:src="@drawable/baseline_arrow_circle_up_24"
app:backgroundTint="#A1F4FB"
app:maxImageSize="56dp" />
app:maxImageSize="40dp" />

</RelativeLayout>
10 changes: 6 additions & 4 deletions app/src/main/res/layout/activity_notedetails.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

</androidx.appcompat.widget.Toolbar>

<EditText
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="17sp"
Expand All @@ -41,7 +41,9 @@
android:hint="Enter your note content here"
android:layout_below="@id/toolbarfornotedetail"
android:padding="15dp"
android:id="@+id/contentofnotedetail" />
android:id="@+id/contentofnotedetail">

</TextView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
Expand All @@ -51,8 +53,8 @@
android:layout_marginBottom="30dp"
android:layout_marginEnd="30dp"
android:id="@+id/gotoeditnote"
android:src="@drawable/edit"
android:src="@drawable/baseline_edit_24"
app:backgroundTint="#A1F4FB"
app:maxImageSize="56dp" />
app:maxImageSize="40dp" />

</RelativeLayout>
Loading