diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java
index 41979865..18d56ebb 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java
@@ -62,6 +62,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
private DBNote originalNote;
protected NotesDatabase db;
private NoteFragmentListener listener;
+ private boolean titleModified = false;
protected boolean isNew = true;
@@ -242,7 +243,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
}
public void onCloseNote() {
- if (originalNote == null && getContent().isEmpty()) {
+ if (!titleModified && originalNote == null && getContent().isEmpty()) {
db.deleteNoteAndSync(ssoAccount, note.getId());
}
}
@@ -261,6 +262,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
} else {
note = db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, newContent, callback);
listener.onNoteUpdated(note);
+ requireActivity().invalidateOptionsMenu();
}
} else {
Log.e(TAG, "note is null");
@@ -327,7 +329,9 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
@Override
public void onTitleEdited(String newTitle) {
-// db.setTitle(ssoAccount, note, newTitle);
+ titleModified = true;
+ note.setTitle(newTitle);
+ note = db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, note.getContent(), newTitle, null);
listener.onNoteUpdated(note);
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
index ac2c3ec5..63b71ece 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
@@ -492,22 +492,36 @@ public class NotesDatabase extends AbstractNotesDatabase {
return db.insert(table_category, null, values);
}
+ public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable ISyncCallback callback) {
+ return updateNoteAndSync(ssoAccount, accountId, oldNote, newContent, null, callback);
+ }
+
/**
* Updates a single Note with a new content.
* The title is derived from the new content automatically, and modified date as well as DBStatus are updated, too -- if the content differs to the state in the database.
*
* @param oldNote Note to be changed
* @param newContent New content. If this is null
, then oldNote
is saved again (useful for undoing changes).
+ * @param newTitle New title. If this is null
, then either the old title is reused (in case the note has been synced before) or a title is generated (in case it is a new note)
* @param callback When the synchronization is finished, this callback will be invoked (optional).
* @return changed note if differs from database, otherwise the old note.
*/
- public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable ISyncCallback callback) {
- //debugPrintFullDB();
+ public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) {
DBNote newNote;
if (newContent == null) {
newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, oldNote.getExcerpt());
} else {
- newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), oldNote.getRemoteId() == 0 ? NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()) : oldNote.getTitle(), newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(newContent));
+ final String title;
+ if (newTitle != null) {
+ title = newTitle;
+ } else {
+ if (oldNote.getRemoteId() == 0) {
+ title = NoteUtil.generateNonEmptyNoteTitle(newContent, getContext());
+ } else {
+ title = oldNote.getTitle();
+ }
+ }
+ newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, accountId, NoteUtil.generateNoteExcerpt(newContent));
}
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java
index 0db9b3ea..65a3b445 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/util/NoteUtil.java
@@ -73,7 +73,7 @@ public class NoteUtil {
* @return truncated string
*/
@NonNull
- private static String truncateString(@NonNull String str, int len) {
+ private static String truncateString(@NonNull String str, @SuppressWarnings("SameParameterValue") int len) {
return str.substring(0, Math.min(len, str.length()));
}