mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-23 05:16:15 +03:00
#831 Migrate from SQLiteOpenHelper to Room
This commit is contained in:
parent
92d0438751
commit
f242452bf2
2 changed files with 7 additions and 83 deletions
|
@ -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<Void, Void, List<Item>> {
|
||||
//
|
||||
// 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<Item> doInBackground(Void... voids) {
|
||||
// List<NoteWithCategory> 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<Item> items) {
|
||||
// callback.onNotesLoaded(items, category.category == null, searchQuery);
|
||||
// }
|
||||
//
|
||||
// public interface NotesLoadedListener {
|
||||
// void onNotesLoaded(List<Item> notes, boolean showCategory, CharSequence searchQuery);
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue