diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt index 524bb783..0f8b7875 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt @@ -20,10 +20,12 @@ package com.moez.QKSMS.feature.compose import android.view.LayoutInflater import android.view.ViewGroup +import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import com.moez.QKSMS.R import com.moez.QKSMS.common.base.QkAdapter import com.moez.QKSMS.common.base.QkViewHolder +import com.moez.QKSMS.common.util.extensions.forwardTouches import com.moez.QKSMS.common.util.extensions.setVisible import com.moez.QKSMS.model.Contact import io.reactivex.subjects.PublishSubject @@ -42,32 +44,34 @@ class ContactAdapter @Inject constructor() : QkAdapter() { val view = layoutInflater.inflate(R.layout.contact_list_item, parent, false) view.addresses.setRecycledViewPool(numbersViewPool) + view.addresses.adapter = PhoneNumberAdapter() + view.addresses.forwardTouches(view) return QkViewHolder(view).apply { - view.primary.setOnClickListener { + view.setOnClickListener { val contact = getItem(adapterPosition) - contactSelected.onNext(copyContact(contact, 0)) - } - - view.addresses.adapter = PhoneNumberAdapter { contact, index -> - contactSelected.onNext(copyContact(contact, index + 1)) + contactSelected.onNext(contact) } } } override fun onBindViewHolder(holder: QkViewHolder, position: Int) { + val prevContact = if (position > 0) getItem(position - 1) else null val contact = getItem(position) val view = holder.containerView + view.index.text = if (contact.name[0].isLetter()) contact.name[0].toString() else "#" + view.index.isVisible = prevContact == null || + (contact.name[0].isLetter() && contact.name[0] != prevContact.name[0]) || + (!contact.name[0].isLetter() && prevContact.name[0].isLetter()) + view.avatar.setContact(contact) view.name.text = contact.name view.name.setVisible(view.name.text.isNotEmpty()) - view.address.text = contact.numbers.firstOrNull()?.address ?: "" - view.type.text = contact.numbers.firstOrNull()?.type ?: "" val adapter = view.addresses.adapter as PhoneNumberAdapter adapter.contact = contact - adapter.data = contact.numbers.drop(Math.min(contact.numbers.size, 1)) + adapter.data = contact.numbers } /** @@ -80,8 +84,4 @@ class ContactAdapter @Inject constructor() : QkAdapter() { numbers.add(contact.numbers[numberIndex]) } - override fun areItemsTheSame(old: Contact, new: Contact): Boolean { - return old.lookupKey == new.lookupKey - } - -} \ No newline at end of file +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/PhoneNumberAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/PhoneNumberAdapter.kt index 94d62e38..14db217c 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/PhoneNumberAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/PhoneNumberAdapter.kt @@ -25,11 +25,9 @@ import com.moez.QKSMS.common.base.QkAdapter import com.moez.QKSMS.common.base.QkViewHolder import com.moez.QKSMS.model.Contact import com.moez.QKSMS.model.PhoneNumber -import kotlinx.android.synthetic.main.contact_list_item.view.* +import kotlinx.android.synthetic.main.contact_number_list_item.view.* -class PhoneNumberAdapter( - private val numberClicked: (Contact, Int) -> Unit -) : QkAdapter() { +class PhoneNumberAdapter : QkAdapter() { lateinit var contact: Contact @@ -43,10 +41,6 @@ class PhoneNumberAdapter( val number = getItem(position) val view = holder.containerView - // Setting this in onCreateViewHolder causes a crash sometimes. [contact] returns the - // contact from a different row, I'm not sure why - view.setOnClickListener { numberClicked(contact, position) } - view.address.text = number.address view.type.text = number.type } diff --git a/presentation/src/main/res/layout/contact_list_item.xml b/presentation/src/main/res/layout/contact_list_item.xml index a2c3bd38..7ccfbbe5 100644 --- a/presentation/src/main/res/layout/contact_list_item.xml +++ b/presentation/src/main/res/layout/contact_list_item.xml @@ -21,16 +21,45 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" + android:paddingTop="8dp" + android:paddingBottom="8dp"> + + + + @@ -41,59 +70,24 @@ android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" - app:layout_constraintBottom_toTopOf="@id/address" + android:textStyle="bold" + app:layout_constraintBottom_toTopOf="@id/addresses" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toEndOf="@id/avatar" - app:layout_constraintTop_toTopOf="@id/avatar" + app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_chainStyle="packed" tools:text="Moez Bhatti" /> - - - - - - \ No newline at end of file diff --git a/presentation/src/main/res/layout/contact_number_list_item.xml b/presentation/src/main/res/layout/contact_number_list_item.xml index 5aa2b23d..0ea6fab3 100644 --- a/presentation/src/main/res/layout/contact_number_list_item.xml +++ b/presentation/src/main/res/layout/contact_number_list_item.xml @@ -22,26 +22,27 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/selectableItemBackground"> + android:paddingTop="2dp"> + + - - + tools:text="(123) 456-7890" /> \ No newline at end of file