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

Commit da249dd

Browse files
committed
Merge branches 'add_track_event_detail' and 'develop' of github.com:squanchy-dev/squanchy-android into add_track_event_detail
# Conflicts: # app/src/main/java/net/squanchy/eventdetails/widget/EventDetailsLayout.kt
2 parents 99d65ff + 218b583 commit da249dd

13 files changed

Lines changed: 57 additions & 46 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import android.content.Context
44
import android.content.res.Resources
55
import android.graphics.Color
66
import android.support.annotation.AttrRes
7-
import android.support.annotation.ColorInt
87
import android.support.constraint.ConstraintLayout
98
import android.support.v4.content.ContextCompat
109
import android.text.SpannableStringBuilder
1110
import android.text.Spanned
1211
import android.text.style.ForegroundColorSpan
1312
import android.util.AttributeSet
14-
import android.util.TypedValue
1513
import android.view.View
1614
import android.widget.TextView
1715
import androidx.view.isVisible
@@ -21,6 +19,7 @@ import net.squanchy.R
2119
import net.squanchy.eventdetails.domain.view.ExperienceLevel
2220
import net.squanchy.schedule.domain.view.Event
2321
import net.squanchy.schedule.domain.view.Place
22+
import net.squanchy.support.content.res.getColorFromAttribute
2423
import net.squanchy.schedule.domain.view.Track
2524
import net.squanchy.support.lang.getOrThrow
2625
import net.squanchy.support.text.parseHtml
@@ -112,6 +111,11 @@ class EventDetailsLayout @JvmOverloads constructor(
112111
endCompoundDrawable?.setTint(color)
113112
}
114113

