#831 Migrate from SQLiteOpenHelper to Room

Fix creating notes
This commit is contained in:
Stefan Niedermann 2020-10-08 13:05:40 +02:00
parent e9c0d853ac
commit 50d853ed9d
4 changed files with 8 additions and 8 deletions

View file

@ -114,7 +114,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
if (content == null) {
throw new IllegalArgumentException(PARAM_NOTE_ID + " is not given, argument " + PARAM_NEWNOTE + " is missing and " + PARAM_CONTENT + " is missing.");
} else {
note = new Note(-1, -1, null, NoteUtil.generateNoteTitle(content), content, false, getString(R.string.category_readonly), null, DBStatus.VOID, -1, "", 0);
note = new Note(-1, -1L, null, NoteUtil.generateNoteTitle(content), content, false, getString(R.string.category_readonly), null, DBStatus.VOID, -1, "", 0);
}
} else {
note = db.getNoteDao().getNote(localAccount.getId(), db.addNoteAndSync(ssoAccount, localAccount.getId(), cloudNote));

View file

@ -179,7 +179,7 @@ public class EditNoteActivity extends LockedActivity implements BaseNoteFragment
if (content == null) {
content = "";
}
Note newNote = new Note(0, Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(content, this), content, favorite, category, null);
Note newNote = new Note(null, Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(content, this), content, favorite, category, null);
fragment = NoteEditFragment.newInstanceWithNewNote(newNote);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_view, fragment).commit();
}

View file

@ -152,7 +152,7 @@ public abstract class NotesDatabase extends RoomDatabase {
* @param note Note
*/
public long addNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, Note note) {
Note entity = new Note(0, 0, note.getModified(), note.getTitle(), note.getContent(), note.getFavorite(), note.getCategory(), note.getETag(), DBStatus.LOCAL_EDITED, accountId, generateNoteExcerpt(note.getContent(), note.getTitle()), 0);
Note entity = new Note(0, null, note.getModified(), note.getTitle(), note.getContent(), note.getFavorite(), note.getCategory(), note.getETag(), DBStatus.LOCAL_EDITED, accountId, generateNoteExcerpt(note.getContent(), note.getTitle()), 0);
long id = addNote(accountId, entity);
notifyWidgets();
serverSyncHelper.scheduleSync(ssoAccount, true);
@ -179,7 +179,7 @@ public abstract class NotesDatabase extends RoomDatabase {
entity.setAccountId(accountId);
entity.setExcerpt(generateNoteExcerpt(note.getContent(), note.getTitle()));
}
if (note.getRemoteId() > 0) {
if (note.getRemoteId() != null && note.getRemoteId() > 0) {
entity.setRemoteId(note.getRemoteId());
}
entity.setTitle(note.getTitle());
@ -194,7 +194,7 @@ public abstract class NotesDatabase extends RoomDatabase {
public void moveNoteToAnotherAccount(SingleSignOnAccount ssoAccount, long oldAccountId, Note note, long newAccountId) {
// Add new note
addNoteAndSync(ssoAccount, newAccountId, new Note(0, note.getModified(), note.getTitle(), note.getContent(), note.getFavorite(), note.getCategory(), null));
addNoteAndSync(ssoAccount, newAccountId, new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getFavorite(), note.getCategory(), null));
deleteNoteAndSync(ssoAccount, note.getId());
notifyWidgets();
@ -261,7 +261,7 @@ public abstract class NotesDatabase extends RoomDatabase {
if (newTitle != null) {
title = newTitle;
} else {
if (oldNote.getRemoteId() == 0 || localAccount.getPreferredApiVersion() == null || localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) < 0) {
if (oldNote.getRemoteId() == null || oldNote.getRemoteId() == 0 || localAccount.getPreferredApiVersion() == null || localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) < 0) {
title = NoteUtil.generateNonEmptyNoteTitle(newContent, context);
} else {
title = oldNote.getTitle();

View file

@ -64,7 +64,7 @@ public class Note implements Serializable {
}
@Ignore
public Note(long remoteId, Calendar modified, String title, String content, Boolean favorite, String category, String eTag) {
public Note(Long remoteId, Calendar modified, String title, String content, Boolean favorite, String category, String eTag) {
this.remoteId = remoteId;
this.title = title;
this.modified = modified;
@ -75,7 +75,7 @@ public class Note implements Serializable {
}
@Ignore
public Note(long id, long remoteId, Calendar modified, String title, String content, boolean favorite, String category, String etag, DBStatus status, long accountId, @NonNull String excerpt, Integer scrollY) {
public Note(long id, Long remoteId, Calendar modified, String title, String content, boolean favorite, String category, String etag, DBStatus status, long accountId, @NonNull String excerpt, Integer scrollY) {
this(remoteId, modified, title, content, favorite, category, etag);
this.id = id;
this.status = status;