Skip to content

Commit

Permalink
Merge pull request #321 from PhilKes/fix/empty-list-preview
Browse files Browse the repository at this point in the history
Show first item if list has no title
  • Loading branch information
PhilKes authored Jan 29, 2025
2 parents 2438b42 + b9ad92b commit 176f1d5
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BaseNoteVH(

when (baseNote.type) {
Type.NOTE -> bindNote(baseNote.body, baseNote.spans, baseNote.title.isEmpty())
Type.LIST -> bindList(baseNote.items)
Type.LIST -> bindList(baseNote.items, baseNote.title.isEmpty())
}
val (date, datePrefixResId) =
when (sortBy) {
Expand Down Expand Up @@ -175,14 +175,15 @@ class BaseNoteVH(
}
}

private fun bindList(items: List<ListItem>) {
private fun bindList(items: List<ListItem>, isTitleEmpty: Boolean) {
binding.apply {
Note.visibility = GONE
if (items.isEmpty()) {
LinearLayout.visibility = GONE
} else {
LinearLayout.visibility = VISIBLE
val filteredList = items.take(preferences.maxItems)
val forceShowFirstItem = preferences.maxItems < 1 && isTitleEmpty
val filteredList = items.take(if (forceShowFirstItem) 1 else preferences.maxItems)
LinearLayout.children.forEachIndexed { index, view ->
if (view.id != R.id.ItemsRemaining) {
if (index < filteredList.size) {
Expand All @@ -196,6 +197,9 @@ class BaseNoteVH(
marginStart = 20.dp(context)
}
}
if (index == filteredList.lastIndex) {
updatePadding(bottom = 0)
}
}
} else view.visibility = GONE
}
Expand Down

0 comments on commit 176f1d5

Please sign in to comment.