114+
private fun createColorSpan(targetView: View, @AttrRes attributeResId: Int): ForegroundColorSpan {
115+
val color = targetView.context.theme.getColorFromAttribute(attributeResId)
116+
return ForegroundColorSpan(color)
117+
}
118+
115119
private fun updateTrack(trackOption: Option<Track>) {
116120
if (trackOption.isDefined()) {
117121
trackGroup.isVisible = true

app/src/main/java/net/squanchy/home/HomeActivity.kt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import android.content.Context
55
import android.content.Intent
66
import android.content.res.Resources
77
import android.os.Bundle
8-
import android.support.annotation.AttrRes
98
import android.support.annotation.ColorInt
109
import android.support.transition.Fade
1110
import android.support.transition.TransitionManager
1211
import android.support.v7.app.AppCompatActivity
13-
import android.util.TypedValue
1412
import android.view.View
1513
import androidx.view.isInvisible
1614
import androidx.view.isVisible
@@ -22,6 +20,7 @@ import net.squanchy.home.deeplink.HomeActivityDeepLinkCreator
2220
import net.squanchy.home.deeplink.HomeActivityIntentParser
2321
import net.squanchy.navigation.Navigator
2422
import net.squanchy.signin.SignInOrigin
23+
import net.squanchy.support.content.res.getColorFromAttribute
2524
import net.squanchy.support.widget.InterceptingBottomNavigationView
2625

2726
class HomeActivity : AppCompatActivity() {
@@ -108,8 +107,8 @@ class HomeActivity : AppCompatActivity() {
108107
bottomNavigationView.selectItemAt(section.ordinal)
109108

110109
val theme = getThemeFor(section)
111-
bottomNavigationView.setBackgroundColor(getColorFromTheme(theme, android.support.design.R.attr.colorPrimary))
112-
window.statusBarColor = getColorFromTheme(theme, android.R.attr.statusBarColor)
110+
bottomNavigationView.setBackgroundColor(theme.getColorFromAttribute(android.support.design.R.attr.colorPrimary))
111+
window.statusBarColor = theme.getColorFromAttribute(android.R.attr.statusBarColor)
113112

114113
currentSection = section
115114
}
@@ -125,8 +124,8 @@ class HomeActivity : AppCompatActivity() {
125124
swapPageTo(section)
126125

127126
val theme = getThemeFor(section)
128-
animateStatusBarColorTo(getColorFromTheme(theme, android.R.attr.statusBarColor))
129-
bottomNavigationView.colorProvider = { getColorFromTheme(theme, android.support.design.R.attr.colorPrimary) }
127+
animateStatusBarColorTo(theme.getColorFromAttribute(android.R.attr.statusBarColor))
128+
bottomNavigationView.colorProvider = { theme.getColorFromAttribute(android.support.design.R.attr.colorPrimary) }
130129

131130
currentSection = section
132131

@@ -147,13 +146,6 @@ class HomeActivity : AppCompatActivity() {
147146
}
148147
}
149148

150-
@ColorInt
151-
private fun getColorFromTheme(theme: Resources.Theme, @AttrRes attributeId: Int): Int {
152-
val typedValue = TypedValue()
153-
theme.resolveAttribute(attributeId, typedValue, true)
154-
return typedValue.data
155-
}
156-
157149
private fun animateStatusBarColorTo(@ColorInt color: Int) {
158150
val currentStatusBarColor = window.statusBarColor
159151

app/src/main/java/net/squanchy/schedule/view/TalkEventItemView.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import kotlinx.android.synthetic.main.item_schedule_event_talk.view.*
88
import net.squanchy.R
99
import net.squanchy.schedule.domain.view.Event
1010
import net.squanchy.schedule.domain.view.Place
11+
import net.squanchy.support.content.res.getColorFromAttribute
12+
import net.squanchy.support.graphics.toColorStateList
1113
import net.squanchy.support.lang.getOrThrow
1214
import org.joda.time.format.DateTimeFormat
15+
import java.util.Locale
1316

1417
class TalkEventItemView @JvmOverloads constructor(
1518
context: Context,
@@ -30,15 +33,21 @@ class TalkEventItemView @JvmOverloads constructor(
3033
isVisible = showRoom
3134
}
3235

33-
if (event.experienceLevel.isDefined()) {
34-
experience_level.setExperienceLevel(event.experienceLevel.getOrThrow())
35-
experience_level.isVisible = true
36-
} else {
37-
experience_level.isVisible = false
36+
when {
37+
event.type == Event.Type.KEYNOTE -> {
38+
experienceLevel.text = event.type.name.toLowerCase(Locale.getDefault())
39+
experienceLevel.backgroundTintList = context.theme.getColorFromAttribute(R.attr.colorAccent).toColorStateList()
40+
experienceLevel.isVisible = true
41+
}
42+
event.experienceLevel.isDefined() -> {
43+
experienceLevel.setExperienceLevel(event.experienceLevel.getOrThrow())
44+
experienceLevel.isVisible = true
45+
}
46+
else -> experienceLevel.isVisible = false
3847
}
3948

40-
speaker_container.visibility = if (event.speakers.isEmpty()) View.GONE else View.VISIBLE
41-
speaker_container.updateWith(event.speakers, null)
49+
speakersContainer.visibility = if (event.speakers.isEmpty()) View.GONE else View.VISIBLE
50+
speakersContainer.updateWith(event.speakers, null)
4251

4352
favoriteIcon.isVisible = if (showFavorite) event.favorite else false
4453
}

app/src/main/java/net/squanchy/search/SearchItemView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SearchItemView @JvmOverloads constructor(
2626
}
2727

2828
fun updateWith(speaker: Speaker, imageLoader: ImageLoader, listener: OnSearchResultClickListener) {
29-
speakerName.text = speaker.name
29+
speakerNames.text = speaker.name
3030
updateSpeakerPhotos(speaker, imageLoader)
3131
setOnClickListener { listener.onSpeakerClicked(speaker) }
3232
}

app/src/main/java/net/squanchy/speaker/widget/SpeakerHeaderView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SpeakerHeaderView @JvmOverloads constructor(
3131
fun updateWith(speaker: Speaker) {
3232
updatePhoto(speaker.photoUrl, imageLoader)
3333

34-
speakerName.text = speaker.name
34+
speakerNames.text = speaker.name
3535

3636
val companyName = speaker.companyName
3737
if (companyName.isDefined()) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package net.squanchy.support.content.res
2+
3+
import android.content.res.Resources
4+
import android.support.annotation.AttrRes
5+
import android.support.annotation.ColorInt
6+
import android.util.TypedValue
7+
8+
@ColorInt
9+
internal fun Resources.Theme.getColorFromAttribute(@AttrRes attributeId: Int): Int {
10+
val typedValue = TypedValue()
11+
resolveAttribute(attributeId, typedValue, true)
12+
return typedValue.data
13+
}

app/src/main/java/net/squanchy/support/graphics/Color.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.squanchy.support.graphics
22

3+
import android.content.res.ColorStateList
34
import android.support.annotation.ColorInt
45
import android.support.annotation.FloatRange
56
import android.support.v4.graphics.ColorUtils
@@ -62,3 +63,5 @@ private var HSLColor.lightness
6263
set(@FloatRange(from = MIN_LIGHTNESS.toDouble(), to = MAX_LIGHTNESS.toDouble()) value) {
6364
this[HSL_COMPONENT_LIGHTNESS] = value
6465
}
66+
67+
internal fun Int.toColorStateList() = ColorStateList.valueOf(this)

app/src/main/java/net/squanchy/support/widget/SpeakerView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class SpeakerView @JvmOverloads constructor(
3838
}
3939

4040
fun updateWith(speakers: List<Speaker>, listener: OnSpeakerClickListener?) {
41-
speakerName.text = toCommaSeparatedNames(speakers)
41+
speakerNames.text = toCommaSeparatedNames(speakers)
4242
updateSpeakerPhotos(speakers, listener, imageLoader)
4343
}
4444

app/src/main/java/net/squanchy/tweets/view/TweetUrlSpanFactory.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package net.squanchy.tweets.view
22

33
import android.content.Context
4-
import android.content.res.Resources
5-
import android.support.annotation.AttrRes
6-
import android.support.annotation.ColorInt
74
import android.text.SpannableStringBuilder
85
import android.text.Spanned
9-
import android.util.TypedValue
106
import net.squanchy.R
117
import net.squanchy.service.firebase.model.twitter.FirestoreTwitterHashtag
128
import net.squanchy.service.firebase.model.twitter.FirestoreTwitterMention
139
import net.squanchy.service.firebase.model.twitter.FirestoreTwitterUrl
10+
import net.squanchy.support.content.res.getColorFromAttribute
1411
import net.squanchy.support.text.parseHtml
1512
import java.util.regex.Pattern
1613

@@ -55,17 +52,10 @@ class TweetUrlSpanFactory(private val context: Context) {
5552
spanFactory.createFor("https://twitter.com/search?q=$text")
5653

5754
private fun createFor(url: String): TweetUrlSpan {
58-
val linkColor = getColorFromTheme(context.theme, R.attr.tweetLinkTextColor)
55+
val linkColor = context.theme.getColorFromAttribute(R.attr.tweetLinkTextColor)
5956
return TweetUrlSpan(url, linkColor)
6057
}
6158

62-
@ColorInt
63-
private fun getColorFromTheme(theme: Resources.Theme, @AttrRes attributeId: Int): Int {
64-
val typedValue = TypedValue()
65-
theme.resolveAttribute(attributeId, typedValue, true)
66-
return typedValue.data
67-
}
68-
6959
private fun offsetStart(entity: FirestoreTwitterMention, startIndex: Int): FirestoreTwitterMention {
7060
entity.start = entity.start - startIndex
7161
entity.end = entity.end - startIndex

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
tools:background="?colorAccent" />
4040

4141
<TextView
42-
android:id="@+id/speakerName"
42+
android:id="@+id/speakerNames"
4343
style="@style/EventDetails.Header.Speaker.Names"
4444
android:layout_width="match_parent"
4545
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)