forked from upstream-mirrors/quik
@@ -28,7 +28,7 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.avatar_view.view.*
|
||||
import javax.inject.Inject
|
||||
@@ -40,28 +40,20 @@ class AvatarView @JvmOverloads constructor(
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var navigator: Navigator
|
||||
|
||||
/**
|
||||
* This value can be changes if we should use the theme from a particular conversation
|
||||
*/
|
||||
var recipientId: Long = 0
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
field = value
|
||||
applyTheme(value)
|
||||
}
|
||||
|
||||
private var lookupKey: String? = null
|
||||
private var name: String? = null
|
||||
private var photoUri: String? = null
|
||||
private var lastUpdated: Long? = null
|
||||
private var theme: Colors.Theme
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
View.inflate(context, R.layout.avatar_view, this)
|
||||
theme = colors.theme()
|
||||
|
||||
View.inflate(context, R.layout.avatar_view, this)
|
||||
setBackgroundResource(R.drawable.circle)
|
||||
clipToOutline = true
|
||||
}
|
||||
@@ -69,11 +61,12 @@ class AvatarView @JvmOverloads constructor(
|
||||
/**
|
||||
* Use the [contact] information to display the avatar.
|
||||
*/
|
||||
fun setContact(contact: Contact?) {
|
||||
lookupKey = contact?.lookupKey
|
||||
name = contact?.name
|
||||
photoUri = contact?.photoUri
|
||||
lastUpdated = contact?.lastUpdate
|
||||
fun setRecipient(recipient: Recipient?) {
|
||||
lookupKey = recipient?.contact?.lookupKey
|
||||
name = recipient?.contact?.name
|
||||
photoUri = recipient?.contact?.photoUri
|
||||
lastUpdated = recipient?.contact?.lastUpdate
|
||||
theme = colors.theme(recipient)
|
||||
updateView()
|
||||
}
|
||||
|
||||
@@ -81,20 +74,16 @@ class AvatarView @JvmOverloads constructor(
|
||||
super.onFinishInflate()
|
||||
|
||||
if (!isInEditMode) {
|
||||
applyTheme(recipientId)
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyTheme(recipientId: Long) {
|
||||
colors.theme(recipientId).run {
|
||||
setBackgroundTint(theme)
|
||||
initial.setTextColor(textPrimary)
|
||||
icon.setTint(textPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
// Apply theme
|
||||
setBackgroundTint(theme.theme)
|
||||
initial.setTextColor(theme.textPrimary)
|
||||
icon.setTint(theme.textPrimary)
|
||||
|
||||
if (name?.isNotEmpty() == true) {
|
||||
val initials = name?.split(" ").orEmpty()
|
||||
.filter { name -> name.isNotEmpty() }
|
||||
|
||||
@@ -64,15 +64,8 @@ class GroupAvatarView @JvmOverloads constructor(
|
||||
avatar2.isVisible = recipients.size > 1
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
recipients.getOrNull(0).run(avatar1::setRecipient)
|
||||
recipients.getOrNull(1).run(avatar2::setRecipient)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.forEach
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.extensions.Optional
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.uber.autodispose.android.ViewScopeProvider
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
@@ -40,6 +42,7 @@ import javax.inject.Inject
|
||||
class PagerTitleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var conversationRepo: ConversationRepository
|
||||
|
||||
private val recipientId: Subject<Long> = BehaviorSubject.create()
|
||||
|
||||
@@ -92,7 +95,8 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
|
||||
recipientId
|
||||
.distinctUntilChanged()
|
||||
.switchMap { recipientId -> colors.themeObservable(recipientId) }
|
||||
.map { recipientId -> Optional(conversationRepo.getRecipient(recipientId)) }
|
||||
.switchMap { recipient -> colors.themeObservable(recipient.value) }
|
||||
.map { theme ->
|
||||
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
|
||||
|
||||
Reference in New Issue
Block a user