From c9da790226a8810af577c287a4be2314825099d2 Mon Sep 17 00:00:00 2001 From: Hui-Ouyang16 <11710106@mail.sustech.edu.cn> Date: Sat, 23 May 2020 04:11:16 +0800 Subject: [PATCH] overload searchNotes method for supporting choose ordering method --- .../notes/persistence/NotesDatabase.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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 0e06e298..ebb19830 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 @@ -286,6 +286,19 @@ public class NotesDatabase extends AbstractNotesDatabase { return getNotesCustom(accountId, key_status + " != ? AND " + key_account_id + " = ?", new String[]{DBStatus.LOCAL_DELETED.getTitle(), "" + accountId}, key_modified + " DESC", "4", true); } + /** + * This method is overloading searchNotes method. + * In order to keep the original code (called this method) still work. + * + * @return List<Note> + */ + @NonNull + @WorkerThread + public List searchNotes(long accountId, @Nullable CharSequence query, + @Nullable String category, @Nullable Boolean favorite) { + return searchNotes(accountId, query, category, favorite, null); + } + /** * Returns a list of all Notes in the Database * This method only supports to return the notes in the categories with the matched title or the notes in the categories whose ancestor category matches @@ -296,7 +309,9 @@ public class NotesDatabase extends AbstractNotesDatabase { */ @NonNull @WorkerThread - public List searchNotes(long accountId, @Nullable CharSequence query, @Nullable String category, @Nullable Boolean favorite) { + public List searchNotes(long accountId, @Nullable CharSequence query, + @Nullable String category, @Nullable Boolean favorite, + @Nullable CategorySortingMethod sortingMethod) { validateAccountId(accountId); List where = new ArrayList<>(); List args = new ArrayList<>(); @@ -330,6 +345,10 @@ public class NotesDatabase extends AbstractNotesDatabase { } String order = category == null ? default_order : key_category + ", " + key_title; + // TODO: modify here, need to test + if (sortingMethod != null) { + order = sortingMethod.getSorder(); + } return getNotesCustom(accountId, TextUtils.join(" AND ", where), args.toArray(new String[]{}), order, true); } @@ -963,7 +982,7 @@ public class NotesDatabase extends AbstractNotesDatabase { * The sorting method of the category can be used to decide * to use which sorting method to show the notes for each categories. * - * @param accountId The user accountID + * @param accountId The user accountID * @param categoryTitle The category title * @return The sorting method in CategorySortingMethod enum format */ @@ -990,7 +1009,7 @@ public class NotesDatabase extends AbstractNotesDatabase { * When the user changes the sorting method, this method should be called. * * @param accountId The user accountID - * @param categoryTitle The category title + * @param categoryTitle The category title * @param sortingMethod The sorting method in CategorySortingMethod enum format */ public void modifyCategoryOrderByTitle(