Skip to content

Commit

Permalink
fix json parsing
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Feb 6, 2025
1 parent 065b9e2 commit 8b78441
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public NotesListWidgetData getNoteListWidgetData(int appWidgetId) {
@NonNull
@MainThread
public LiveData<Note> 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<Note>();
executor.submit(() -> ret.postValue(addNote(account.getId(), entity)));
return map(ret, newNote -> {
Expand Down Expand Up @@ -508,7 +508,7 @@ public Note addNote(long accountId, @NonNull Note note) {

@MainThread
public LiveData<Note> 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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Note> getNoteById$(long id);
Expand Down Expand Up @@ -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 <code>null</code>
*/
@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<Note> getRemoteIdAndId(long accountId);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -104,20 +103,20 @@ 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;
this.content = content;
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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ private String createInternalLink() {

@Override
public void copyLink(OCShare share) {
if (!note.isSharedViaLink()) {
if (!note.isShared()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 8b78441

Please sign in to comment.