Add isInEditMode support for AvatarView

This commit is contained in:
Moez Bhatti
2018-03-05 17:51:21 -05:00
parent 545319756e
commit a45c49c54b
@@ -50,8 +50,11 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
} }
init { init {
if (!isInEditMode) {
appComponent.inject(this)
}
View.inflate(context, R.layout.avatar_view, this) View.inflate(context, R.layout.avatar_view, this)
appComponent.inject(this)
setBackgroundResource(R.drawable.circle) setBackgroundResource(R.drawable.circle)
clipToOutline = true clipToOutline = true
@@ -59,28 +62,31 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
colors.theme
.autoDisposable(scope())
.subscribe { color -> background.setTint(color) }
colors.textPrimaryOnTheme if (!isInEditMode) {
.autoDisposable(scope()) colors.theme
.subscribe { color -> icon.setTint(color) } .autoDisposable(scope())
.subscribe { color -> background.setTint(color) }
clicks() colors.textPrimaryOnTheme
.autoDisposable(scope()) .autoDisposable(scope())
.subscribe { .subscribe { color -> icon.setTint(color) }
if (contact?.lookupKey.isNullOrEmpty()) {
contact?.numbers?.firstOrNull()?.let { number -> clicks()
navigator.addContact(number.address) .autoDisposable(scope())
.subscribe {
if (contact?.lookupKey.isNullOrEmpty()) {
contact?.numbers?.firstOrNull()?.let { number ->
navigator.addContact(number.address)
}
} else {
val key = contact?.lookupKey
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, key)
ContactsContract.QuickContact.showQuickContact(context, this@AvatarView, uri,
ContactsContract.QuickContact.MODE_MEDIUM, null)
} }
} else {
val key = contact?.lookupKey
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, key)
ContactsContract.QuickContact.showQuickContact(context, this@AvatarView, uri,
ContactsContract.QuickContact.MODE_MEDIUM, null)
} }
} }
} }
override fun onFinishInflate() { override fun onFinishInflate() {