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

Commit de0950c

Browse files
authored
Merge pull request #563 from squanchy-dev/add_track_event_detail
Add track event detail
2 parents 4e98966 + bc3d0c9 commit de0950c

12 files changed

Lines changed: 95 additions & 38 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: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package net.squanchy.eventdetails.widget
22

33
import android.content.Context
4+
import android.graphics.Color
45
import android.support.annotation.AttrRes
6+
import android.support.annotation.ColorInt
57
import android.support.constraint.ConstraintLayout
68
import android.support.v4.content.ContextCompat
79
import android.text.SpannableStringBuilder
810
import android.text.Spanned
911
import android.text.style.ForegroundColorSpan
1012
import android.util.AttributeSet
1113
import android.view.View
14+
import android.widget.TextView
1215
import androidx.view.isVisible
1316
import arrow.core.Option
1417
import kotlinx.android.synthetic.main.merge_event_details_layout.view.*
1518
import net.squanchy.R
1619
import net.squanchy.eventdetails.domain.view.ExperienceLevel
1720
import net.squanchy.schedule.domain.view.Event
1821
import net.squanchy.schedule.domain.view.Place
22+
import net.squanchy.schedule.domain.view.Track
1923
import net.squanchy.support.content.res.getColorFromAttribute
2024
import net.squanchy.support.lang.getOrThrow
2125
import net.squanchy.support.text.parseHtml
@@ -41,6 +45,7 @@ class EventDetailsLayout @JvmOverloads constructor(
4145
updateWhen(event.startTime, event.timeZone)
4246
updateWhere(event.place)
4347
updateLevel(event.experienceLevel)
48+
updateTrack(event.track)
4449
updateDescription(event.description)
4550
}
4651

@@ -75,28 +80,45 @@ class EventDetailsLayout @JvmOverloads constructor(
7580
return builder
7681
}
7782

83+
private fun createColorSpan(targetView: View, @AttrRes attributeResId: Int): ForegroundColorSpan {
84+
val color = targetView.context.theme.getColorFromAttribute(attributeResId)
85+
return ForegroundColorSpan(color)
86+
}
87+
7888
private fun updateLevel(level: Option<ExperienceLevel>) {
7989
if (level.isDefined()) {
8090
levelGroup.isVisible = true
8191

8292
val experienceLevel = level.getOrThrow()
8393
levelValue.setText(experienceLevel.labelStringResId)
84-
tintCompoundDrawableEnd(experienceLevel)
94+
val experienceColor = ContextCompat.getColor(context, experienceLevel.colorResId)
95+
tintCompoundDrawableEnd(levelValue, experienceColor)
8596
} else {
8697
levelGroup.isVisible = false
8798
}
8899
}
89100

90-
private fun tintCompoundDrawableEnd(experienceLevel: ExperienceLevel) {
91-
val compoundDrawables = levelValue.compoundDrawablesRelative
101+
private fun tintCompoundDrawableEnd(textView: TextView, @ColorInt color: Int) {
102+
val compoundDrawables = textView.compoundDrawablesRelative
92103
val endCompoundDrawable = compoundDrawables[2]
93-
endCompoundDrawable?.setTint(ContextCompat.getColor(context, experienceLevel.colorResId))
104+
endCompoundDrawable?.setTint(color)
94105
}
95106

96-
private fun createColorSpan(targetView: View, @AttrRes attributeResId: Int): ForegroundColorSpan {
97-
val color = targetView.context.theme.getColorFromAttribute(attributeResId)
98-
return ForegroundColorSpan(color)
107+
private fun updateTrack(trackOption: Option<Track>) {
108+
if (trackOption.isDefined()) {
109+
trackGroup.isVisible = true
110+
111+
val track = trackOption.getOrThrow()
112+
trackValue.text = track.name
113+
track.accentColor?.let {
114+
val trackColor = Color.parseColor(it)
115+
tintCompoundDrawableEnd(trackValue, trackColor)
116+
}
117+
} else {
118+
trackGroup.isVisible = false
119+
}
99120
}
121+
100122
private fun updateDescription(description: Option<String>) {
101123
if (description.isDefined()) {
102124
descriptionGroup.isVisible = true

app/src/main/java/net/squanchy/notification/NotificationCreator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class NotificationCreator(private val context: Context) {
127127

128128
private fun getTrackColor(event: Event): Int {
129129
return event.track
130-
.map { (_, _, _, accentColor) -> Color.parseColor(accentColor.or(ARGB_TRANSPARENT)) }
130+
.map { Color.parseColor(it.accentColor ?: ARGB_TRANSPARENT) }
131131
.or(Color.TRANSPARENT)
132132
}
133133

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>
@@ -784,5 +788,4 @@
784788
</style>
785789

786790
<style name="TextAppearance.Squanchy.WifiConfigError.Button" parent="TextAppearance.Squanchy.Button.Colored" />
787-
788791
</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)