forked from upstream-mirrors/quik
Display recent, starred, and contact groups in compose
This commit is contained in:
@@ -76,7 +76,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
@Inject lateinit var attachmentAdapter: AttachmentAdapter
|
||||
@Inject lateinit var chipsAdapter: ChipsAdapter
|
||||
@Inject lateinit var contactsAdapter: ContactAdapter
|
||||
@Inject lateinit var contactsAdapter: ComposeItemAdapter
|
||||
@Inject lateinit var dateFormatter: DateFormatter
|
||||
@Inject lateinit var messageAdapter: MessagesAdapter
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@@ -86,7 +86,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val queryChangedIntent: Observable<CharSequence> by lazy { chipsAdapter.textChanges }
|
||||
override val queryBackspaceIntent: Observable<*> by lazy { chipsAdapter.backspaces }
|
||||
override val queryEditorActionIntent: Observable<Int> by lazy { chipsAdapter.actions }
|
||||
override val chipSelectedIntent: Subject<Contact> by lazy { contactsAdapter.contactSelected }
|
||||
override val chipSelectedIntent: Subject<ComposeItem> by lazy { contactsAdapter.itemSelected }
|
||||
override val chipDeletedIntent: Subject<Contact> by lazy { chipsAdapter.chipDeleted }
|
||||
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
|
||||
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
|
||||
@@ -211,7 +211,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}
|
||||
|
||||
chipsAdapter.data = state.selectedContacts
|
||||
contactsAdapter.data = state.contacts
|
||||
contactsAdapter.data = state.composeItems
|
||||
|
||||
loading.setVisible(state.loading)
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose
|
||||
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.ContactGroup
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.PhoneNumber
|
||||
import io.realm.RealmList
|
||||
|
||||
sealed class ComposeItem {
|
||||
|
||||
abstract fun getContacts(): List<Contact>
|
||||
|
||||
data class New(val value: Contact) : ComposeItem() {
|
||||
override fun getContacts(): List<Contact> = listOf(value)
|
||||
}
|
||||
|
||||
data class Recent(val value: Conversation) : ComposeItem() {
|
||||
override fun getContacts(): List<Contact> = value.recipients.map { recipient ->
|
||||
Contact(numbers = RealmList(PhoneNumber(address = recipient.address)))
|
||||
}
|
||||
}
|
||||
|
||||
data class Starred(val value: Contact) : ComposeItem() {
|
||||
override fun getContacts(): List<Contact> = listOf(value)
|
||||
}
|
||||
|
||||
data class Group(val value: ContactGroup) : ComposeItem() {
|
||||
override fun getContacts(): List<Contact> = value.contacts
|
||||
}
|
||||
|
||||
data class Person(val value: Contact) : ComposeItem() {
|
||||
override fun getContacts(): List<Contact> = listOf(value)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
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.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.forwardTouches
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.ContactGroup
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.contact_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ComposeItemAdapter @Inject constructor(private val colors: Colors) : QkAdapter<ComposeItem>() {
|
||||
|
||||
val itemSelected: Subject<ComposeItem> = PublishSubject.create()
|
||||
|
||||
private val numbersViewPool = RecyclerView.RecycledViewPool()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val view = layoutInflater.inflate(R.layout.contact_list_item, parent, false)
|
||||
|
||||
view.icon.setTint(colors.theme().theme)
|
||||
|
||||
view.numbers.setRecycledViewPool(numbersViewPool)
|
||||
view.numbers.adapter = PhoneNumberAdapter()
|
||||
view.numbers.forwardTouches(view)
|
||||
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val item = getItem(adapterPosition)
|
||||
itemSelected.onNext(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val prevItem = if (position > 0) getItem(position - 1) else null
|
||||
val item = getItem(position)
|
||||
val view = holder.containerView
|
||||
|
||||
when (item) {
|
||||
is ComposeItem.New -> bindNew(view, item.value)
|
||||
is ComposeItem.Recent -> bindRecent(view, item.value, prevItem)
|
||||
is ComposeItem.Starred -> bindStarred(view, item.value, prevItem)
|
||||
is ComposeItem.Person -> bindPerson(view, item.value, prevItem)
|
||||
is ComposeItem.Group -> bindGroup(view, item.value, prevItem)
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindNew(view: View, contact: Contact) {
|
||||
view.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = false
|
||||
|
||||
view.avatar.contacts = listOf(Recipient(contact = contact))
|
||||
|
||||
view.title.text = contact.numbers.joinToString { it.address }
|
||||
|
||||
view.subtitle.isVisible = false
|
||||
|
||||
view.numbers.isVisible = false
|
||||
}
|
||||
|
||||
private fun bindRecent(view: View, conversation: Conversation, prev: ComposeItem?) {
|
||||
view.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = prev !is ComposeItem.Recent
|
||||
view.icon.setImageResource(R.drawable.ic_history_black_24dp)
|
||||
|
||||
view.avatar.contacts = conversation.recipients
|
||||
|
||||
view.title.text = conversation.getTitle()
|
||||
|
||||
view.subtitle.isVisible = conversation.recipients.size > 1 && conversation.name.isBlank()
|
||||
view.subtitle.text = conversation.recipients.joinToString(", ") { recipient ->
|
||||
recipient.contact?.name ?: recipient.address
|
||||
}
|
||||
|
||||
view.numbers.isVisible = conversation.recipients.size == 1
|
||||
(view.numbers.adapter as PhoneNumberAdapter).data = conversation.recipients
|
||||
.mapNotNull { recipient -> recipient.contact }
|
||||
.flatMap { contact -> contact.numbers }
|
||||
}
|
||||
|
||||
private fun bindStarred(view: View, contact: Contact, prev: ComposeItem?) {
|
||||
view.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = prev !is ComposeItem.Starred
|
||||
view.icon.setImageResource(R.drawable.ic_star_black_24dp)
|
||||
|
||||
view.avatar.contacts = listOf(Recipient(contact = contact))
|
||||
|
||||
view.title.text = contact.name
|
||||
|
||||
view.subtitle.isVisible = false
|
||||
|
||||
view.numbers.isVisible = true
|
||||
(view.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
}
|
||||
|
||||
private fun bindGroup(view: View, group: ContactGroup, prev: ComposeItem?) {
|
||||
view.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = prev !is ComposeItem.Group
|
||||
view.icon.setImageResource(R.drawable.ic_people_black_24dp)
|
||||
|
||||
view.avatar.contacts = group.contacts.map { contact -> Recipient(contact = contact) }
|
||||
|
||||
view.title.text = group.title
|
||||
|
||||
view.subtitle.isVisible = true
|
||||
view.subtitle.text = group.contacts.joinToString(", ") { it.name }
|
||||
|
||||
view.numbers.isVisible = false
|
||||
}
|
||||
|
||||
private fun bindPerson(view: View, contact: Contact, prev: ComposeItem?) {
|
||||
view.index.isVisible = true
|
||||
view.index.text = if (contact.name.getOrNull(0)?.isLetter() == true) contact.name[0].toString() else "#"
|
||||
view.index.isVisible = prev !is ComposeItem.Person ||
|
||||
(contact.name[0].isLetter() && !contact.name[0].equals(prev.value.name[0], ignoreCase = true)) ||
|
||||
(!contact.name[0].isLetter() && prev.value.name[0].isLetter())
|
||||
|
||||
view.icon.isVisible = false
|
||||
|
||||
view.avatar.contacts = listOf(Recipient(contact = contact))
|
||||
|
||||
view.title.text = contact.name
|
||||
|
||||
view.subtitle.isVisible = false
|
||||
|
||||
view.numbers.isVisible = true
|
||||
(view.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(old: ComposeItem, new: ComposeItem): Boolean = false
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import io.realm.RealmResults
|
||||
data class ComposeState(
|
||||
val hasError: Boolean = false,
|
||||
val editingMode: Boolean = false,
|
||||
val contacts: List<Contact> = ArrayList(),
|
||||
val composeItems: List<ComposeItem> = ArrayList(),
|
||||
val contactsVisible: Boolean = false,
|
||||
val selectedConversation: Long = 0,
|
||||
val selectedContacts: List<Contact> = ArrayList(),
|
||||
|
||||
@@ -33,7 +33,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val queryChangedIntent: Observable<CharSequence>
|
||||
val queryBackspaceIntent: Observable<*>
|
||||
val queryEditorActionIntent: Observable<Int>
|
||||
val chipSelectedIntent: Subject<Contact>
|
||||
val chipSelectedIntent: Subject<ComposeItem>
|
||||
val chipDeletedIntent: Subject<Contact>
|
||||
val menuReadyIntent: Observable<Unit>
|
||||
val optionsItemIntent: Observable<Int>
|
||||
|
||||
@@ -37,7 +37,9 @@ import com.moez.QKSMS.extensions.isImage
|
||||
import com.moez.QKSMS.extensions.isVideo
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.extensions.removeAccents
|
||||
import com.moez.QKSMS.feature.compose.ComposeItem.*
|
||||
import com.moez.QKSMS.filter.ContactFilter
|
||||
import com.moez.QKSMS.filter.ContactGroupFilter
|
||||
import com.moez.QKSMS.interactor.AddScheduledMessage
|
||||
import com.moez.QKSMS.interactor.CancelDelayedMessage
|
||||
import com.moez.QKSMS.interactor.ContactSync
|
||||
@@ -50,6 +52,7 @@ import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Attachments
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.ContactGroup
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.PhoneNumber
|
||||
@@ -89,6 +92,7 @@ class ComposeViewModel @Inject constructor(
|
||||
private val billingManager: BillingManager,
|
||||
private val cancelMessage: CancelDelayedMessage,
|
||||
private val contactFilter: ContactFilter,
|
||||
private val contactGroupFilter: ContactGroupFilter,
|
||||
private val contactsRepo: ContactRepository,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteMessages: DeleteMessages,
|
||||
@@ -110,13 +114,16 @@ class ComposeViewModel @Inject constructor(
|
||||
) {
|
||||
|
||||
private val attachments: Subject<List<Attachment>> = BehaviorSubject.createDefault(sharedAttachments)
|
||||
private val contacts: Observable<List<Contact>> by lazy { contactsRepo.getUnmanagedContacts().toObservable() }
|
||||
private val contactGroups: Observable<List<ContactGroup>> by lazy { contactsRepo.getUnmanagedContactGroups() }
|
||||
private val contacts: Observable<List<Contact>> by lazy { contactsRepo.getUnmanagedContacts() }
|
||||
private val contactsReducer: Subject<(List<Contact>) -> List<Contact>> = PublishSubject.create()
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
private val messages: Subject<List<Message>> = BehaviorSubject.create()
|
||||
private val recents: Observable<List<Conversation>> by lazy { conversationRepo.getUnmanagedConversations() }
|
||||
private val selectedContacts: Subject<List<Contact>> = BehaviorSubject.createDefault(listOf())
|
||||
private val searchResults: Subject<List<Message>> = BehaviorSubject.create()
|
||||
private val searchSelection: Subject<Long> = BehaviorSubject.createDefault(-1)
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
private val messages: Subject<List<Message>> = BehaviorSubject.create()
|
||||
private val starredContacts: Observable<List<Contact>> by lazy { contactsRepo.getUnmanagedContacts(true) }
|
||||
|
||||
init {
|
||||
val initialConversation = threadId.takeIf { it != 0L }
|
||||
@@ -250,31 +257,48 @@ class ComposeViewModel @Inject constructor(
|
||||
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
||||
// that have already been selected
|
||||
Observables
|
||||
.combineLatest(view.queryChangedIntent, contacts, selectedContacts) { query, contacts,
|
||||
selectedContacts ->
|
||||
.combineLatest(
|
||||
view.queryChangedIntent, recents, starredContacts, contactGroups, contacts, selectedContacts
|
||||
) { query, recents, starredContacts, contactGroups, contacts, selectedContacts ->
|
||||
val composeItems = mutableListOf<ComposeItem>()
|
||||
if (query.isBlank()) {
|
||||
composeItems += recents.map(::Recent)
|
||||
composeItems += starredContacts.map(::Starred)
|
||||
composeItems += contactGroups.map(::Group)
|
||||
composeItems += contacts.map(::Person)
|
||||
} else {
|
||||
// If the entry is a valid destination, allow it as a recipient
|
||||
if (phoneNumberUtils.isPossibleNumber(query.toString())) {
|
||||
val newAddress = phoneNumberUtils.formatNumber(query)
|
||||
val newContact = Contact(numbers = RealmList(PhoneNumber(address = newAddress)))
|
||||
composeItems += New(newContact)
|
||||
}
|
||||
|
||||
// Strip the accents from the query. This can be an expensive operation, so
|
||||
// cache the result instead of doing it for each contact
|
||||
val normalizedQuery = query.removeAccents()
|
||||
// Strip the accents from the query. This can be an expensive operation, so
|
||||
// cache the result instead of doing it for each contact
|
||||
val normalizedQuery = query.removeAccents()
|
||||
composeItems += starredContacts
|
||||
.filterNot { contact -> selectedContacts.contains(contact) }
|
||||
.filter { contact -> contactFilter.filter(contact, normalizedQuery) }
|
||||
.map(::Starred)
|
||||
|
||||
var filteredContacts = contacts
|
||||
.filterNot { contact -> selectedContacts.contains(contact) }
|
||||
.filter { contact -> contactFilter.filter(contact, normalizedQuery) }
|
||||
composeItems += contactGroups
|
||||
.filter { group -> contactGroupFilter.filter(group, normalizedQuery) }
|
||||
.map(::Group)
|
||||
|
||||
// If the entry is a valid destination, allow it as a recipient
|
||||
if (phoneNumberUtils.isPossibleNumber(query.toString())) {
|
||||
val newAddress = phoneNumberUtils.formatNumber(query)
|
||||
val newContact = Contact(numbers = RealmList(PhoneNumber(address = newAddress)))
|
||||
filteredContacts = listOf(newContact) + filteredContacts
|
||||
composeItems += contacts
|
||||
.filterNot { contact -> selectedContacts.contains(contact) }
|
||||
.filter { contact -> contactFilter.filter(contact, normalizedQuery) }
|
||||
.map(::Person)
|
||||
}
|
||||
|
||||
filteredContacts
|
||||
composeItems
|
||||
}
|
||||
.skipUntil(state.filter { state -> state.editingMode })
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { contacts -> newState { copy(contacts = contacts) } }
|
||||
.subscribe { items -> newState { copy(composeItems = items) } }
|
||||
|
||||
// Backspaces should delete the most recent contact if there's no text input
|
||||
// Close the activity if user presses back
|
||||
@@ -293,8 +317,8 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(state) { _, state -> state }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { state ->
|
||||
state.contacts.firstOrNull()?.let { contact ->
|
||||
contactsReducer.onNext { contacts -> contacts + contact }
|
||||
state.composeItems.firstOrNull()?.let { composeItem ->
|
||||
contactsReducer.onNext { contacts -> contacts + composeItem.getContacts() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,8 +327,10 @@ class ComposeViewModel @Inject constructor(
|
||||
view.chipDeletedIntent.doOnNext { contact ->
|
||||
contactsReducer.onNext { contacts -> contacts.filterNot { it == contact } }
|
||||
},
|
||||
view.chipSelectedIntent.doOnNext { contact ->
|
||||
contactsReducer.onNext { contacts -> contacts.toMutableList().apply { add(contact) } }
|
||||
view.chipSelectedIntent.doOnNext { composeItem ->
|
||||
contactsReducer.onNext { contacts ->
|
||||
contacts.toMutableList().apply { addAll(composeItem.getContacts()) }
|
||||
}
|
||||
})
|
||||
.skipUntil(state.filter { state -> state.editingMode })
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.contact_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ContactAdapter @Inject constructor() : QkAdapter<Contact>() {
|
||||
|
||||
val contactSelected: Subject<Contact> = PublishSubject.create()
|
||||
|
||||
private val numbersViewPool = RecyclerView.RecycledViewPool()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
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.setOnClickListener {
|
||||
val contact = getItem(adapterPosition)
|
||||
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.getOrNull(0)?.isLetter() == true) contact.name[0].toString() else "#"
|
||||
view.index.isVisible = prevContact == null ||
|
||||
(contact.name[0].isLetter() && !contact.name[0].equals(prevContact.name[0], ignoreCase = true)) ||
|
||||
(!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.addresses.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of the contact with only one phone number, so that the chips
|
||||
* view can still display the name/photo, and not get confused about which phone number to use
|
||||
*/
|
||||
private fun copyContact(contact: Contact, numberIndex: Int) = Contact().apply {
|
||||
lookupKey = contact.lookupKey
|
||||
name = contact.name
|
||||
numbers.add(contact.numbers[numberIndex])
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(old: Contact, new: Contact): Boolean = false
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user