Skip to content
This repository was archived by the owner on Feb 17, 2020. It is now read-only.

Commit 2747dcb

Browse files
committed
add the track to the event detail and remove the Option from the track
1 parent 4e4d009 commit 2747dcb

9 files changed

Lines changed: 91 additions & 34 deletions

File tree

app/src/debug/java/net/squanchy/support/debug/DebugActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ class DebugActivity : AppCompatActivity() {
108108
"0",
109109
0,
110110
"UI",
111-
Option(generateColor()),
112-
Option(generateColor()),
113-
Option.empty()
111+
generateColor(),
112+
generateColor(),
113+
null
114114
)
115115

116116
private fun generateColor(): String {

app/src/main/java/net/squanchy/eventdetails/widget/EventDetailsLayout.kt

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package net.squanchy.eventdetails.widget
22

33
import android.content.Context
44
import android.content.res.Resources
5+
import android.graphics.Color
56
import android.support.annotation.AttrRes
67
import android.support.annotation.ColorInt
78
import android.support.constraint.ConstraintLayout
@@ -12,13 +13,15 @@ import android.text.style.ForegroundColorSpan
1213
import android.util.AttributeSet
1314
import android.util.TypedValue
1415
import android.view.View
16+
import android.widget.TextView
1517
import androidx.view.isVisible
1618
import arrow.core.Option
1719
import kotlinx.android.synthetic.main.merge_event_details_layout.view.*
1820
import net.squanchy.R
1921
import net.squanchy.eventdetails.domain.view.ExperienceLevel
2022
import net.squanchy.schedule.domain.view.Event
2123
import net.squanchy.schedule.domain.view.Place
24+
import net.squanchy.schedule.domain.view.Track
2225
import net.squanchy.support.lang.getOrThrow
2326
import net.squanchy.support.text.parseHtml
2427
import 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>) {
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package net.squanchy.schedule.domain.view
22

3-
import arrow.core.Option
4-
53
data class Track(
64
val id: String,
75
val numericId: Long,
86
val name: String,
9-
val accentColor: Option<String> = Option.empty(),
10-
val textColor: Option<String> = Option.empty(),
11-
val iconUrl: Option<String> = Option.empty()
7+
val accentColor: String? = null,
8+
val textColor: String? = null,
9+
val iconUrl: String? = null
1210
)

app/src/main/java/net/squanchy/schedule/tracksfilter/TracksFilterAdapter.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import android.view.ViewGroup
1111
import net.squanchy.R
1212
import net.squanchy.schedule.domain.view.Track
1313
import net.squanchy.schedule.tracksfilter.widget.FilterChipView
14-
import net.squanchy.support.lang.getOrThrow
15-
import net.squanchy.support.lang.or
1614

1715
internal class TracksFilterAdapter(
1816
context: Context,
@@ -57,9 +55,11 @@ internal class TrackViewHolder(val item: FilterChipView) : RecyclerView.ViewHold
5755
item.apply {
5856
text = track.name
5957

60-
color = track.accentColor
61-
.map { Color.parseColor(track.accentColor.getOrThrow()) }
62-
.or(ContextCompat.getColor(context, R.color.chip_default_background_tint))
58+
if (track.accentColor != null) {
59+
color = Color.parseColor(track.accentColor)
60+
} else {
61+
color = ContextCompat.getColor(context, R.color.chip_default_background_tint)
62+
}
6363

6464
onCheckedChangeListener = { _, checked -> listener.invoke(track, checked) }
6565
isChecked = selected

app/src/main/java/net/squanchy/service/firebase/FirestoreMappers.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ fun FirestoreTrack.toTrack(checksum: Checksum) = Track(
2222
id = id,
2323
numericId = checksum.getChecksumOf("track_$id"),
2424
name = name,
25-
accentColor = accentColor.option(),
26-
textColor = textColor.option(),
27-
iconUrl = iconUrl.option()
25+
accentColor = accentColor,
26+
textColor = textColor,
27+
iconUrl = iconUrl
2828
)
2929

3030
fun FirestoreSpeaker.toSpeaker(checksum: Checksum) = Speaker(

app/src/main/res/layout/merge_event_details_layout.xml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,48 @@
127127
app:constraint_referenced_ids="levelValue,levelLabel"
128128
tools:visibility="visible" />
129129

130+
<TextView
131+
android:id="@+id/trackLabel"
132+
style="@style/EventDetails.Body.Label.Track"
133+
android:layout_width="wrap_content"
134+
android:layout_height="wrap_content"
135+
android:layout_marginTop="@dimen/event_details_body_row_margin_top"
136+
app:layout_constraintStart_toStartOf="@+id/labelsStartMargin"
137+
app:layout_constraintTop_toBottomOf="@+id/levelBarrier" />
138+
139+
<TextView
140+
android:id="@+id/trackValue"
141+
style="@style/EventDetails.Body.Value.Level"
142+
android:layout_width="@dimen/match_constraint"
143+
android:layout_height="wrap_content"
144+
app:layout_constraintStart_toEndOf="@+id/valuesBarrier"
145+
app:layout_constraintEnd_toEndOf="@+id/whenValue"
146+
app:layout_constraintBaseline_toBaselineOf="@+id/trackLabel"
147+
tools:text="Tools" />
148+
149+
<android.support.constraint.Barrier
150+
android:id="@+id/trackBarrier"
151+
android:layout_width="wrap_content"
152+
android:layout_height="wrap_content"
153+
app:barrierDirection="bottom"
154+
app:barrierAllowsGoneWidgets="true"
155+
app:constraint_referenced_ids="trackLabel,trackValue" />
156+
157+
<android.support.constraint.Group
158+
android:id="@+id/trackGroup"
159+
android:layout_width="wrap_content"
160+
android:layout_height="wrap_content"
161+
android:visibility="gone"
162+
app:constraint_referenced_ids="trackValue,trackLabel"
163+
tools:visibility="visible" />
164+
130165
<TextView
131166
android:id="@+id/descriptionLabel"
132167
style="@style/EventDetails.Body.Label.About"
133168
android:layout_width="wrap_content"
134169
android:layout_height="wrap_content"
135170
android:layout_marginTop="@dimen/event_details_body_row_margin_top"
136-
app:layout_constraintTop_toBottomOf="@id/levelBarrier"
171+
app:layout_constraintTop_toBottomOf="@id/trackBarrier"
137172
app:layout_constraintStart_toStartOf="@+id/labelsStartMargin"
138173
tools:visibility="visible" />
139174

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<string name="event_details_body_label_where_text">Where</string>
5353
<string name="event_details_body_label_level_text">Level</string>
5454
<string name="event_details_body_label_about_text">About</string>
55+
<string name="event_details_body_label_track_text">Track</string>
5556

5657
<string name="menu_speaker_twitter">Twitter profile</string>
5758
<string name="menu_speaker_website">Personal page</string>

app/src/main/res/values/styles.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@
235235
<item name="android:text">@string/event_details_body_label_level_text</item>
236236
</style>
237237

238+
<style name="EventDetails.Body.Label.Track" parent="EventDetails.Body.Label">
239+
<item name="android:text">@string/event_details_body_label_track_text</item>
240+
</style>
241+
238242
<style name="EventDetails.Body.Label.About" parent="EventDetails.Body.Label">
239243
<item name="android:gravity">start|center_vertical</item>
240244
<item name="android:text">@string/event_details_body_label_about_text</item>
@@ -783,5 +787,4 @@
783787
</style>
784788

785789
<style name="TextAppearance.Squanchy.WifiConfigError.Button" parent="TextAppearance.Squanchy.Button.Colored" />
786-
787790
</resources>

app/src/test/java/net/squanchy/schedule/domain/view/ScheduleFixtures.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ fun aTrack(
8282
id: String = "a track id",
8383
numericId: Long = 0,
8484
name: String = "a track name",
85-
accentColor: Option<String> = Option("#ABCDEF"),
86-
textColor: Option<String> = Option("#FEDCBA"),
87-
iconUrl: Option<String> = Option("www.squanchy.net")
85+
accentColor: String? = "#ABCDEF",
86+
textColor: String? = "#FEDCBA",
87+
iconUrl: String? = "www.squanchy.net"
8888
) = Track(
8989
id = id,
9090
numericId = numericId,

0 commit comments

Comments
 (0)