Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show first item if list has no title #321

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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