@@ -2,6 +2,7 @@ package net.squanchy.eventdetails.widget
22
33import android.content.Context
44import android.content.res.Resources
5+ import android.graphics.Color
56import android.support.annotation.AttrRes
67import android.support.annotation.ColorInt
78import android.support.constraint.ConstraintLayout
@@ -12,13 +13,15 @@ import android.text.style.ForegroundColorSpan
1213import android.util.AttributeSet
1314import android.util.TypedValue
1415import android.view.View
16+ import android.widget.TextView
1517import androidx.view.isVisible
1618import arrow.core.Option
1719import kotlinx.android.synthetic.main.merge_event_details_layout.view.*
1820import net.squanchy.R
1921import net.squanchy.eventdetails.domain.view.ExperienceLevel
2022import net.squanchy.schedule.domain.view.Event
2123import net.squanchy.schedule.domain.view.Place
24+ import net.squanchy.schedule.domain.view.Track
2225import net.squanchy.support.lang.getOrThrow
2326import net.squanchy.support.text.parseHtml
2427import org.joda.time.DateTimeZone
@@ -43,6 +46,7 @@ class EventDetailsLayout @JvmOverloads constructor(
4346 updateWhen(event.startTime, event.timeZone)
4447 updateWhere(event.place)
4548 updateLevel(event.experienceLevel)
49+ updateTrack(event.track)
4650 updateDescription(event.description)
4751 }
4852
@@ -77,34 +81,50 @@ class EventDetailsLayout @JvmOverloads constructor(
7781 return builder
7882 }
7983
84+ private fun createColorSpan (targetView : View , @AttrRes attributeResId : Int ): ForegroundColorSpan {
85+ val color = getColorFromTheme(targetView.context.theme, attributeResId)
86+ return ForegroundColorSpan (color)
87+ }
88+
89+ @ColorInt
90+ private fun getColorFromTheme (theme : Resources .Theme , @AttrRes attributeId : Int ): Int {
91+ val typedValue = TypedValue ()
92+ theme.resolveAttribute(attributeId, typedValue, true )
93+ return typedValue.data
94+ }
95+
8096 private fun updateLevel (level : Option <ExperienceLevel >) {
8197 if (level.isDefined()) {
8298 levelGroup.isVisible = true
8399
84100 val experienceLevel = level.getOrThrow()
85101 levelValue.setText(experienceLevel.labelStringResId)
86- tintCompoundDrawableEnd(experienceLevel)
102+ val experienceColor = ContextCompat .getColor(context, experienceLevel.colorResId)
103+ tintCompoundDrawableEnd(levelValue, experienceColor)
87104 } else {
88105 levelGroup.isVisible = false
89106 }
90107 }
91108
92- private fun tintCompoundDrawableEnd (experienceLevel : ExperienceLevel ) {
93- val compoundDrawables = levelValue .compoundDrawablesRelative
109+ private fun tintCompoundDrawableEnd (textView : TextView , @ColorInt color : Int ) {
110+ val compoundDrawables = textView .compoundDrawablesRelative
94111 val endCompoundDrawable = compoundDrawables[2 ]
95- endCompoundDrawable?.setTint(ContextCompat .getColor(context, experienceLevel.colorResId) )
112+ endCompoundDrawable?.setTint(color )
96113 }
97114
98- private fun createColorSpan (targetView : View , @AttrRes attributeResId : Int ): ForegroundColorSpan {
99- val color = getColorFromTheme(targetView.context.theme, attributeResId)
100- return ForegroundColorSpan (color)
101- }
115+ private fun updateTrack (trackOption : Option <Track >) {
116+ if (trackOption.isDefined()) {
117+ trackGroup.isVisible = true
102118
103- @ColorInt
104- private fun getColorFromTheme (theme : Resources .Theme , @AttrRes attributeId : Int ): Int {
105- val typedValue = TypedValue ()
106- theme.resolveAttribute(attributeId, typedValue, true )
107- return typedValue.data
119+ val track = trackOption.getOrThrow()
120+ trackValue.text = track.name
121+ track.accentColor?.let {
122+ val trackColor = Color .parseColor(it)
123+ tintCompoundDrawableEnd(trackValue, trackColor)
124+ }
125+ } else {
126+ trackGroup.isVisible = false
127+ }
108128 }
109129
110130 private fun updateDescription (description : Option <String >) {
0 commit comments