Loading app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +22 −10 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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; Loading Loading @@ -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); Loading @@ -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); Loading @@ -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; } Loading Loading @@ -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 Loading @@ -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; Loading app/src/main/java/it/niedermann/owncloud/notes/model/NoteViewGridHolderOnlyTitle.java 0 → 100644 +47 −0 Original line number Diff line number Diff line 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 app/src/main/res/layout/item_notes_list_note_item_grid_only_title.xml 0 → 100644 +59 −0 Original line number Diff line number Diff line <?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 Loading
app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +22 −10 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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; Loading Loading @@ -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); Loading @@ -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); Loading @@ -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; } Loading Loading @@ -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 Loading @@ -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; Loading
app/src/main/java/it/niedermann/owncloud/notes/model/NoteViewGridHolderOnlyTitle.java 0 → 100644 +47 −0 Original line number Diff line number Diff line 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
app/src/main/res/layout/item_notes_list_note_item_grid_only_title.xml 0 → 100644 +59 −0 Original line number Diff line number Diff line <?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