From f242452bf2b49c0c5e83370f942b64649bf600ed Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Thu, 8 Oct 2020 15:35:05 +0200 Subject: [PATCH] #831 Migrate from SQLiteOpenHelper to Room --- .../notes/persistence/LoadNotesListTask.java | 75 ------------------- .../notes/persistence/NotesDatabase.java | 15 ++-- 2 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java deleted file mode 100644 index 094d09d7..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java +++ /dev/null @@ -1,75 +0,0 @@ -//package it.niedermann.owncloud.notes.persistence; -// -//import android.content.Context; -//import android.os.AsyncTask; -//import android.text.TextUtils; -//import android.text.format.DateUtils; -// -//import androidx.annotation.NonNull; -//import androidx.annotation.Nullable; -//import androidx.annotation.WorkerThread; -// -//import java.util.ArrayList; -//import java.util.Calendar; -//import java.util.List; -// -//import it.niedermann.owncloud.notes.R; -//import it.niedermann.owncloud.notes.main.items.section.SectionItem; -//import it.niedermann.owncloud.notes.persistence.entity.Note; -//import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; -//import it.niedermann.owncloud.notes.shared.model.OldCategory; -//import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; -//import it.niedermann.owncloud.notes.shared.model.Item; -//import it.niedermann.owncloud.notes.shared.util.NoteUtil; -// -//public class LoadNotesListTask extends AsyncTask> { -// -// private final Context context; -// private final NotesLoadedListener callback; -// private final OldCategory category; -// private final String searchQuery; -// private final long accountId; -// -// public LoadNotesListTask(long accountId, @NonNull Context context, @NonNull NotesLoadedListener callback, @NonNull OldCategory category, @Nullable CharSequence searchQuery) { -// this.context = context; -// this.callback = callback; -// this.category = category; -// this.searchQuery = searchQuery == null ? "%" : "%" + searchQuery + "%"; -// this.accountId = accountId; -// } -// -// @Override -// protected List doInBackground(Void... voids) { -// List noteList; -// NotesDatabase db = NotesDatabase.getInstance(context); -// CategorySortingMethod sortingMethod = db.getCategoryOrder(accountId, category); -// -// if(Boolean.TRUE.equals(category.favorite)) { -// noteList = db.getNoteDao().searchNotesByCategoryFavoritesDirectly(accountId, searchQuery, sortingMethod); -// } else if(TextUtils.isEmpty(category.category)) { -// noteList = db.getNoteDao().searchNotesByUncategorizedDirectly(accountId, searchQuery, sortingMethod); -// } else { -// noteList = db.getNoteDao().searchNotesByCategoryDirectly(accountId, searchQuery, category.category, sortingMethod); -// } -// -//// if (category.category == null) { -//// if (sortingMethod == CategorySortingMethod.SORT_MODIFIED_DESC) { -//// return fillListByTime(noteList); -//// } else { -//// return fillListByInitials(noteList); -//// } -//// } else { -//// return fillListByCategory(noteList); -//// } -// } -// -// @Override -// protected void onPostExecute(List items) { -// callback.onNotesLoaded(items, category.category == null, searchQuery); -// } -// -// public interface NotesLoadedListener { -// void onNotesLoaded(List notes, boolean showCategory, CharSequence searchQuery); -// } -// } -//} 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 64bdc578..7056c042 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 @@ -167,13 +167,13 @@ public abstract class NotesDatabase extends RoomDatabase { */ long addNote(long accountId, Note note) { Note entity = new Note(); - if (entity.getId() != null) { - if (entity.getId() > 0) { - entity.setId(entity.getId()); + if (note.getId() != null) { + if (note.getId() > 0) { + entity.setId(note.getId()); } - entity.setStatus(entity.getStatus()); - entity.setAccountId(entity.getAccountId()); - entity.setExcerpt(entity.getExcerpt()); + entity.setStatus(note.getStatus()); + entity.setAccountId(note.getAccountId()); + entity.setExcerpt(note.getExcerpt()); } else { entity.setStatus(DBStatus.VOID); entity.setAccountId(accountId); @@ -186,8 +186,7 @@ public abstract class NotesDatabase extends RoomDatabase { entity.setModified(note.getModified()); entity.setContent(note.getContent()); entity.setFavorite(note.getFavorite()); - // FIXME -// entity.setCategory(getOrCreateCategoryIdByTitle(accountId, note.getCategory())); + entity.setCategoryId(getOrCreateCategoryIdByTitle(accountId, note.getCategory())); entity.setETag(note.getETag()); return getNoteDao().addNote(entity); }