Skip to content

Commit a715566

Browse files
committed
fix json parsing
Signed-off-by: alperozturk <[email protected]>
1 parent 96d05c3 commit a715566

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public NotesListWidgetData getNoteListWidgetData(int appWidgetId) {
480480
@NonNull
481481
@MainThread
482482
public LiveData<Note> addNoteAndSync(Account account, Note note) {
483-
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());
483+
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());
484484
final var ret = new MutableLiveData<Note>();
485485
executor.submit(() -> ret.postValue(addNote(account.getId(), entity)));
486486
return map(ret, newNote -> {
@@ -508,7 +508,7 @@ public Note addNote(long accountId, @NonNull Note note) {
508508

509509
@MainThread
510510
public LiveData<Note> moveNoteToAnotherAccount(Account account, @NonNull Note note) {
511-
final var fullNote = new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null, note.isSharedViaLink());
511+
final var fullNote = new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null, note.isShared());
512512
fullNote.setStatus(DBStatus.LOCAL_EDITED);
513513
deleteNoteAndSync(account, note.getId());
514514
return addNoteAndSync(account, fullNote);
@@ -570,7 +570,7 @@ public Note updateNoteAndSync(@NonNull Account localAccount, @NonNull Note oldNo
570570
// https://github.com/nextcloud/notes-android/issues/1198
571571
@Nullable final Long remoteId = db.getNoteDao().getRemoteId(oldNote.getId());
572572
if (newContent == null) {
573-
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());
573+
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());
574574
} else {
575575
final String title;
576576
if (newTitle != null) {
@@ -584,7 +584,7 @@ public Note updateNoteAndSync(@NonNull Account localAccount, @NonNull Note oldNo
584584
title = oldNote.getTitle();
585585
}
586586
}
587-
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());
587+
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());
588588
}
589589
int rows = db.getNoteDao().updateNote(newNote);
590590
// if data was changed, set new status and schedule sync (with callback); otherwise invoke callback directly.

