From 033ae67ef38fe5cdd4bd2a8425f2c57a23f7e068 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Fri, 16 Oct 2020 16:22:24 +0200 Subject: [PATCH] Minor stuff --- .../it/niedermann/owncloud/notes/main/MainViewModel.java | 9 +-------- .../owncloud/notes/persistence/NotesDatabase.java | 9 ++++----- .../SingleNoteWidgetConfigurationActivity.java | 1 - 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java index e49b0726..c93e8bdd 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java @@ -22,7 +22,6 @@ import com.nextcloud.android.sso.model.SingleSignOnAccount; import java.net.HttpURLConnection; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import it.niedermann.owncloud.notes.R; @@ -403,12 +402,10 @@ public class MainViewModel extends AndroidViewModel { return db.getAccountDao().getAccounts(); } - @AnyThread public void setCategory(SingleSignOnAccount ssoAccount, long accountId, Long noteId, @NonNull String category) { db.setCategory(ssoAccount, accountId, noteId, category); } - @AnyThread public LiveData moveNoteToAnotherAccount(SingleSignOnAccount ssoAccount, NoteWithCategory note, long newAccountId) { return db.moveNoteToAnotherAccount(ssoAccount, note, newAccountId); } @@ -418,22 +415,18 @@ public class MainViewModel extends AndroidViewModel { return db.getCategoryDao().getCategory(id); } - @AnyThread public LiveData deleteAccount(@NonNull Account account) { return db.deleteAccount(account); } - @AnyThread public void toggleFavoriteAndSync(SingleSignOnAccount ssoAccount, long noteId) { db.toggleFavoriteAndSync(ssoAccount, noteId); } - @AnyThread public void deleteNoteAndSync(SingleSignOnAccount ssoAccount, long id) { db.deleteNoteAndSync(ssoAccount, id); } - @AnyThread public LiveData addAccount(@NonNull String url, @NonNull String username, @NonNull String accountName, @NonNull Capabilities capabilities) { return db.addAccount(url, username, accountName, capabilities); } @@ -443,11 +436,11 @@ public class MainViewModel extends AndroidViewModel { return db.getNoteDao().getNoteWithCategory(accountId, id); } - @AnyThread public LiveData addNoteAndSync(SingleSignOnAccount ssoAccount, long accountId, NoteWithCategory note) { return db.addNoteAndSync(ssoAccount, accountId, note); } + @WorkerThread public void updateNoteAndSync(SingleSignOnAccount ssoAccount, @NonNull Account localAccount, @NonNull NoteWithCategory oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) { db.updateNoteAndSync(ssoAccount, localAccount, oldNote, newContent, newTitle, callback); } 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 46d4d112..6538529e 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 @@ -261,11 +261,11 @@ public abstract class NotesDatabase extends RoomDatabase { * @param callback When the synchronization is finished, this callback will be invoked (optional). * @return changed {@link Note} if differs from database, otherwise the old {@link Note}. */ + @WorkerThread public NoteWithCategory updateNoteAndSync(SingleSignOnAccount ssoAccount, @NonNull Account localAccount, @NonNull NoteWithCategory oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) { - NoteWithCategory newNote = new NoteWithCategory(); + final NoteWithCategory newNote; if (newContent == null) { - newNote.setNote(new Note(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY())); - newNote.setCategory(oldNote.getCategory()); + newNote = new NoteWithCategory(new Note(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY()), oldNote.getCategory()); } else { final String title; if (newTitle != null) { @@ -277,8 +277,7 @@ public abstract class NotesDatabase extends RoomDatabase { title = oldNote.getTitle(); } } - newNote.setNote(new Note(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title), oldNote.getScrollY())); - newNote.setCategory(oldNote.getCategory()); + newNote = new NoteWithCategory(new Note(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title), oldNote.getScrollY()), oldNote.getCategory()); } newNote.getNote().setCategoryId(getOrCreateCategoryIdByTitle(newNote.getAccountId(), newNote.getCategory())); int rows = getNoteDao().updateNote(newNote.getNote()); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java index 375fa27a..7651d5e7 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java @@ -16,7 +16,6 @@ import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.exception.ExceptionHandler; import it.niedermann.owncloud.notes.main.MainActivity; -import it.niedermann.owncloud.notes.persistence.entity.Note; import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.persistence.entity.SingleNoteWidgetData;