Skip to content

Commit

Permalink
Show multiple tags on a list item
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Corry <[email protected]>
  • Loading branch information
kylecorry31 committed Jan 9, 2025
1 parent 540ec8a commit 8295d52
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
import com.vanniktech.maven.publish.SonatypeHost

val versionName = "12.2.0"
val versionName = "12.3.0"
val groupId = "com.kylecorry.andromeda"

buildscript {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.google.android.flexbox.FlexboxLayout
import com.kylecorry.andromeda.core.system.Resources
import com.kylecorry.andromeda.core.ui.Colors
import com.kylecorry.andromeda.list.ListView
import com.kylecorry.andromeda.pickers.Pickers
import com.kylecorry.andromeda.views.R
import com.kylecorry.andromeda.views.badge.Badge
import com.kylecorry.andromeda.views.databinding.AndromedaViewListItemBinding

class AndromedaListView(context: Context, attrs: AttributeSet?) : RecyclerView(context, attrs) {
Expand All @@ -36,21 +38,34 @@ class AndromedaListView(context: Context, attrs: AttributeSet?) : RecyclerView(c
binding.description.isVisible = listItem.subtitle != null

if (listItem.tags.isNotEmpty()) {
// TODO: Allow multiple
val tag = listItem.tags.first()
binding.tag.isVisible = true
val foregroundColor =
Colors.mostContrastingColor(Color.WHITE, Color.BLACK, tag.color)
binding.tag.statusImage.isVisible = tag.icon != null
tag.icon?.let {
it.apply(binding.tag.statusImage)
Colors.setImageColor(binding.tag.statusImage, foregroundColor)
binding.tags.isVisible = true
val margin = Resources.dp(context, 8f).toInt()
val tagViews = listItem.tags.map {
Badge(view.context, null).apply {
val foregroundColor =
Colors.mostContrastingColor(Color.WHITE, Color.BLACK, it.color)
statusImage.isVisible = it.icon != null
it.icon?.let {
it.apply(statusImage)
Colors.setImageColor(statusImage, foregroundColor)
}
setStatusText(it.text)
statusText.setTextColor(foregroundColor)
setBackgroundTint(it.color)
layoutParams = FlexboxLayout.LayoutParams(
FlexboxLayout.LayoutParams.WRAP_CONTENT,
FlexboxLayout.LayoutParams.WRAP_CONTENT
).apply {
setMargins(0, 0, margin, margin)
}
}
}
binding.tags.removeAllViews()
tagViews.forEach {
binding.tags.addView(it)
}
binding.tag.setStatusText(tag.text)
binding.tag.statusText.setTextColor(foregroundColor)
binding.tag.setBackgroundTint(tag.color)
} else {
binding.tag.isVisible = false
binding.tags.isVisible = false
}

binding.trailingText.isVisible = listItem.trailingText != null
Expand Down
12 changes: 7 additions & 5 deletions views/src/main/res/layout/andromeda_view_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
app:flexDirection="column"
app:layout_flexGrow="1">

<com.kylecorry.andromeda.views.badge.Badge
android:id="@+id/tag"
android:layout_width="wrap_content"
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/tags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:visibility="gone"
tools:visibility="visible" />
tools:visibility="visible"
app:alignItems="center"
app:flexDirection="row"
app:flexWrap="wrap" />

<TextView
android:id="@+id/title"
Expand Down

0 comments on commit 8295d52

Please sign in to comment.