forked from upstream-mirrors/quik
@@ -43,7 +43,7 @@ class AvatarView @JvmOverloads constructor(
|
||||
/**
|
||||
* This value can be changes if we should use the theme from a particular conversation
|
||||
*/
|
||||
var threadId: Long = 0
|
||||
var recipientId: Long = 0
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
field = value
|
||||
@@ -81,13 +81,13 @@ class AvatarView @JvmOverloads constructor(
|
||||
super.onFinishInflate()
|
||||
|
||||
if (!isInEditMode) {
|
||||
applyTheme(threadId)
|
||||
applyTheme(recipientId)
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyTheme(threadId: Long) {
|
||||
colors.theme(threadId).run {
|
||||
private fun applyTheme(recipientId: Long) {
|
||||
colors.theme(recipientId).run {
|
||||
setBackgroundTint(theme)
|
||||
initial.setTextColor(textPrimary)
|
||||
icon.setTint(textPrimary)
|
||||
|
||||
@@ -35,7 +35,7 @@ class GroupAvatarView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null
|
||||
) : ConstraintLayout(context, attrs) {
|
||||
|
||||
var contacts: List<Recipient> = ArrayList()
|
||||
var recipients: List<Recipient> = ArrayList()
|
||||
set(value) {
|
||||
field = value.sortedWith(compareByDescending { contact -> contact.contact?.lookupKey })
|
||||
updateView()
|
||||
@@ -54,17 +54,25 @@ class GroupAvatarView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
avatar1Frame.setBackgroundTint(when (contacts.size > 1) {
|
||||
avatar1Frame.setBackgroundTint(when (recipients.size > 1) {
|
||||
true -> context.resolveThemeColor(android.R.attr.windowBackground)
|
||||
false -> context.getColorCompat(android.R.color.transparent)
|
||||
})
|
||||
avatar1Frame.updateLayoutParams<LayoutParams> {
|
||||
matchConstraintPercentWidth = if (contacts.size > 1) 0.75f else 1.0f
|
||||
matchConstraintPercentWidth = if (recipients.size > 1) 0.75f else 1.0f
|
||||
}
|
||||
avatar2.isVisible = contacts.size > 1
|
||||
avatar2.isVisible = recipients.size > 1
|
||||
|
||||
avatar1.setContact(contacts.getOrNull(0)?.contact)
|
||||
avatar2.setContact(contacts.getOrNull(1)?.contact)
|
||||
|
||||
recipients.getOrNull(0).let { recipient ->
|
||||
avatar1.recipientId = recipient?.id ?: 0
|
||||
avatar1.setContact(recipient?.contact)
|
||||
}
|
||||
|
||||
recipients.getOrNull(1).let { recipient ->
|
||||
avatar2.recipientId = recipient?.id ?: 0
|
||||
avatar2.setContact(recipient?.contact)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
|
||||
private val threadId: Subject<Long> = BehaviorSubject.create()
|
||||
private val recipientId: Subject<Long> = BehaviorSubject.create()
|
||||
|
||||
var pager: ViewPager? = null
|
||||
set(value) {
|
||||
@@ -55,8 +55,8 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
if (!isInEditMode) appComponent.inject(this)
|
||||
}
|
||||
|
||||
fun setThreadId(id: Long) {
|
||||
threadId.onNext(id)
|
||||
fun setRecipientId(id: Long) {
|
||||
recipientId.onNext(id)
|
||||
}
|
||||
|
||||
private fun recreate() {
|
||||
@@ -90,9 +90,9 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
intArrayOf(android.R.attr.state_activated),
|
||||
intArrayOf(-android.R.attr.state_activated))
|
||||
|
||||
threadId
|
||||
recipientId
|
||||
.distinctUntilChanged()
|
||||
.switchMap { threadId -> colors.themeObservable(threadId) }
|
||||
.switchMap { recipientId -> colors.themeObservable(recipientId) }
|
||||
.map { theme ->
|
||||
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
|
||||
|
||||
Reference in New Issue
Block a user