From a45c49c54bbdd17b5234ebfd902aa732f154cf33 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Mon, 5 Mar 2018 17:51:21 -0500 Subject: [PATCH] Add isInEditMode support for AvatarView --- .../presentation/common/widget/AvatarView.kt | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/qksms/src/main/java/presentation/common/widget/AvatarView.kt b/qksms/src/main/java/presentation/common/widget/AvatarView.kt index b79b70cf..04cff991 100644 --- a/qksms/src/main/java/presentation/common/widget/AvatarView.kt +++ b/qksms/src/main/java/presentation/common/widget/AvatarView.kt @@ -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() {