From 996eb10ba7160a5b587f22414be43f1a7378ab5b Mon Sep 17 00:00:00 2001 From: maltaisn Date: Mon, 27 Apr 2020 10:44:07 -0400 Subject: [PATCH] Improved note items layout when title or content is missing --- .../ui/note/adapter/NoteListViewHolder.kt | 19 +++++++------ app/src/main/res/layout/item_note_list.xml | 27 +++++++++---------- app/src/main/res/layout/item_note_text.xml | 10 +++++-- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/app/src/main/kotlin/com/maltaisn/notes/ui/note/adapter/NoteListViewHolder.kt b/app/src/main/kotlin/com/maltaisn/notes/ui/note/adapter/NoteListViewHolder.kt index 0069da5a..c520c78a 100644 --- a/app/src/main/kotlin/com/maltaisn/notes/ui/note/adapter/NoteListViewHolder.kt +++ b/app/src/main/kotlin/com/maltaisn/notes/ui/note/adapter/NoteListViewHolder.kt @@ -62,10 +62,11 @@ class TextNoteViewHolder(private val binding: ItemNoteTextBinding) : super.bind(adapter, item) require(item.note.type == NoteType.TEXT) - val txv = binding.contentTxv - txv.text = HighlightHelper.getHighlightedText(item.note.content, item.contentHighlights, + val contentTxv = binding.contentTxv + contentTxv.isVisible = item.note.content.isNotBlank() + contentTxv.text = HighlightHelper.getHighlightedText(item.note.content, item.contentHighlights, adapter.highlightBackgroundColor, adapter.highlightForegroundColor) - txv.maxLines = adapter.listLayoutMode.maxTextLines + contentTxv.maxLines = adapter.listLayoutMode.maxTextLines } } @@ -82,10 +83,13 @@ class ListNoteViewHolder(private val binding: ItemNoteListBinding) : require(item.note.type == NoteType.LIST) require(itemViewHolders.isEmpty()) - val maxItems = adapter.listLayoutMode.maxListItems + val noteItems = item.note.listItems + + val itemsLayout = binding.itemsLayout + itemsLayout.isVisible = noteItems.isNotEmpty() // Add the first fewitems in list note using view holders in pool. - val noteItems = item.note.listItems + val maxItems = adapter.listLayoutMode.maxListItems val itemHighlights = HighlightHelper.splitListNoteHighlightsByItem( noteItems, item.contentHighlights) for (i in 0 until min(maxItems, noteItems.size)) { @@ -93,7 +97,7 @@ class ListNoteViewHolder(private val binding: ItemNoteListBinding) : val viewHolder = adapter.obtainListNoteItemViewHolder() itemViewHolders += viewHolder viewHolder.bind(adapter, noteItem, itemHighlights[i]) - binding.itemsLayout.addView(viewHolder.binding.root, i + 1) + itemsLayout.addView(viewHolder.binding.root, i) } // Show a label indicating the number of items not shown. @@ -115,9 +119,8 @@ class ListNoteViewHolder(private val binding: ItemNoteListBinding) : } // Free view holders used by the item. - val itemsLayout = binding.itemsLayout val viewHolders = itemViewHolders.toList() - binding.itemsLayout.removeViews(1, itemsLayout.childCount - 2) + binding.itemsLayout.removeAllViews() itemViewHolders.clear() return viewHolders diff --git a/app/src/main/res/layout/item_note_list.xml b/app/src/main/res/layout/item_note_list.xml index 77e1b2cc..6e19548d 100644 --- a/app/src/main/res/layout/item_note_list.xml +++ b/app/src/main/res/layout/item_note_list.xml @@ -24,11 +24,13 @@ > - - + android:layout_marginTop="8dp" + android:orientation="vertical" + tools:visibility="gone"/> diff --git a/app/src/main/res/layout/item_note_text.xml b/app/src/main/res/layout/item_note_text.xml index 17162c4f..1fab6118 100644 --- a/app/src/main/res/layout/item_note_text.xml +++ b/app/src/main/res/layout/item_note_text.xml @@ -27,7 +27,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:padding="16dp" + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:paddingTop="16dp" + android:paddingBottom="8dp" >