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 {
if (!isInEditMode) {
appComponent.inject(this)
}
View.inflate(context, R.layout.avatar_view, this)
appComponent.inject(this)
setBackgroundResource(R.drawable.circle)
clipToOutline = true
@@ -59,28 +62,31 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
override fun onAttachedToWindow() {
super.onAttachedToWindow()
colors.theme
.autoDisposable(scope())
.subscribe { color -> background.setTint(color) }
colors.textPrimaryOnTheme
.autoDisposable(scope())
.subscribe { color -> icon.setTint(color) }
if (!isInEditMode) {
colors.theme
.autoDisposable(scope())
.subscribe { color -> background.setTint(color) }
clicks()
.autoDisposable(scope())
.subscribe {
if (contact?.lookupKey.isNullOrEmpty()) {
contact?.numbers?.firstOrNull()?.let { number ->
navigator.addContact(number.address)
colors.textPrimaryOnTheme
.autoDisposable(scope())
.subscribe { color -> icon.setTint(color) }
clicks()
.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() {