diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-10-07 12:20:50 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-10-07 12:20:50 +0300 |
commit | 457a90b8c95754e3eb6b012c6ec341c911150b9d (patch) | |
tree | f63b0852a956f8b03537be5dda29fc8fdba66039 /app/src/main/java/it/niedermann/owncloud | |
parent | 8eed93b90d5db6d0e3de33dacce58f9d4fcdde00 (diff) |
#831 Migrate from SQLiteOpenHelper to Room
Try to map table and column names for easier migration
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud')
25 files changed, 196 insertions, 175 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java index 8ddb26ca..a342ee3e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java @@ -327,7 +327,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (frag != null) { manager.beginTransaction().remove(frag).commit(); } - final DialogFragment categoryFragment = CategoryDialogFragment.newInstance(note.getAccountId(), note.getCategory().getTitle()); + final DialogFragment categoryFragment = CategoryDialogFragment.newInstance(note.getAccountId(), note.getCategory()); categoryFragment.setTargetFragment(this, 0); categoryFragment.show(manager, fragmentId); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java index 8e533ae8..ea8f6836 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java @@ -254,10 +254,10 @@ public class EditNoteActivity extends LockedActivity implements BaseNoteFragment public void onNoteUpdated(Note note) { if (note != null) { binding.toolbar.setTitle(note.getTitle()); - if (note.getCategory().getTitle().isEmpty()) { + if (note.getCategory().isEmpty()) { binding.toolbar.setSubtitle(null); } else { - binding.toolbar.setSubtitle(NoteUtil.extendCategory(note.getCategory().getTitle())); + binding.toolbar.setSubtitle(NoteUtil.extendCategory(note.getCategory())); } } else { // Maybe account is not authenticated -> note == null diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index 4fe4423e..f5e19988 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -991,9 +991,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V public void onCategoryChosen(String category) { for (Integer i : new ArrayList<>(adapter.getSelected())) { Note note = (Note) adapter.getItem(i); - Category c = new Category(); - c.setTitle(category); - note.setCategory(c); + note.setCategory(category); db.setCategory(ssoAccount, note, category, this::refreshLists); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java index 87d78b36..144a3ee0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java @@ -226,7 +226,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i if (getItem(position).isSection()) return TYPE_SECTION; Note note = (Note) getItem(position); if (TextUtils.isEmpty(note.getExcerpt())) { - if (TextUtils.isEmpty(note.getCategory().getTitle())) { + if (TextUtils.isEmpty(note.getCategory())) { return TYPE_NOTE_ONLY_TITLE; } else { return TYPE_NOTE_WITHOUT_EXCERPT; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java index d962c0c4..518cfc9b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java @@ -42,7 +42,7 @@ public class NoteViewGridHolder extends NoteViewHolder { public void bind(@NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { super.bind(note, showCategory, mainColor, textColor, searchQuery); @NonNull final Context context = itemView.getContext(); - bindCategory(context, binding.noteCategory, showCategory, note.getCategory().getTitle(), mainColor); + bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), mainColor); bindFavorite(binding.noteFavorite, note.getFavorite()); bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java index cd937733..2964a9cf 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java @@ -32,7 +32,7 @@ public class NoteViewHolderWithExcerpt extends NoteViewHolder { super.bind(note, showCategory, mainColor, textColor, searchQuery); @NonNull final Context context = itemView.getContext(); binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f); - bindCategory(context, binding.noteCategory, showCategory, note.getCategory().getTitle(), mainColor); + bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), mainColor); bindFavorite(binding.noteFavorite, note.getFavorite()); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java index ab4e31c7..33d9fc37 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java @@ -32,7 +32,7 @@ public class NoteViewHolderWithoutExcerpt extends NoteViewHolder { super.bind(note, showCategory, mainColor, textColor, searchQuery); @NonNull final Context context = itemView.getContext(); binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f); - bindCategory(context, binding.noteCategory, showCategory, note.getCategory().getTitle(), mainColor); + bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), mainColor); bindFavorite(binding.noteFavorite, note.getFavorite()); bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); 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 index b54015ac..993a044f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java @@ -62,11 +62,11 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> { for (Note entity : noteList) { Note note = entity; if (currentCategory != null && !currentCategory.equals(note.getCategory())) { - itemList.add(new SectionItem(NoteUtil.extendCategory(note.getCategory().getTitle()))); + itemList.add(new SectionItem(NoteUtil.extendCategory(note.getCategory()))); } itemList.add(note); - currentCategory = note.getCategory().getTitle(); + currentCategory = note.getCategory(); } return itemList; } 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 d832d15c..02f34afb 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 @@ -137,7 +137,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().getTitle(), note.getETag(), DBStatus.LOCAL_EDITED, accountId, generateNoteExcerpt(note.getContent(), note.getTitle()), 0); + 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); long id = addNote(accountId, entity); notifyWidgets(); serverSyncHelper.scheduleSync(ssoAccount, true); @@ -179,7 +179,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().getTitle(), null)); + addNoteAndSync(ssoAccount, newAccountId, new Note(0, note.getModified(), note.getTitle(), note.getContent(), note.getFavorite(), note.getCategory(), null)); deleteNoteAndSync(ssoAccount, note.getId()); notifyWidgets(); @@ -260,9 +260,9 @@ public abstract class NotesDatabase extends RoomDatabase { * @param callback When the synchronization is finished, this callback will be invoked (optional). */ public void setCategory(SingleSignOnAccount ssoAccount, @NonNull Note note, @NonNull String category, @Nullable ISyncCallback callback) { - note.setCategory(getCategoryDao().getCategory(getCategoryDao().getCategoryIdByTitle(getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name).getId(), category))); + note.setCategory(category); getNoteDao().updateStatus(note.getId(), DBStatus.LOCAL_DELETED); - long categoryId = getOrCreateCategoryIdByTitle(note.getAccountId(), note.getCategory().getTitle()); + long categoryId = getOrCreateCategoryIdByTitle(note.getAccountId(), note.getCategory()); getNoteDao().updateCategory(note.getId(), categoryId); getCategoryDao().removeEmptyCategory(note.getAccountId()); if (callback != null) { @@ -284,7 +284,7 @@ public abstract class NotesDatabase extends RoomDatabase { public Note updateNoteAndSync(SingleSignOnAccount ssoAccount, @NonNull LocalAccount localAccount, @NonNull Note oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) { Note newNote; if (newContent == null) { - newNote = new Note(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.getFavorite(), oldNote.getCategory().getTitle(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY()); + newNote = new Note(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.getFavorite(), oldNote.getCategory(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY()); } else { final String title; if (newTitle != null) { @@ -296,7 +296,7 @@ public abstract class NotesDatabase extends RoomDatabase { title = oldNote.getTitle(); } } - newNote = new Note(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.getFavorite(), oldNote.getCategory().getTitle(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title), oldNote.getScrollY()); + newNote = new Note(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.getFavorite(), oldNote.getCategory(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title), oldNote.getScrollY()); } int rows = getNoteDao().updateNote(newNote); getCategoryDao().removeEmptyCategory(localAccount.getId()); @@ -612,9 +612,9 @@ public abstract class NotesDatabase extends RoomDatabase { // The other columns have to be updated in dependency of forceUnchangedDBNoteState, // since the Synchronization-Task must not overwrite locales changes! if (forceUnchangedDBNoteState != null) { - getNoteDao().updateIfModifiedLocallyDuringSync(id, remoteNote.getModified().getTimeInMillis() / 1000, remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getCategory().getTitle(), remoteNote.getETag(), remoteNote.getContent()); + getNoteDao().updateIfModifiedLocallyDuringSync(id, remoteNote.getModified().getTimeInMillis() / 1000, remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getCategory(), remoteNote.getETag(), remoteNote.getContent()); } else { - getNoteDao().updateIfNotModifiedLocallyAndRemoteColumnHasChanged(id, remoteNote.getModified().getTimeInMillis() / 1000, remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getCategory().getTitle(), remoteNote.getETag(), remoteNote.getContent()); + getNoteDao().updateIfNotModifiedLocallyAndRemoteColumnHasChanged(id, remoteNote.getModified().getTimeInMillis() / 1000, remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getCategory(), remoteNote.getETag(), remoteNote.getContent()); } getCategoryDao().removeEmptyCategory(accountId); Log.d(TAG, "updateNote: " + remoteNote + " || forceUnchangedDBNoteState: " + forceUnchangedDBNoteState + ""); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java index 85a1dee1..dd9e7506 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java @@ -16,7 +16,7 @@ public interface CategoryDao { @Insert Long addCategory(Category entity); - @Query("SELECT * FROM Category WHERE id = :id") + @Query("SELECT * FROM CATEGORIES WHERE CATEGORY_ID = :id") Category getCategory(long id); /** @@ -28,10 +28,10 @@ public interface CategoryDao { * * @param accountId The user accountId */ - @Query("DELETE FROM Category WHERE accountId = :accountId AND id NOT IN (SELECT categoryId FROM Note)") + @Query("DELETE FROM CATEGORIES WHERE CATEGORY_ACCOUNT_ID = :accountId AND CATEGORY_ID NOT IN (SELECT CATEGORY_ID FROM NOTES)") void removeEmptyCategory(long accountId); - @Query("SELECT id FROM Category WHERE accountId = :accountId AND title = :title") + @Query("SELECT CATEGORY_ID FROM CATEGORIES WHERE CATEGORY_ACCOUNT_ID = :accountId AND CATEGORY_TITLE = :title") Long getCategoryIdByTitle(long accountId, String title); @@ -44,7 +44,7 @@ public interface CategoryDao { * @param categoryTitle The category title * @param sortingMethod The sorting method in {@link CategorySortingMethod} enum format */ - @Query("UPDATE Category SET categorySortingMethod = :sortingMethod WHERE id = (SELECT id FROM Category WHERE accountId = :accountId AND title = :categoryTitle)") + @Query("UPDATE CATEGORIES SET CATEGORY_SORTING_METHOD = :sortingMethod WHERE CATEGORY_ID = (SELECT CATEGORY_ID FROM CATEGORIES WHERE CATEGORY_ACCOUNT_ID = :accountId AND CATEGORY_TITLE = :categoryTitle)") void modifyCategoryOrderByTitle(long accountId, String categoryTitle, CategorySortingMethod sortingMethod); /** @@ -56,13 +56,13 @@ public interface CategoryDao { * @param categoryTitle The category title * @return The sorting method in {@link CategorySortingMethod} enum format */ - @Query("SELECT categorySortingMethod FROM Category WHERE accountId = :accountId AND title = :categoryTitle") + @Query("SELECT CATEGORY_SORTING_METHOD FROM CATEGORIES WHERE CATEGORY_ACCOUNT_ID = :accountId AND CATEGORY_TITLE = :categoryTitle") CategorySortingMethod getCategoryOrderByTitle(long accountId, String categoryTitle); - @Query("SELECT title FROM Category WHERE id = :categoryId") + @Query("SELECT CATEGORY_TITLE FROM CATEGORIES WHERE CATEGORY_ID = :categoryId") String getCategoryTitleById(long categoryId); - @Query("SELECT Category.id, Category.title, COUNT(*) as 'totalNotes' FROM Category INNER JOIN Note ON Category.id = Note.category_id" + - " WHERE Note.status != 'LOCAL_DELETED' AND Note.accountId = :accountId AND Category.title LIKE '%' + :categoryTitle + '%' GROUP BY Category.title") + @Query("SELECT CATEGORY_ID, CATEGORY_TITLE, COUNT(*) as 'totalNotes' FROM CATEGORIES INNER JOIN NOTES ON CATEGORY_ID = CATEGORY" + + " WHERE STATUS != 'LOCAL_DELETED' AND NOTES.ACCOUNT_ID = :accountId AND CATEGORY_TITLE LIKE '%' + :categoryTitle + '%' GROUP BY CATEGORY_TITLE") List<CategoryWithNotesCount> searchCategories(Long accountId, String categoryTitle); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java index 72e428e5..9afb2259 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java @@ -18,30 +18,30 @@ public interface LocalAccountDao { @Delete int deleteAccount(LocalAccount localAccount); - @Query("SELECT * FROM LocalAccount WHERE id = :accountId") + @Query("SELECT * FROM ACCOUNTS WHERE ID = :accountId") LocalAccount getAccount(long accountId); - @Query("SELECT * FROM LocalAccount WHERE accountName = :accountName") + @Query("SELECT * FROM ACCOUNTS WHERE ACCOUNT_NAME = :accountName") LocalAccount getLocalAccountByAccountName(String accountName); - @Query("SELECT * FROM LocalAccount") + @Query("SELECT * FROM ACCOUNTS") List<LocalAccount> getAccounts(); - @Query("SELECT COUNT(*) FROM LocalAccount") + @Query("SELECT COUNT(*) FROM ACCOUNTS") Integer getAccountsCount(); - @Query("UPDATE LocalAccount SET color = :color AND textColor = :textColor WHERE id = :id") + @Query("UPDATE ACCOUNTS SET COLOR = :color AND TEXT_COLOR = :textColor WHERE id = :id") void updateBrand(long id, String color, String textColor); - @Query("UPDATE LocalAccount SET eTag = :eTag WHERE id = :id") + @Query("UPDATE ACCOUNTS SET ETAG = :eTag WHERE ID = :id") void updateETag(long id, String eTag); - @Query("UPDATE LocalAccount SET capabilitiesETag = :capabilitiesETag WHERE id = :id") + @Query("UPDATE ACCOUNTS SET CAPABILITIES_ETAG = :capabilitiesETag WHERE id = :id") void updateCapabilitiesETag(long id, String capabilitiesETag); - @Query("UPDATE LocalAccount SET modified = :modified WHERE id = :id") + @Query("UPDATE ACCOUNTS SET MODIFIED = :modified WHERE id = :id") void updateModified(long id, long modified); - @Query("UPDATE LocalAccount SET apiVersion = :apiVersion WHERE id = :id") + @Query("UPDATE ACCOUNTS SET API_VERSION = :apiVersion WHERE id = :id") int updateApiVersion(Long id, String apiVersion); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java index 5c8b6242..97becceb 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java @@ -23,7 +23,7 @@ public interface NoteDao { @Update(onConflict = OnConflictStrategy.REPLACE) int updateNote(Note newNote); - @Query("DELETE FROM Note WHERE accountId = :accountId") + @Query("DELETE FROM NOTES WHERE ACCOUNT_ID = :accountId") int deleteByAccountId(Long accountId); /** @@ -31,22 +31,22 @@ public interface NoteDao { * * @return List<Note> */ - @Query("SELECT * FROM Note WHERE accountId = :accountId AND status != 'LOCAL_DELETED' ORDER BY favorite DESC, modified DESC") + @Query("SELECT * FROM NOTES WHERE ACCOUNT_ID = :accountId AND status != 'LOCAL_DELETED' ORDER BY favorite DESC, modified DESC") List<Note> getNotes(long accountId); - @Query("DELETE FROM Note WHERE id = :id and status = :forceDBStatus") + @Query("DELETE FROM NOTES WHERE id = :id and status = :forceDBStatus") void deleteByCardId(long id, DBStatus forceDBStatus); - @Query("UPDATE Note SET scrollY = :scrollY WHERE id = :id") + @Query("UPDATE NOTES SET SCROLL_Y = :scrollY WHERE id = :id") void updateScrollY(long id, int scrollY); - @Query("SELECT * FROM Note WHERE id = :id AND accountId = :accountId AND status != :accountId") + @Query("SELECT * FROM NOTES WHERE id = :id AND ACCOUNT_ID = :accountId AND status != :accountId") Note getNote(long accountId, long id); - @Query("UPDATE Note SET status = :status WHERE id = :id") + @Query("UPDATE NOTES SET status = :status WHERE id = :id") void updateStatus(long id, DBStatus status); - @Query("UPDATE Note SET category_id = :categoryId WHERE id = :id") + @Query("UPDATE NOTES SET CATEGORY = :categoryId WHERE id = :id") void updateCategory(long id, long categoryId); /** @@ -55,10 +55,10 @@ public interface NoteDao { * @param accountId get the remoteIds from all notes of this account * @return {@link Set<String>} remoteIds from all notes */ - @Query("SELECT DISTINCT remoteId FROM Note WHERE accountId = :accountId AND status != 'LOCAL_DELETED'") + @Query("SELECT DISTINCT remoteId FROM NOTES WHERE ACCOUNT_ID = :accountId AND status != 'LOCAL_DELETED'") List<Long> getRemoteIds(long accountId); - @Query("SELECT * FROM Note WHERE accountId = :accountId AND status != 'LOCAL_DELETED'") + @Query("SELECT * FROM NOTES WHERE ACCOUNT_ID = :accountId AND status != 'LOCAL_DELETED'") List<Note> getRemoteIdAndId(long accountId); /** @@ -67,13 +67,13 @@ public interface NoteDao { * @param remoteId int - remote ID of the requested Note * @return {@link Note#getId()} */ - @Query("SELECT id FROM Note WHERE accountId = :accountId AND remoteId = :remoteId AND status != 'LOCAL_DELETED'") + @Query("SELECT id FROM NOTES WHERE ACCOUNT_ID = :accountId AND remoteId = :remoteId AND status != 'LOCAL_DELETED'") Long getLocalIdByRemoteId(long accountId, long remoteId); - @Query("SELECT COUNT(*) FROM Note WHERE status != 'LOCAL_DELETED' AND accountId = :accountId AND favorite = 1") + @Query("SELECT COUNT(*) FROM NOTES WHERE status != 'LOCAL_DELETED' AND ACCOUNT_ID = :accountId AND favorite = 1") Integer getFavoritesCount(long accountId); - @Query("SELECT COUNT(*) FROM Note WHERE status != 'LOCAL_DELETED' AND accountId = :accountId AND favorite = 0") + @Query("SELECT COUNT(*) FROM NOTES WHERE status != 'LOCAL_DELETED' AND ACCOUNT_ID = :accountId AND favorite = 0") Integer getNonFavoritesCount(long accountId); /** @@ -81,40 +81,40 @@ public interface NoteDao { * * @return {@link List< Note >} */ - @Query("SELECT * FROM Note WHERE status != '' AND accountId = :accountId") + @Query("SELECT * FROM NOTES WHERE status != '' AND ACCOUNT_ID = :accountId") List<Note> getLocalModifiedNotes(long accountId); - @Query("SELECT * FROM Note WHERE status != 'LOCAL_DELETED' AND accountId = :accountId ORDER BY modified DESC LIMIT 4") + @Query("SELECT * FROM NOTES WHERE status != 'LOCAL_DELETED' AND ACCOUNT_ID = :accountId ORDER BY modified DESC LIMIT 4") List<Note> getRecentNotes(long accountId); - @Query("UPDATE Note SET status = 'LOCAL_EDITED', favorite = ((favorite | 1) - (favorite & 1)) WHERE id = :id") + @Query("UPDATE NOTES SET status = 'LOCAL_EDITED', favorite = ((favorite | 1) - (favorite & 1)) WHERE id = :id") void toggleFavorite(long id); - @Query("SELECT * FROM Note WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE '%' + :query + '%' OR content LIKE '%' + :query + '%' OR category_title LIKE '%' + :query + '%') AND (category_title = :category OR title LIKE :category + '/%') AND favorite = :favorite ORDER BY favorite DESC, :sortingMethod") + @Query("SELECT * FROM NOTES WHERE ACCOUNT_ID = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE '%' + :query + '%' OR content LIKE '%' + :query + '%' OR CATEGORY LIKE '%' + :query + '%') AND (CATEGORY = :category OR title LIKE :category + '/%') AND favorite = :favorite ORDER BY favorite DESC, :sortingMethod") List<Note> searchNotes(long accountId, String query, String category, Boolean favorite, CategorySortingMethod sortingMethod); /** * Needed for subcategories, see https://github.com/stefan-niedermann/nextcloud-notes/issues/902 */ - @Query("SELECT * FROM Note WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE '%' + :query + '%' OR content LIKE '%' + :query + '%' OR category_title LIKE '%' + :query + '%') AND (category_title = :category OR title LIKE :category + '/%') AND favorite = :favorite ORDER BY category_title, favorite DESC, :sortingMethod") + @Query("SELECT * FROM NOTES WHERE ACCOUNT_ID = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE '%' + :query + '%' OR content LIKE '%' + :query + '%' OR CATEGORY LIKE '%' + :query + '%') AND (CATEGORY = :category OR title LIKE :category + '/%') AND favorite = :favorite ORDER BY CATEGORY, favorite DESC, :sortingMethod") List<Note> searchNotesSubcategory(long accountId, String query, String category, Boolean favorite, CategorySortingMethod sortingMethod); - @Query("UPDATE Note SET remoteId = :remoteId WHERE id = :id") + @Query("UPDATE NOTES SET remoteId = :remoteId WHERE id = :id") void updateRemoteId(long id, long remoteId); /** * used by: {@link NoteServerSyncHelper.SyncTask#pushLocalChanges()} update only, if not modified locally during the synchronization * (i.e. all (!) user changeable columns (content, favorite, category) must still have the same value), uses reference value gathered at start of synchronization */ - @Query("UPDATE Note SET id = :id, title = :title, modified = :modified, title = :title, favorite = :favorite, etag = :eTag, content = :content " + - "WHERE id = :id AND content = :content AND favorite = :favorite AND category_title = :categoryTitle") + @Query("UPDATE NOTES SET id = :id, title = :title, modified = :modified, title = :title, favorite = :favorite, etag = :eTag, content = :content " + + "WHERE id = :id AND content = :content AND favorite = :favorite AND CATEGORY = :categoryTitle") void updateIfModifiedLocallyDuringSync(long id, long modified, String title, Boolean favorite, String categoryTitle, String eTag, String content); /** * used by: {@link NoteServerSyncHelper.SyncTask#pullRemoteChanges()} update only, if not modified locally (i.e. STATUS="") and if modified remotely (i.e. any (!) column has changed) */ - @Query("UPDATE Note SET id = :id, title = :title, modified = :modified, title = :title, favorite = :favorite, etag = :eTag, content = :content " + - "WHERE id = :id AND status = '' AND (modified != :modified OR favorite != :favorite OR category_title != :categoryTitle OR (eTag == NULL OR eTag != :eTag) OR content != :content)") + @Query("UPDATE NOTES SET id = :id, title = :title, modified = :modified, title = :title, favorite = :favorite, etag = :eTag, content = :content " + + "WHERE id = :id AND status = '' AND (modified != :modified OR favorite != :favorite OR CATEGORY != :categoryTitle OR (eTag == NULL OR eTag != :eTag) OR content != :content)") void updateIfNotModifiedLocallyAndRemoteColumnHasChanged(long id, long modified, String title, Boolean favorite, String categoryTitle, String eTag, String content); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java index f90fb5d9..55805b6b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java @@ -5,7 +5,6 @@ import androidx.room.Insert; import androidx.room.Query; import it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData; -import it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData; @Dao public interface WidgetNotesListDao { @@ -13,9 +12,9 @@ public interface WidgetNotesListDao { @Insert void createOrUpdateNoteListWidgetData(NotesListWidgetData data); - @Query("DELETE FROM NotesListWidgetData WHERE id = :appWidgetId") + @Query("DELETE FROM WIDGET_NOTE_LISTS WHERE ID = :appWidgetId") void removeNoteListWidget(int appWidgetId); - @Query("SELECT * FROM NotesListWidgetData WHERE id = :appWidgetId") - NoteListsWidgetData getNoteListWidgetData(int appWidgetId); + @Query("SELECT * FROM WIDGET_NOTE_LISTS WHERE ID = :appWidgetId") + NotesListWidgetData getNoteListWidgetData(int appWidgetId); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetSingleNoteDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetSingleNoteDao.java index c2520705..661dace4 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetSingleNoteDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetSingleNoteDao.java @@ -13,9 +13,9 @@ public interface WidgetSingleNoteDao { @Insert(onConflict = OnConflictStrategy.REPLACE) void createOrUpdateSingleNoteWidgetData(SingleNoteWidgetData data); - @Query("DELETE FROM SingleNoteWidgetData WHERE id = :id") + @Query("DELETE FROM WIDGET_SINGLE_NOTES WHERE ID = :id") void removeSingleNoteWidget(int id); - @Query("SELECT * FROM SingleNoteWidgetData WHERE id = :id") + @Query("SELECT * FROM WIDGET_SINGLE_NOTES WHERE ID = :id") SingleNoteWidgetData getSingleNoteWidgetData(int id); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java index a918e51c..242bfea3 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Category.java @@ -1,5 +1,6 @@ package it.niedermann.owncloud.notes.persistence.entity; +import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Index; @@ -8,25 +9,31 @@ import androidx.room.PrimaryKey; import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; @Entity( + tableName = "CATEGORIES", foreignKeys = { @ForeignKey( entity = LocalAccount.class, - parentColumns = "accountId", - childColumns = "id", + parentColumns = "ID", + childColumns = "CATEGORY_ID", onDelete = ForeignKey.CASCADE ) }, indices = { - @Index(value = "accountId"), - @Index(value = "title"), - @Index(value = "categorySortingMethod") + @Index(name = "CATEGORIES_CATEGORY_ACCOUNT_ID_idx", value = "CATEGORY_ACCOUNT_ID"), + @Index(name = "CATEGORIES_CATEGORY_ID_idx", value = "CATEGORY_ID"), + @Index(name = "CATEGORIES_CATEGORY_SORTING_METHOD_idx", value = "CATEGORY_SORTING_METHOD"), + @Index(name = "CATEGORIES_CATEGORY_TITLE_idx", value = "CATEGORY_TITLE") } ) public class Category { @PrimaryKey + @ColumnInfo(name = "CATEGORY_ID") private long id; + @ColumnInfo(name = "CATEGORY_ACCOUNT_ID") private long accountId; + @ColumnInfo(name = "CATEGORY_TITLE") private String title; + @ColumnInfo(name = "CATEGORY_SORTING_METHOD") private CategorySortingMethod categorySortingMethod; public long getId() { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccount.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccount.java index 1952d9a8..45d0bb85 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccount.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccount.java @@ -2,6 +2,7 @@ package it.niedermann.owncloud.notes.persistence.entity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.Ignore; import androidx.room.Index; @@ -22,26 +23,37 @@ import it.niedermann.owncloud.notes.shared.model.Capabilities; import it.niedermann.owncloud.notes.shared.util.ColorUtil; @Entity( + tableName = "ACCOUNTS", indices = { - @Index(value = "url"), - @Index(value = "userName"), - @Index(value = "accountName"), - @Index(value = "eTag"), - @Index(value = "modified") + @Index(name = "ACCOUNTS_ACCOUNT_NAME_idx", value = "ACCOUNT_NAME"), + @Index(name = "ACCOUNTS_ETAG_idx", value = "ETAG"), + @Index(name = "ACCOUNTS_MODIFIED_idx", value = "MODIFIED"), + @Index(name = "ACCOUNTS_URL_idx", value = "URL"), + @Index(name = "ACCOUNTS_USERNAME_idx", value = "USERNAME") } ) public class LocalAccount { @PrimaryKey - public Long id; + @ColumnInfo(name = "ID") + private Long id; + @ColumnInfo(name = "URL") private String url; + @ColumnInfo(name = "USERNAME") private String userName; + @ColumnInfo(name = "ACCOUNT_NAME") private String accountName; + @ColumnInfo(name = "ETAG") private String eTag; + @ColumnInfo(name = "MODIFIED") private Calendar modified; + @ColumnInfo(name = "API_VERSION") private String apiVersion; - private String capabilitiesETag; + @ColumnInfo(name = "COLOR") private String color; + @ColumnInfo(name = "TEXT_COLOR") private String textColor; + @ColumnInfo(name = "CAPABILITIES_ETAG") + private String capabilitiesETag; @Nullable @Ignore diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java index 45cfd413..bb81ae11 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java @@ -1,6 +1,7 @@ package it.niedermann.owncloud.notes.persistence.entity; import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Ignore; @@ -14,61 +15,77 @@ import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.Item; @Entity( + tableName = "NOTES", foreignKeys = { @ForeignKey( entity = LocalAccount.class, - parentColumns = "accountId", - childColumns = "id", + parentColumns = "ID", + childColumns = "ACCOUNT_ID", onDelete = ForeignKey.CASCADE ), @ForeignKey( entity = Category.class, - parentColumns = "categoryId", - childColumns = "id", + parentColumns = "CATEGORY_ID", + childColumns = "CATEGORY", onDelete = ForeignKey.SET_DEFAULT ) }, indices = { - @Index(value = "remoteId"), - @Index(value = "accountId"), - @Index(value = "categoryId"), - @Index(value = "status"), - @Index(value = "favorite"), - @Index(value = "modified") + @Index(name = "NOTES_ACCOUNT_ID_idx", value = "ACCOUNT_ID"), + @Index(name = "NOTES_CATEGORY_idx", value = "CATEGORY"), + @Index(name = "NOTES_FAVORITE_idx", value = "FAVORITE"), + @Index(name = "NOTES_MODIFIED_idx", value = "MODIFIED"), + @Index(name = "NOTES_REMOTEID_idx", value = "REMOTEID"), + @Index(name = "NOTES_STATUS_idx", value = "STATUS") } ) public class Note implements Serializable, Item { @PrimaryKey + @ColumnInfo(name = "ID") private Long id; + @ColumnInfo(name = "REMOTEID") private Long remoteId; + @ColumnInfo(name = "ACCOUNT_ID") private Long accountId; - private Long categoryId; + @ColumnInfo(name = "STATUS") private DBStatus status = DBStatus.VOID; + @ColumnInfo(name = "TITLE") private String title; + @ColumnInfo(name = "MODIFIED") private Calendar modified; + @ColumnInfo(name = "CONTENT") private String content; + @ColumnInfo(name = "FAVORITE") private Boolean favorite; + @ColumnInfo(name = "CATEGORY") + private Long categoryId; + @ColumnInfo(name = "ETAG") private String eTag; + @ColumnInfo(name = "EXCERPT") private String excerpt; + @ColumnInfo(name = "SCROLL_Y") private Integer scrollY; + @Ignore + private String category; public Note() { super(); } @Ignore - public Note(long remoteId, Calendar modified, String title, String content, Boolean favorite, 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; this.content = content; this.favorite = favorite; this.eTag = eTag; + this.category = category; } @Ignore - public Note(long id, long remoteId, Calendar modified, String title, String content, boolean favorite, String etag, DBStatus status, long accountId, String excerpt, Integer scrollY) { - this(remoteId, modified, title, content, favorite, etag); + public Note(long id, long remoteId, Calendar modified, String title, String content, boolean favorite, String category, String etag, DBStatus status, long accountId, String excerpt, Integer scrollY) { + this(remoteId, modified, title, content, favorite, category, etag); this.id = id; this.status = status; this.accountId = accountId; @@ -172,6 +189,14 @@ public class Note implements Serializable, Item { this.scrollY = scrollY; } + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + @Ignore @Override public boolean isSection() { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java index d1066e5a..f756ad0e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NotesListWidgetData.java @@ -2,12 +2,30 @@ package it.niedermann.owncloud.notes.persistence.entity; import androidx.annotation.IntRange; import androidx.annotation.Nullable; +import androidx.room.ColumnInfo; import androidx.room.Entity; +import androidx.room.ForeignKey; import androidx.room.Ignore; import it.niedermann.owncloud.notes.widget.AbstractWidgetData; -@Entity() +@Entity( + tableName = "WIDGET_NOTE_LISTS", + foreignKeys = { + @ForeignKey( + entity = LocalAccount.class, + parentColumns = "ID", + childColumns = "ACCOUNT_ID", + onDelete = ForeignKey.CASCADE + ), + @ForeignKey( + entity = Category.class, + parentColumns = "CATEGORY_ID", + childColumns = "ID", + onDelete = ForeignKey.CASCADE + ) + } +) public class NotesListWidgetData extends AbstractWidgetData { @Ignore @@ -18,9 +36,10 @@ public class NotesListWidgetData extends AbstractWidgetData { public static final int MODE_DISPLAY_CATEGORY = 2; @IntRange(from = 0, to = 2) + @ColumnInfo(name = "MODE") private int mode; - @Nullable + @ColumnInfo(name = "CATEGORY_ID") private Long categoryId; @Nullable @@ -42,7 +61,7 @@ public class NotesListWidgetData extends AbstractWidgetData { @Override public String toString() { - return "WidgetNotesListEntity{" + + return "NotesListWidgetData{" + "mode=" + mode + ", categoryId=" + categoryId + '}'; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java index 491ccb03..fe45bce5 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/SingleNoteWidgetData.java @@ -1,12 +1,31 @@ package it.niedermann.owncloud.notes.persistence.entity; +import androidx.room.ColumnInfo; import androidx.room.Entity; +import androidx.room.ForeignKey; import androidx.room.Ignore; import it.niedermann.owncloud.notes.widget.AbstractWidgetData; -@Entity() +@Entity( + tableName = "WIDGET_SINGLE_NOTES", + foreignKeys = { + @ForeignKey( + entity = LocalAccount.class, + parentColumns = "ID", + childColumns = "ACCOUNT_ID", + onDelete = ForeignKey.CASCADE + ), + @ForeignKey( + entity = Note.class, + parentColumns = "ID", + childColumns = "NOTE_ID", + onDelete = ForeignKey.CASCADE + ) + } +) public class SingleNoteWidgetData extends AbstractWidgetData { + @ColumnInfo(name = "NOTE_ID") private long noteId; public SingleNoteWidgetData() { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java index 9873d100..35c4c9df 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/AbstractWidgetData.java @@ -1,14 +1,18 @@ package it.niedermann.owncloud.notes.widget; import androidx.annotation.IntRange; +import androidx.room.ColumnInfo; import androidx.room.PrimaryKey; public abstract class AbstractWidgetData { @PrimaryKey + @ColumnInfo(name = "ID") private int id; + @ColumnInfo(name = "ACCOUNT_ID") private long accountId; @IntRange(from = 0, to = 2) + @ColumnInfo(name = "THEME_MODE") private int themeMode; protected AbstractWidgetData() { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java index 5f39fa19..615d3bc3 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java @@ -20,13 +20,14 @@ import it.niedermann.owncloud.notes.edit.EditNoteActivity; import it.niedermann.owncloud.notes.main.MainActivity; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.entity.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; import it.niedermann.owncloud.notes.shared.model.OldCategory; import static it.niedermann.owncloud.notes.edit.EditNoteActivity.PARAM_CATEGORY; -import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_ALL; -import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_CATEGORY; -import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_STARRED; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_ALL; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_CATEGORY; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_STARRED; public class NoteListWidget extends AppWidgetProvider { private static final String TAG = NoteListWidget.class.getSimpleName(); @@ -43,7 +44,7 @@ public class NoteListWidget extends AppWidgetProvider { for (int appWidgetId : appWidgetIds) { try { - final NoteListsWidgetData data = db.getWidgetNotesListDao().getNoteListWidgetData(appWidgetId); + final NotesListWidgetData data = db.getWidgetNotesListDao().getNoteListWidgetData(appWidgetId); final LocalAccount localAccount = db.getLocalAccountDao().getAccount(data.getAccountId()); String category = null; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java index 5464586a..3d1e4210 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java @@ -29,6 +29,10 @@ import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.entity.LocalAccount; import it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_ALL; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_CATEGORY; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_STARRED; + public class NoteListWidgetConfigurationActivity extends LockedActivity { private static final String TAG = Activity.class.getSimpleName(); @@ -89,11 +93,11 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity { data.setId(appWidgetId); if (itemRecent.equals(item)) { - data.setMode(NoteListsWidgetData.MODE_DISPLAY_ALL); + data.setMode(MODE_DISPLAY_ALL); } else if (itemFavorites.equals(item)) { - data.setMode(NoteListsWidgetData.MODE_DISPLAY_STARRED); + data.setMode(MODE_DISPLAY_STARRED); } else { - data.setMode(NoteListsWidgetData.MODE_DISPLAY_CATEGORY); + data.setMode(MODE_DISPLAY_CATEGORY); if (item instanceof CategoryNavigationItem) { data.setCategoryId(((CategoryNavigationItem) item).categoryId); } else { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java index aaa18956..7208bbe9 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java @@ -16,17 +16,19 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.edit.EditNoteActivity; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; -import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_ALL; -import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_CATEGORY; -import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_STARRED; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_ALL; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_CATEGORY; +import static it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_STARRED; + public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFactory { private static final String TAG = NoteListWidgetFactory.class.getSimpleName(); private final Context context; - private final NoteListsWidgetData data; + private final NotesListWidgetData data; private final boolean darkTheme; private NotesDatabase db; private List<Note> noteEntities; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListsWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListsWidgetData.java deleted file mode 100644 index a21714ce..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListsWidgetData.java +++ /dev/null @@ -1,44 +0,0 @@ -package it.niedermann.owncloud.notes.widget.notelist; - -import androidx.annotation.IntRange; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import it.niedermann.owncloud.notes.widget.AbstractWidgetData; - -public class NoteListsWidgetData extends AbstractWidgetData { - public static final int MODE_DISPLAY_ALL = 0; - public static final int MODE_DISPLAY_STARRED = 1; - public static final int MODE_DISPLAY_CATEGORY = 2; - - @IntRange(from = 0, to = 2) - private int mode; - @Nullable - private Long categoryId; - - public int getMode() { - return mode; - } - - public void setMode(@IntRange(from = 0, to = 2) int mode) { - this.mode = mode; - } - - @Nullable - public Long getCategoryId() { - return categoryId; - } - - public void setCategoryId(@Nullable Long categoryId) { - this.categoryId = categoryId; - } - - @NonNull - @Override - public String toString() { - return "NoteListsWidgetData{" + - "mode=" + mode + - ", categoryId=" + categoryId + - '}'; - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetData.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetData.java deleted file mode 100644 index 79b83006..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetData.java +++ /dev/null @@ -1,25 +0,0 @@ -package it.niedermann.owncloud.notes.widget.singlenote; - -import it.niedermann.owncloud.notes.widget.AbstractWidgetData; - -public class SingleNoteWidgetData extends AbstractWidgetData { - private long noteId; - - public SingleNoteWidgetData() { - - } - - public SingleNoteWidgetData(int appWidgetId, long accountId, long noteId, int themeMode) { - super(appWidgetId, accountId, themeMode); - this.noteId = noteId; - } - - public long getNoteId() { - return noteId; - } - - public void setNoteId(long noteId) { - this.noteId = noteId; - } - -} |