app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public interface NoteDao {
3838
String getNoteById = "SELECT * FROM NOTE WHERE id = :id";
3939
String count = "SELECT COUNT(*) FROM NOTE WHERE status != 'LOCAL_DELETED' AND accountId = :accountId";
4040
String countFavorites = "SELECT COUNT(*) FROM NOTE WHERE status != 'LOCAL_DELETED' AND accountId = :accountId AND favorite = 1";
41-
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";
42-
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";
43-
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";
44-
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";
45-
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";
46-
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";
47-
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";
48-
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";
41+
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";
42+
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";
43+
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";
44+
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";
45+
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";
46+
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";
47+
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";
48+
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";
4949

5050
@Query(getNoteById)
5151
LiveData<Note> getNoteById$(long id);
@@ -141,7 +141,7 @@ public interface NoteDao {
141141
* Gets a list of {@link Note} objects with filled {@link Note#id} and {@link Note#remoteId},
142142
* where {@link Note#remoteId} is not <code>null</code>
143143
*/
144-
@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")
144+
@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")
145145
List<Note> getRemoteIdAndId(long accountId);
146146

147147
/**

app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Note.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@Index(name = "IDX_NOTE_ACCOUNTID", value = "accountId"),
3939
@Index(name = "IDX_NOTE_CATEGORY", value = "category"),
4040
@Index(name = "IDX_NOTE_FAVORITE", value = "favorite"),
41-
@Index(name = "IDX_NOTE_IS_SHARED_VIA_LINK", value = "share_by_link"),
41+
@Index(name = "IDX_NOTE_IS_SHARED", value = "isShared"),
4242
@Index(name = "IDX_NOTE_MODIFIED", value = "modified"),
4343
@Index(name = "IDX_NOTE_REMOTEID", value = "remoteId"),
4444
@Index(name = "IDX_NOTE_STATUS", value = "status")
@@ -83,9 +83,8 @@ public class Note implements Serializable, Item {
8383
private boolean favorite = false;
8484

8585
@Expose
86-
@ColumnInfo(defaultValue = "0", name = "share_by_link")
87-
@SerializedName("share_by_link")
88-
private boolean isSharedViaLink = false;
86+
@ColumnInfo(defaultValue = "0")
87+
private boolean isShared = false;
8988

9089
@Expose
9190
@Nullable
@@ -104,20 +103,20 @@ public Note() {
104103
}
105104

106105
@Ignore
107-
public Note(@Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, @NonNull String category, boolean favorite, @Nullable String eTag, boolean isSharedViaLink) {
106+
public Note(@Nullable Long remoteId, @Nullable Calendar modified, @NonNull String title, @NonNull String content, @NonNull String category, boolean favorite, @Nullable String eTag, boolean isShared) {
108107
this.remoteId = remoteId;
109108
this.title = title;
110109
this.modified = modified;
111110
this.content = content;
112111
this.favorite = favorite;
113112
this.category = category;
114113
this.eTag = eTag;
115-
this.isSharedViaLink = isSharedViaLink;
114+
this.isShared = isShared;
116115
}
117116

118117
@Ignore
119-
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) {
120-
this(remoteId, modified, title, content, category, favorite, etag, isSharedViaLink);
118+
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) {
119+
this(remoteId, modified, title, content, category, favorite, etag, isShared);
121120
this.id = id;
122121
this.status = status;
123122
this.accountId = accountId;
@@ -133,12 +132,12 @@ public void setId(long id) {
133132
this.id = id;
134133
}
135134

136-
public boolean isSharedViaLink() {
137-
return isSharedViaLink;
135+
public boolean isShared() {
136+
return isShared;
138137
}
139138

140-
public void setIsSharedViaLink(boolean value) {
141-
this.isSharedViaLink = value;
139+
public void setIsShared(boolean value) {
140+
this.isShared = value;
142141
}
143142

144143
@NonNull
@@ -245,7 +244,7 @@ public boolean equals(Object o) {
245244
if (id != note.id) return false;
246245
if (accountId != note.accountId) return false;
247246
if (favorite != note.favorite) return false;
248-
if (isSharedViaLink != note.isSharedViaLink) return false;
247+
if (isShared != note.isShared) return false;
249248
if (scrollY != note.scrollY) return false;
250249
if (!Objects.equals(remoteId, note.remoteId))
251250
return false;
@@ -270,7 +269,7 @@ public int hashCode() {
270269
result = 31 * result + (modified != null ? modified.hashCode() : 0);
271270
result = 31 * result + content.hashCode();
272271
result = 31 * result + (favorite ? 1 : 0);
273-
result = 31 * result + (isSharedViaLink ? 1 : 0);
272+
result = 31 * result + (isShared ? 1 : 0);
274273
result = 31 * result + (eTag != null ? eTag.hashCode() : 0);
275274
result = 31 * result + excerpt.hashCode();
276275
result = 31 * result + scrollY;
@@ -290,7 +289,7 @@ public String toString() {
290289
", modified=" + modified +
291290
", content='" + content + '\'' +
292291
", favorite=" + favorite +
293-
", share_by_link=" + isSharedViaLink +
292+
", isShared=" + isShared +
294293
", eTag='" + eTag + '\'' +
295294
", excerpt='" + excerpt + '\'' +
296295
", scrollY=" + scrollY +

app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public void createPublicShareLink() {
278278
executorService.schedule(() -> {
279279
final var result = repository.addShare(note, ShareType.PUBLIC_LINK, "", "false", "", 0, "");
280280
if (result != null) {
281-
note.setIsSharedViaLink(true);
281+
note.setIsShared(true);
282282
repository.updateNote(note);
283283
runOnUiThread(this::recreate);
284284
}
@@ -315,7 +315,7 @@ private String createInternalLink() {
315315

316316
@Override
317317
public void copyLink(OCShare share) {
318-
if (!note.isSharedViaLink()) {
318+
if (!note.isShared()) {
319319
return;
320320
}
321321

app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class ShareRepository(private val applicationContext: Context, private val accou
203203
if (response.isSuccessful) {
204204

205205
if (share.shareType == ShareType.PUBLIC_LINK) {
206-
note.setIsSharedViaLink(false)
206+
note.setIsShared(false)
207207
updateNote(note)
208208
}
209209

0 commit comments

Comments
 (0)