diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-06-12 17:56:36 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-06-12 17:56:36 +0300 |
commit | 0f3a5972b1d2290e77362338bd8d43146f70ea6e (patch) | |
tree | c204d3b8c768c30c75f113715a87f3fc69c38acc | |
parent | f11184188bf1ef72e86a314cb2b12e4cf73dd23e (diff) |
Enhances presentation of only-title-notes in grid view
3 files changed, 128 insertions, 10 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java index 81f46b55..f6efada4 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java @@ -21,10 +21,11 @@ import java.util.List; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.Branded; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridBinding; +import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridOnlyTitleBinding; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithExcerptBinding; +import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithoutExcerptBinding; import it.niedermann.owncloud.notes.databinding.ItemNotesListSectionItemBinding; -import static it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithoutExcerptBinding.inflate; import static it.niedermann.owncloud.notes.util.NoteUtil.getFontSizeFromPreferences; public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements Branded { @@ -34,6 +35,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i public static final int TYPE_SECTION = 0; public static final int TYPE_NOTE_WITH_EXCERPT = 1; public static final int TYPE_NOTE_WITHOUT_EXCERPT = 2; + public static final int TYPE_NOTE_ONLY_TITLE = 3; private final NoteClickListener noteClickListener; private final boolean gridView; @@ -109,6 +111,9 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i case TYPE_SECTION: { return new SectionViewHolder(ItemNotesListSectionItemBinding.inflate(LayoutInflater.from(parent.getContext()))); } + case TYPE_NOTE_ONLY_TITLE: { + return new NoteViewGridHolderOnlyTitle(ItemNotesListNoteItemGridOnlyTitleBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false), noteClickListener, monospace, fontSize); + } case TYPE_NOTE_WITH_EXCERPT: case TYPE_NOTE_WITHOUT_EXCERPT: { return new NoteViewGridHolder(ItemNotesListNoteItemGridBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false), noteClickListener, monospace, fontSize); @@ -125,8 +130,9 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i case TYPE_NOTE_WITH_EXCERPT: { return new NoteViewHolderWithExcerpt(ItemNotesListNoteItemWithExcerptBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false), noteClickListener); } + case TYPE_NOTE_ONLY_TITLE: case TYPE_NOTE_WITHOUT_EXCERPT: { - return new NoteViewHolderWithoutExcerpt(inflate(LayoutInflater.from(parent.getContext()), parent, false), noteClickListener); + return new NoteViewHolderWithoutExcerpt(ItemNotesListNoteItemWithoutExcerptBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false), noteClickListener); } default: { throw new IllegalArgumentException("Not supported viewType: " + viewType); @@ -143,7 +149,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i break; } case TYPE_NOTE_WITH_EXCERPT: - case TYPE_NOTE_WITHOUT_EXCERPT: { + case TYPE_NOTE_WITHOUT_EXCERPT: + case TYPE_NOTE_ONLY_TITLE: { ((NoteViewHolder) holder).bind((DBNote) itemList.get(position), showCategory, mainColor, textColor, searchQuery); break; } @@ -200,18 +207,23 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i return itemList.size(); } - @IntRange(from = 0, to = 2) + @IntRange(from = 0, to = 3) @Override public int getItemViewType(int position) { Item item = getItem(position); if (item == null) { throw new IllegalArgumentException("Item at position " + position + " must not be null"); } - return getItem(position).isSection() - ? TYPE_SECTION - : TextUtils.isEmpty(((DBNote) getItem(position)).getExcerpt()) - ? TYPE_NOTE_WITHOUT_EXCERPT - : TYPE_NOTE_WITH_EXCERPT; + if (getItem(position).isSection()) return TYPE_SECTION; + DBNote note = (DBNote) getItem(position); + if (TextUtils.isEmpty(note.getExcerpt())) { + if (TextUtils.isEmpty(note.getCategory())) { + return TYPE_NOTE_ONLY_TITLE; + } else { + return TYPE_NOTE_WITHOUT_EXCERPT; + } + } + return TYPE_NOTE_WITH_EXCERPT; } @Override @@ -228,7 +240,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i /** * @return the position of the first item which matches the given viewtype, -1 if not available */ - public int getFirstPositionOfViewType(@IntRange(from = 0, to = 2) int viewType) { + public int getFirstPositionOfViewType(@IntRange(from = 0, to = 3) int viewType) { for (int i = 0; i < itemList.size(); i++) { if (getItemViewType(i) == viewType) { return i; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/NoteViewGridHolderOnlyTitle.java b/app/src/main/java/it/niedermann/owncloud/notes/model/NoteViewGridHolderOnlyTitle.java new file mode 100644 index 00000000..59e14eff --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/NoteViewGridHolderOnlyTitle.java @@ -0,0 +1,47 @@ +package it.niedermann.owncloud.notes.model; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.TypedValue; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.Px; + +import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridOnlyTitleBinding; + +import static android.view.View.INVISIBLE; +import static android.view.View.VISIBLE; + +public class NoteViewGridHolderOnlyTitle extends NoteViewHolder { + @NonNull + private final ItemNotesListNoteItemGridOnlyTitleBinding binding; + + public NoteViewGridHolderOnlyTitle(@NonNull ItemNotesListNoteItemGridOnlyTitleBinding binding, @NonNull NoteClickListener noteClickListener, boolean monospace, @Px float fontSize) { + super(binding.getRoot(), noteClickListener); + this.binding = binding; + + binding.noteTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 1.1f); + if (monospace) { + binding.noteTitle.setTypeface(Typeface.MONOSPACE); + } + } + + public void showSwipe(boolean left) { + throw new UnsupportedOperationException(NoteViewGridHolderOnlyTitle.class.getSimpleName() + " does not support swiping"); + } + + public void bind(@NonNull DBNote note, boolean showCategory, int mainColor, int textColor, @Nullable CharSequence searchQuery) { + super.bind(note, showCategory, mainColor, textColor, searchQuery); + @NonNull final Context context = itemView.getContext(); + binding.noteStatus.setVisibility(DBStatus.VOID.equals(note.getStatus()) ? INVISIBLE : VISIBLE); + bindFavorite(binding.noteFavorite, note.isFavorite()); + bindSearchableContent(context, binding.noteTitle, searchQuery, note.getTitle(), mainColor); + } + + @Nullable + public View getNoteSwipeable() { + return null; + } +}
\ No newline at end of file diff --git a/app/src/main/res/layout/item_notes_list_note_item_grid_only_title.xml b/app/src/main/res/layout/item_notes_list_note_item_grid_only_title.xml new file mode 100644 index 00000000..6bf47835 --- /dev/null +++ b/app/src/main/res/layout/item_notes_list_note_item_grid_only_title.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="utf-8"?> +<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/card" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:focusable="true"> + + <LinearLayout + android:id="@+id/wrapper" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@drawable/grid_item_background_selector" + android:orientation="horizontal" + android:paddingBottom="@dimen/spacer_1x"> + + <TextView + android:id="@+id/noteTitle" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/spacer_2x" + android:layout_marginLeft="@dimen/spacer_2x" + android:layout_marginTop="@dimen/spacer_2x" + android:layout_marginEnd="@dimen/spacer_2x" + android:layout_marginRight="@dimen/spacer_2x" + android:layout_marginBottom="@dimen/spacer_1x" + android:layout_weight="1" + android:textAppearance="?attr/textAppearanceHeadline5" + android:textColor="@color/fg_default" + tools:maxLength="50" + tools:text="@tools:sample/lorem/random" /> + + <FrameLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + <ImageView + android:id="@+id/noteFavorite" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="?attr/selectableItemBackgroundBorderless" + android:contentDescription="@string/menu_favorite" + android:padding="@dimen/spacer_2x" + tools:src="@drawable/ic_star_yellow_24dp" /> + + <androidx.appcompat.widget.AppCompatImageView + android:id="@+id/noteStatus" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|end" + android:layout_marginTop="12dp" + android:layout_marginEnd="4dp" + android:layout_marginRight="4dp" + android:baseline="14dp" + app:srcCompat="@drawable/ic_sync_blue_18dp" /> + </FrameLayout> + </LinearLayout> +</com.google.android.material.card.MaterialCardView>
\ No newline at end of file |