diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java index 144a3ee0..7828a82c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java @@ -32,6 +32,7 @@ import it.niedermann.owncloud.notes.main.items.list.NoteViewHolderWithoutExcerpt import it.niedermann.owncloud.notes.main.items.section.SectionItem; import it.niedermann.owncloud.notes.main.items.section.SectionViewHolder; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.shared.model.Item; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; @@ -160,7 +161,7 @@ public class ItemAdapter extends RecyclerView.Adapter i case TYPE_NOTE_WITH_EXCERPT: case TYPE_NOTE_WITHOUT_EXCERPT: case TYPE_NOTE_ONLY_TITLE: { - ((NoteViewHolder) holder).bind((Note) itemList.get(position), showCategory, mainColor, textColor, searchQuery); + ((NoteViewHolder) holder).bind((NoteWithCategory) itemList.get(position), showCategory, mainColor, textColor, searchQuery); break; } } @@ -224,9 +225,9 @@ public class ItemAdapter extends RecyclerView.Adapter i throw new IllegalArgumentException("Item at position " + position + " must not be null"); } if (getItem(position).isSection()) return TYPE_SECTION; - Note note = (Note) getItem(position); - if (TextUtils.isEmpty(note.getExcerpt())) { - if (TextUtils.isEmpty(note.getCategory())) { + NoteWithCategory note = (NoteWithCategory) getItem(position); + if (TextUtils.isEmpty(note.getNote().getExcerpt())) { + if (TextUtils.isEmpty(note.getNote().getCategory())) { return TYPE_NOTE_ONLY_TITLE; } else { return TYPE_NOTE_WITHOUT_EXCERPT; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java index cca6b84a..01860919 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java @@ -30,6 +30,7 @@ import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; @@ -49,7 +50,7 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder { } @CallSuper - public void bind(@NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { + public void bind(@NonNull NoteWithCategory note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { itemView.setOnClickListener((view) -> noteClickListener.onNoteClick(getAdapterPosition(), view)); itemView.setOnLongClickListener((view) -> noteClickListener.onNoteLongClick(getAdapterPosition(), view)); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java index 518cfc9b..e28d0a1e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java @@ -13,6 +13,7 @@ import androidx.annotation.Px; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridBinding; import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; import static android.view.View.GONE; @@ -39,8 +40,9 @@ public class NoteViewGridHolder extends NoteViewHolder { throw new UnsupportedOperationException(NoteViewGridHolder.class.getSimpleName() + " does not support swiping"); } - public void bind(@NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { - super.bind(note, showCategory, mainColor, textColor, searchQuery); + public void bind(@NonNull NoteWithCategory noteWithCategory, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { + super.bind(noteWithCategory, showCategory, mainColor, textColor, searchQuery); + Note note = noteWithCategory.getNote(); @NonNull final Context context = itemView.getContext(); bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); bindStatus(binding.noteStatus, note.getStatus(), mainColor); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java index 823661d8..a6f7d126 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java @@ -12,6 +12,7 @@ import androidx.annotation.Px; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridOnlyTitleBinding; import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; public class NoteViewGridHolderOnlyTitle extends NoteViewHolder { @@ -32,12 +33,12 @@ public class NoteViewGridHolderOnlyTitle extends NoteViewHolder { throw new UnsupportedOperationException(NoteViewGridHolderOnlyTitle.class.getSimpleName() + " does not support swiping"); } - public void bind(@NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { + public void bind(@NonNull NoteWithCategory note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { super.bind(note, showCategory, mainColor, textColor, searchQuery); @NonNull final Context context = itemView.getContext(); - bindStatus(binding.noteStatus, note.getStatus(), mainColor); - bindFavorite(binding.noteFavorite, note.getFavorite()); - bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); + bindStatus(binding.noteStatus, note.getNote().getStatus(), mainColor); + bindFavorite(binding.noteFavorite, note.getNote().getFavorite()); + bindSearchableContent(context, binding.noteTitle, searchQuery, note.getNote().getTitle(), mainColor); } @Nullable diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java index 2964a9cf..59097a85 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java @@ -10,6 +10,7 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithExcerptBinding; import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; @@ -28,8 +29,9 @@ public class NoteViewHolderWithExcerpt extends NoteViewHolder { binding.noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention); } - public void bind(@NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { - super.bind(note, showCategory, mainColor, textColor, searchQuery); + public void bind(@NonNull NoteWithCategory noteWithCategory, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { + super.bind(noteWithCategory, showCategory, mainColor, textColor, searchQuery); + Note note = noteWithCategory.getNote(); @NonNull final Context context = itemView.getContext(); binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f); bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java index 33d9fc37..a1f8e8af 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java @@ -10,6 +10,7 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithoutExcerptBinding; import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; @@ -28,8 +29,9 @@ public class NoteViewHolderWithoutExcerpt extends NoteViewHolder { binding.noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention); } - public void bind(@NonNull Note note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { - super.bind(note, showCategory, mainColor, textColor, searchQuery); + public void bind(@NonNull NoteWithCategory noteWithCategory, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { + super.bind(noteWithCategory, showCategory, mainColor, textColor, searchQuery); + Note note = noteWithCategory.getNote(); @NonNull final Context context = itemView.getContext(); binding.noteSwipeable.setAlpha(DBStatus.LOCAL_DELETED.equals(note.getStatus()) ? 0.5f : 1.0f); bindCategory(context, binding.noteCategory, showCategory, note.getCategory(), mainColor); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java index 309c3a4c..21aa0296 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java @@ -15,6 +15,7 @@ import java.util.List; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.main.items.section.SectionItem; import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.persistence.entity.NoteWithCategory; import it.niedermann.owncloud.notes.shared.model.OldCategory; import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; import it.niedermann.owncloud.notes.shared.model.Item; @@ -38,7 +39,7 @@ public class LoadNotesListTask extends AsyncTask> { @Override protected List doInBackground(Void... voids) { - List noteList; + List noteList; NotesDatabase db = NotesDatabase.getInstance(context); CategorySortingMethod sortingMethod = db.getCategoryOrder(accountId, category); noteList = db.getNoteDao().searchNotesSubcategory(accountId, searchQuery == null ? "%" : "%" + searchQuery + "%", category.category, Boolean.TRUE.equals(category.favorite), sortingMethod); @@ -56,10 +57,10 @@ public class LoadNotesListTask extends AsyncTask> { @NonNull @WorkerThread - private List fillListByCategory(@NonNull List noteList) { + private List fillListByCategory(@NonNull List noteList) { List itemList = new ArrayList<>(); String currentCategory = category.category; - for (Note note : noteList) { + for (NoteWithCategory note : noteList) { if (currentCategory != null && !currentCategory.equals(note.getCategory())) { itemList.add(new SectionItem(NoteUtil.extendCategory(note.getCategory()))); } @@ -72,17 +73,17 @@ public class LoadNotesListTask extends AsyncTask> { @NonNull @WorkerThread - private List fillListByTime(@NonNull List noteList) { + private List fillListByTime(@NonNull List noteList) { List itemList = new ArrayList<>(); Timeslotter timeslotter = new Timeslotter(); String lastTimeslot = null; for (int i = 0; i < noteList.size(); i++) { - Note currentNote = noteList.get(i); - String timeslot = timeslotter.getTimeslot(currentNote); + NoteWithCategory currentNote = noteList.get(i); + String timeslot = timeslotter.getTimeslot(currentNote.getNote()); if (i > 0 && !timeslot.equals(lastTimeslot)) { itemList.add(new SectionItem(timeslot)); } - itemList.add(currentNote); + itemList.add(currentNote.getNote()); lastTimeslot = timeslot; } @@ -91,12 +92,12 @@ public class LoadNotesListTask extends AsyncTask> { @NonNull @WorkerThread - private List fillListByInitials(@NonNull List noteList) { + private List fillListByInitials(@NonNull List noteList) { List itemList = new ArrayList<>(); String lastInitials = null; for (int i = 0; i < noteList.size(); i++) { - Note currentNote = noteList.get(i); - String initials = currentNote.getTitle().substring(0, 1).toUpperCase(); + NoteWithCategory currentNote = noteList.get(i); + String initials = currentNote.getNote().getTitle().substring(0, 1).toUpperCase(); if (!initials.matches("[A-Z\\u00C0-\\u00DF]")) { initials = initials.matches("[\\u0250-\\uFFFF]") ? context.getString(R.string.simple_other) : "#"; } 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 dc72defa..ffbc5f6c 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 @@ -100,7 +100,7 @@ public interface NoteDao { @Query("SELECT *, CATEGORY.title as 'category' FROM NOTE INNER JOIN CATEGORY ON categoryId = CATEGORY.id WHERE NOTE.accountId = :accountId AND status != 'LOCAL_DELETED' AND ( " + "NOTE.title LIKE :query OR content LIKE :query OR CATEGORY.title LIKE :query) AND (CATEGORY.title = :category OR CATEGORY.title LIKE :category + '/%' " + ") AND favorite = :favorite ORDER BY categoryId, favorite DESC, :sortingMethod") - List searchNotesSubcategory(long accountId, String query, String category, Boolean favorite, CategorySortingMethod sortingMethod); + List searchNotesSubcategory(long accountId, String query, String category, Boolean favorite, CategorySortingMethod sortingMethod); @Query("UPDATE NOTE SET remoteId = :remoteId WHERE id = :id") void updateRemoteId(long id, long remoteId); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java index 76c46749..e770b385 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteWithCategory.java @@ -7,8 +7,7 @@ import it.niedermann.owncloud.notes.shared.model.Item; public class NoteWithCategory implements Item { @Embedded private Note note; - @Embedded(prefix = "category_") - private Category category; + private String category; public Note getNote() { return note; @@ -18,11 +17,11 @@ public class NoteWithCategory implements Item { this.note = note; } - public Category getCategory() { + public String getCategory() { return category; } - public void setCategory(Category category) { + public void setCategory(String category) { this.category = category; } }