Fix: Date/time now shows last edited time, not last opened

The app was incorrectly updating the note's timestamp every time it was saved,
even when no changes were made. This caused the displayed date to show 'last
opened' instead of 'created/last edited'.

Changes:
- Added hasChanges() method to Note model to detect actual content modifications
- Added markAsSaved() method to update original values after successful save
- Modified saveNoteImmediately() to only update timestamp when changes exist
- Used transient fields for tracking original values (not serialized)
This commit is contained in:
Marvin 2026-03-17 16:21:37 -03:00
parent 0c69cd11c5
commit 7d3122f137
2 changed files with 44 additions and 1 deletions

View File

@ -257,8 +257,11 @@ public class NoteEditorFragment extends Fragment {
}
private void saveNoteImmediately() {
note.setModifiedTimestamp(System.currentTimeMillis());
if (note.hasChanges()) {
note.setModifiedTimestamp(System.currentTimeMillis());
}
storage.saveNote(note);
note.markAsSaved();
}
@Override

View File

@ -16,6 +16,11 @@ public class Note implements Serializable {
private long modifiedTimestamp;
private String content;
private List<ChecklistItem> items;
// Track original values to detect actual changes
private transient String originalTitle;
private transient String originalContent;
private transient List<String> originalItemsJson;
public Note() {
this.id = 0;
@ -24,6 +29,7 @@ public class Note implements Serializable {
this.modifiedTimestamp = System.currentTimeMillis();
this.content = "";
this.items = new ArrayList<>();
setOriginalValues();
}
public Note(int id, String title, NoteType type) {
@ -33,6 +39,40 @@ public class Note implements Serializable {
this.modifiedTimestamp = System.currentTimeMillis();
this.content = "";
this.items = new ArrayList<>();
setOriginalValues();
}
private void setOriginalValues() {
originalTitle = title != null ? title : "";
originalContent = content != null ? content : "";
if (items != null) {
originalItemsJson = new ArrayList<>();
for (ChecklistItem item : items) {
originalItemsJson.add(item.getText() + "|" + Boolean.toString(item.isChecked()));
}
} else {
originalItemsJson = new ArrayList<>();
}
}
public boolean hasChanges() {
if (!originalTitle.equals(title)) return true;
if (!originalContent.equals(content)) return true;
// Check checklist items
if (items != null && originalItemsJson != null) {
if (items.size() != originalItemsJson.size()) return true;
for (int i = 0; i < items.size(); i++) {
String expected = items.get(i).getText() + "|" + Boolean.toString(items.get(i).isChecked());
if (!expected.equals(originalItemsJson.get(i))) return true;
}
}
return false;
}
public void markAsSaved() {
setOriginalValues();
}
public int getId() {