Don't overwrite DB Status LOCAL_CREATED with LOCAL_EDITED

To prevent errors on synchronization (create -> edit -> sync)
This commit is contained in:
Stefan Niedermann 2016-03-09 14:47:22 +01:00
parent 37df7dd93c
commit eb6e2b0d74

View file

@ -226,9 +226,26 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
@SuppressWarnings("UnusedReturnValue")
public int updateNoteAndSync(Note note) {
SQLiteDatabase db = this.getWritableDatabase();
DBStatus newStatus = DBStatus.LOCAL_EDITED;
Cursor cursor =
db.query(table_notes,
columns,
key_id + " = ? AND " + key_status + " != ?",
new String[]{String.valueOf(note.getId()), DBStatus.LOCAL_DELETED.getTitle()},
null,
null,
null,
null);
if (cursor != null) {
cursor.moveToFirst();
if (DBStatus.valueOf(cursor.getString(1)) == DBStatus.LOCAL_CREATED) {
newStatus = DBStatus.LOCAL_CREATED;
}
cursor.close();
}
ContentValues values = new ContentValues();
values.put(key_id, note.getId());
values.put(key_status, DBStatus.LOCAL_EDITED.getTitle());
values.put(key_status, newStatus.getTitle());
values.put(key_title, note.getTitle());
values.put(key_modified, note.getModified(DATE_FORMAT));
values.put(key_content, note.getContent());