mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-19 12:28:53 +01:00
Update contact list stype to show indices
This commit is contained in:
@@ -20,10 +20,12 @@ package com.moez.QKSMS.feature.compose
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.base.QkAdapter
|
import com.moez.QKSMS.common.base.QkAdapter
|
||||||
import com.moez.QKSMS.common.base.QkViewHolder
|
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.common.util.extensions.setVisible
|
||||||
import com.moez.QKSMS.model.Contact
|
import com.moez.QKSMS.model.Contact
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
@@ -42,32 +44,34 @@ class ContactAdapter @Inject constructor() : QkAdapter<Contact>() {
|
|||||||
val view = layoutInflater.inflate(R.layout.contact_list_item, parent, false)
|
val view = layoutInflater.inflate(R.layout.contact_list_item, parent, false)
|
||||||
|
|
||||||
view.addresses.setRecycledViewPool(numbersViewPool)
|
view.addresses.setRecycledViewPool(numbersViewPool)
|
||||||
|
view.addresses.adapter = PhoneNumberAdapter()
|
||||||
|
view.addresses.forwardTouches(view)
|
||||||
|
|
||||||
return QkViewHolder(view).apply {
|
return QkViewHolder(view).apply {
|
||||||
view.primary.setOnClickListener {
|
view.setOnClickListener {
|
||||||
val contact = getItem(adapterPosition)
|
val contact = getItem(adapterPosition)
|
||||||
contactSelected.onNext(copyContact(contact, 0))
|
contactSelected.onNext(contact)
|
||||||
}
|
|
||||||
|
|
||||||
view.addresses.adapter = PhoneNumberAdapter { contact, index ->
|
|
||||||
contactSelected.onNext(copyContact(contact, index + 1))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
|
val prevContact = if (position > 0) getItem(position - 1) else null
|
||||||
val contact = getItem(position)
|
val contact = getItem(position)
|
||||||
val view = holder.containerView
|
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.avatar.setContact(contact)
|
||||||
view.name.text = contact.name
|
view.name.text = contact.name
|
||||||
view.name.setVisible(view.name.text.isNotEmpty())
|
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
|
val adapter = view.addresses.adapter as PhoneNumberAdapter
|
||||||
adapter.contact = contact
|
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<Contact>() {
|
|||||||
numbers.add(contact.numbers[numberIndex])
|
numbers.add(contact.numbers[numberIndex])
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun areItemsTheSame(old: Contact, new: Contact): Boolean {
|
}
|
||||||
return old.lookupKey == new.lookupKey
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,11 +25,9 @@ import com.moez.QKSMS.common.base.QkAdapter
|
|||||||
import com.moez.QKSMS.common.base.QkViewHolder
|
import com.moez.QKSMS.common.base.QkViewHolder
|
||||||
import com.moez.QKSMS.model.Contact
|
import com.moez.QKSMS.model.Contact
|
||||||
import com.moez.QKSMS.model.PhoneNumber
|
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(
|
class PhoneNumberAdapter : QkAdapter<PhoneNumber>() {
|
||||||
private val numberClicked: (Contact, Int) -> Unit
|
|
||||||
) : QkAdapter<PhoneNumber>() {
|
|
||||||
|
|
||||||
lateinit var contact: Contact
|
lateinit var contact: Contact
|
||||||
|
|
||||||
@@ -43,10 +41,6 @@ class PhoneNumberAdapter(
|
|||||||
val number = getItem(position)
|
val number = getItem(position)
|
||||||
val view = holder.containerView
|
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.address.text = number.address
|
||||||
view.type.text = number.type
|
view.type.text = number.type
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,16 +21,45 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
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">
|
||||||
|
|
||||||
|
<com.moez.QKSMS.common.widget.QkTextView
|
||||||
|
android:id="@+id/index"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:maxLength="1"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:visibility="invisible"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/avatar"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/avatar"
|
||||||
|
app:textColor="theme"
|
||||||
|
app:textSize="primary"
|
||||||
|
tools:text="M"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:visibility="invisible"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/avatar"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/avatar" />
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.AvatarView
|
<com.moez.QKSMS.common.widget.AvatarView
|
||||||
android:id="@+id/avatar"
|
android:id="@+id/avatar"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toEndOf="@id/icon"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintVertical_bias="0" />
|
app:layout_constraintVertical_bias="0" />
|
||||||
|
|
||||||
@@ -41,59 +70,24 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="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_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
app:layout_constraintHorizontal_bias="0"
|
||||||
app:layout_constraintStart_toEndOf="@id/avatar"
|
app:layout_constraintStart_toEndOf="@id/avatar"
|
||||||
app:layout_constraintTop_toTopOf="@id/avatar"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintVertical_chainStyle="packed"
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
tools:text="Moez Bhatti" />
|
tools:text="Moez Bhatti" />
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.QkTextView
|
|
||||||
android:id="@+id/address"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginTop="2dp"
|
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@id/avatar"
|
|
||||||
app:layout_constraintEnd_toStartOf="@id/type"
|
|
||||||
app:layout_constraintStart_toEndOf="@id/avatar"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/name"
|
|
||||||
app:textSize="secondary"
|
|
||||||
tools:text="(123) 456-7890"
|
|
||||||
tools:textColor="@color/textSecondary" />
|
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.QkTextView
|
|
||||||
android:id="@+id/type"
|
|
||||||
style="@style/TextSecondary"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="@id/address"
|
|
||||||
tools:text="Mobile"
|
|
||||||
tools:textColor="@color/textTertiary" />
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/primary"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="56dp"
|
|
||||||
android:background="?attr/selectableItemBackground" />
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/addresses"
|
android:id="@+id/addresses"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
app:layout_constraintEnd_toEndOf="@id/type"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="@id/name"
|
app:layout_constraintStart_toStartOf="@id/name"
|
||||||
app:layout_constraintTop_toBottomOf="@id/address"
|
app:layout_constraintTop_toBottomOf="@id/name"
|
||||||
tools:listitem="@layout/contact_number_list_item" />
|
tools:listitem="@layout/contact_number_list_item" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -22,26 +22,27 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground">
|
android:paddingTop="2dp">
|
||||||
|
|
||||||
|
<com.moez.QKSMS.common.widget.QkTextView
|
||||||
|
android:id="@+id/type"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textColor="?android:attr/textColorTertiary"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:textSize="secondary"
|
||||||
|
tools:text="Mobile" />
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.QkTextView
|
<com.moez.QKSMS.common.widget.QkTextView
|
||||||
android:id="@+id/address"
|
android:id="@+id/address"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorTertiary"
|
||||||
app:textSize="secondary"
|
app:textSize="secondary"
|
||||||
tools:text="(123) 456-7890"
|
tools:text="(123) 456-7890" />
|
||||||
tools:textColor="@color/textSecondary" />
|
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.QkTextView
|
|
||||||
android:id="@+id/type"
|
|
||||||
style="@style/TextSecondary"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
tools:text="Mobile"
|
|
||||||
tools:textColor="@color/textTertiary" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user