Skip to content

Commit

Permalink
Improved note items layout when title or content is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
maltaisn committed Apr 27, 2020
1 parent 551a07c commit 996eb10
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -82,18 +83,21 @@ 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)) {
val noteItem = noteItems[i]
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.
Expand All @@ -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
Expand Down
27 changes: 12 additions & 15 deletions app/src/main/res/layout/item_note_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,34 @@
>

<LinearLayout
android:id="@+id/items_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="8dp"
android:paddingBottom="16dp"
>

<TextView
android:id="@+id/title_txv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?textAppearanceSubtitle1"
android:paddingBottom="8dp"
android:maxLines="2"
android:ellipsize="end"
android:layout_marginTop="8dp"
tools:text="Lorem ipsum dolor sit amet"
tools:visibility="visible"
/>

<!-- List items are added here. -->
<!--
<include
layout="@layout/item_note_list_item"
<LinearLayout
android:id="@+id/items_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<include
layout="@layout/item_note_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
-->
android:layout_marginTop="8dp"
android:orientation="vertical"
tools:visibility="gone"/>

<TextView
android:id="@+id/info_txv"
Expand All @@ -66,6 +62,7 @@
android:layout_marginStart="24dp"
android:maxLines="1"
android:ellipsize="end"
android:visibility="gone"
tools:text="+ 12 list items"
/>

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/res/layout/item_note_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@
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"
>

<TextView
android:id="@+id/title_txv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?textAppearanceSubtitle1"
android:paddingBottom="8dp"
android:maxLines="2"
android:paddingBottom="8dp"
android:ellipsize="end"
tools:text="Lorem ipsum dolor sit amet"
tools:visibility="visible"
/>

<TextView
Expand All @@ -49,7 +53,9 @@
android:textColor="@color/material_on_background_emphasis_medium"
android:maxLines="5"
android:ellipsize="end"
android:paddingBottom="8dp"
tools:text="Mauris rutrum massa placerat felis pharetra tristique. Nulla sed urna a dui vehicula euismod. Aenean sit amet velit feugiat, aliquet leo sed, sodales risus. Donec non justo et nisi lobortis sodales sed eget erat. Donec ac libero ut enim porta porta id at sem. Aliquam erat volutpat. In eu turpis quis eros posuere porta."
tools:visibility="visible"
/>

</LinearLayout>
Expand Down

0 comments on commit 996eb10

Please sign in to comment.