You can now delete notes by long pressing the save button

This commit is contained in:
Bradley Bickford 2025-04-13 20:28:48 -04:00
parent 22306965ed
commit 0e2bfece64

View File

@ -1,10 +1,12 @@
package com.coldlightalchemist.notesapp;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
@ -72,5 +74,30 @@ public class NewNote extends AppCompatActivity {
finish();
});
saveNote.setOnLongClickListener((v) -> {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(v.getContext());
DialogInterface.OnClickListener listener = (d, w) -> {
switch(w) {
case DialogInterface.BUTTON_POSITIVE:
if(note != null) {
NoteDB.getDB(getApplicationContext()).noteDAO().delete(note);
}
finish();
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
};
alertBuilder.setMessage("Are you sure you want to delete this note?")
.setPositiveButton("Yes", listener)
.setNegativeButton("No", listener)
.show();
return true;
});
}
}