From 8b784416c955d5ff5861c50810d3959f888c7191 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 6 Feb 2025 10:11:38 +0100 Subject: [PATCH] fix json parsing Signed-off-by: alperozturk --- .../notes/persistence/NotesRepository.java | 8 ++--- .../notes/persistence/dao/NoteDao.java | 18 ++++++------ .../notes/persistence/entity/Note.java | 29 +++++++++---------- .../notes/share/NoteShareActivity.java | 4 +-- .../notes/share/repository/ShareRepository.kt | 2 +- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java index 6f54244d2..fa9eb594d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java @@ -480,7 +480,7 @@ public NotesListWidgetData getNoteListWidgetData(int appWidgetId) { @NonNull @MainThread public LiveData addNoteAndSync(Account account, Note note) { - final var entity = new Note(0, null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), note.getETag(), DBStatus.LOCAL_EDITED, account.getId(), generateNoteExcerpt(note.getContent(), note.getTitle()), 0, note.isSharedViaLink()); + final var entity = new Note(0, null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), note.getETag(), DBStatus.LOCAL_EDITED, account.getId(), generateNoteExcerpt(note.getContent(), note.getTitle()), 0, note.isShared()); final var ret = new MutableLiveData(); executor.submit(() -> ret.postValue(addNote(account.getId(), entity))); return map(ret, newNote -> { @@ -508,7 +508,7 @@ public Note addNote(long accountId, @NonNull Note note) { @MainThread public LiveData moveNoteToAnotherAccount(Account account, @NonNull Note note) { - final var fullNote = new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null, note.isSharedViaLink()); + final var fullNote = new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null, note.isShared()); fullNote.setStatus(DBStatus.LOCAL_EDITED); deleteNoteAndSync(account, note.getId()); return addNoteAndSync(account, fullNote); @@ -570,7 +570,7 @@ public Note updateNoteAndSync(@NonNull Account localAccount, @NonNull Note oldNo // https://github.com/nextcloud/notes-android/issues/1198 @Nullable final Long remoteId = db.getNoteDao().getRemoteId(oldNote.getId()); if (newContent == null) { - newNote = new Note(oldNote.getId(), remoteId, oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.getCategory(), oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY(), oldNote.isSharedViaLink()); + newNote = new Note(oldNote.getId(), remoteId, oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.getCategory(), oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY(), oldNote.isShared()); } else { final String title; if (newTitle != null) { @@ -584,7 +584,7 @@ public Note updateNoteAndSync(@NonNull Account localAccount, @NonNull Note oldNo title = oldNote.getTitle(); } } - newNote = new Note(oldNote.getId(), remoteId, Calendar.getInstance(), title, newContent, oldNote.getCategory(), oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title), oldNote.getScrollY(), oldNote.isSharedViaLink()); + newNote = new Note(oldNote.getId(), remoteId, Calendar.getInstance(), title, newContent, oldNote.getCategory(), oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title), oldNote.getScrollY(), oldNote.isShared()); } int rows = db.getNoteDao().updateNote(newNote); // if data was changed, set new status and schedule sync (with callback); otherwise invoke callback directly. 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 7b475c5c7..2f04c77e9 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 @@ -38,14 +38,14 @@ public interface NoteDao { String getNoteById = "SELECT * FROM NOTE WHERE id = :id"; String count = "SELECT COUNT(*) FROM NOTE WHERE status != 'LOCAL_DELETED' AND accountId = :accountId"; String countFavorites = "SELECT COUNT(*) FROM NOTE WHERE status != 'LOCAL_DELETED' AND accountId = :accountId AND favorite = 1"; - String searchRecentByModified = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) ORDER BY favorite DESC, modified DESC"; - String searchRecentLexicographically = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) ORDER BY favorite DESC, title COLLATE LOCALIZED ASC"; - String searchFavoritesByModified = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND favorite = 1 ORDER BY modified DESC"; - String searchFavoritesLexicographically = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND favorite = 1 ORDER BY title COLLATE LOCALIZED ASC"; - String searchUncategorizedByModified = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND category = '' ORDER BY favorite DESC, modified DESC"; - String searchUncategorizedLexicographically = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND category = '' ORDER BY favorite DESC, title COLLATE LOCALIZED ASC"; - String searchCategoryByModified = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND (category = :category OR category LIKE :category || '/%') ORDER BY category, favorite DESC, modified DESC"; - String searchCategoryLexicographically = "SELECT id, remoteId, accountId, title, favorite, share_by_link, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND (category = :category OR category LIKE :category || '/%') ORDER BY category, favorite DESC, title COLLATE LOCALIZED ASC"; + String searchRecentByModified = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) ORDER BY favorite DESC, modified DESC"; + String searchRecentLexicographically = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) ORDER BY favorite DESC, title COLLATE LOCALIZED ASC"; + String searchFavoritesByModified = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND favorite = 1 ORDER BY modified DESC"; + String searchFavoritesLexicographically = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND favorite = 1 ORDER BY title COLLATE LOCALIZED ASC"; + String searchUncategorizedByModified = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND category = '' ORDER BY favorite DESC, modified DESC"; + String searchUncategorizedLexicographically = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND category = '' ORDER BY favorite DESC, title COLLATE LOCALIZED ASC"; + String searchCategoryByModified = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND (category = :category OR category LIKE :category || '/%') ORDER BY category, favorite DESC, modified DESC"; + String searchCategoryLexicographically = "SELECT id, remoteId, accountId, title, favorite, isShared, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) AND (category = :category OR category LIKE :category || '/%') ORDER BY category, favorite DESC, title COLLATE LOCALIZED ASC"; @Query(getNoteById) LiveData getNoteById$(long id); @@ -141,7 +141,7 @@ public interface NoteDao { * Gets a list of {@link Note} objects with filled {@link Note#id} and {@link Note#remoteId}, * where {@link Note#remoteId} is not null */ - @Query("SELECT id, remoteId, 0 as accountId, '' as title, 0 as favorite, 0 as share_by_link, '' as excerpt, 0 as modified, '' as eTag, 0 as status, '' as category, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND remoteId IS NOT NULL") + @Query("SELECT id, remoteId, 0 as accountId, '' as title, 0 as favorite, 0 as isShared, '' as excerpt, 0 as modified, '' as eTag, 0 as status, '' as category, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND remoteId IS NOT NULL") List getRemoteIdAndId(long accountId); /** 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 7b8285670..84756ebbc 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 @@ -38,7 +38,7 @@ @Index(name = "IDX_NOTE_ACCOUNTID", value = "accountId"), @Index(name = "IDX_NOTE_CATEGORY", value = "category"), @Index(name = "IDX_NOTE_FAVORITE", value = "favorite"), - @Index(name = "IDX_NOTE_IS_SHARED_VIA_LINK", value = "share_by_link"), + @Index(name = "IDX_NOTE_IS_SHARED", value = "isShared"), @Index(name = "IDX_NOTE_MODIFIED", value = "modified"), @Index(name = "IDX_NOTE_REMOTEID", value = "remoteId"), @Index(name = "IDX_NOTE_STATUS", value = "status") @@ -83,9 +83,8 @@ public class Note implements Serializable, Item { private boolean favorite = false; @Expose - @ColumnInfo(defaultValue = "0", name = "share_by_link") - @SerializedName("share_by_link") - private boolean isSharedViaLink = false; + @ColumnInfo(defaultValue = "0") + private boolean isShared = false; @Expose @Nullable @@ -104,7 +103,7 @@ public Note() { } @Ignore - public Note(@Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, @NonNull String category, boolean favorite, @Nullable String eTag, boolean isSharedViaLink) { + public Note(@Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, @NonNull String category, boolean favorite, @Nullable String eTag, boolean isShared) { this.remoteId = remoteId; this.title = title; this.modified = modified; @@ -112,12 +111,12 @@ public Note(@Nullable Long remoteId, @Nullable Calendar modified, @NonNull Strin this.favorite = favorite; this.category = category; this.eTag = eTag; - this.isSharedViaLink = isSharedViaLink; + this.isShared = isShared; } @Ignore - public Note(long id, @Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, @NonNull String category, boolean favorite, @Nullable String etag, @NonNull DBStatus status, long accountId, @NonNull String excerpt, int scrollY, boolean isSharedViaLink) { - this(remoteId, modified, title, content, category, favorite, etag, isSharedViaLink); + public Note(long id, @Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, @NonNull String category, boolean favorite, @Nullable String etag, @NonNull DBStatus status, long accountId, @NonNull String excerpt, int scrollY, boolean isShared) { + this(remoteId, modified, title, content, category, favorite, etag, isShared); this.id = id; this.status = status; this.accountId = accountId; @@ -133,12 +132,12 @@ public void setId(long id) { this.id = id; } - public boolean isSharedViaLink() { - return isSharedViaLink; + public boolean isShared() { + return isShared; } - public void setIsSharedViaLink(boolean value) { - this.isSharedViaLink = value; + public void setIsShared(boolean value) { + this.isShared = value; } @NonNull @@ -245,7 +244,7 @@ public boolean equals(Object o) { if (id != note.id) return false; if (accountId != note.accountId) return false; if (favorite != note.favorite) return false; - if (isSharedViaLink != note.isSharedViaLink) return false; + if (isShared != note.isShared) return false; if (scrollY != note.scrollY) return false; if (!Objects.equals(remoteId, note.remoteId)) return false; @@ -270,7 +269,7 @@ public int hashCode() { result = 31 * result + (modified != null ? modified.hashCode() : 0); result = 31 * result + content.hashCode(); result = 31 * result + (favorite ? 1 : 0); - result = 31 * result + (isSharedViaLink ? 1 : 0); + result = 31 * result + (isShared ? 1 : 0); result = 31 * result + (eTag != null ? eTag.hashCode() : 0); result = 31 * result + excerpt.hashCode(); result = 31 * result + scrollY; @@ -290,7 +289,7 @@ public String toString() { ", modified=" + modified + ", content='" + content + '\'' + ", favorite=" + favorite + - ", share_by_link=" + isSharedViaLink + + ", isShared=" + isShared + ", eTag='" + eTag + '\'' + ", excerpt='" + excerpt + '\'' + ", scrollY=" + scrollY + diff --git a/app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java index 60e620a42..0401416eb 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java @@ -278,7 +278,7 @@ public void createPublicShareLink() { executorService.schedule(() -> { final var result = repository.addShare(note, ShareType.PUBLIC_LINK, "", "false", "", 0, ""); if (result != null) { - note.setIsSharedViaLink(true); + note.setIsShared(true); repository.updateNote(note); runOnUiThread(this::recreate); } @@ -315,7 +315,7 @@ private String createInternalLink() { @Override public void copyLink(OCShare share) { - if (!note.isSharedViaLink()) { + if (!note.isShared()) { return; } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt b/app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt index 480f3ef8e..f62652193 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt @@ -203,7 +203,7 @@ class ShareRepository(private val applicationContext: Context, private val accou if (response.isSuccessful) { if (share.shareType == ShareType.PUBLIC_LINK) { - note.setIsSharedViaLink(false) + note.setIsShared(false) updateNote(note) }