diff --git a/vector/src/main/java/im/vector/riotx/core/contacts/ContactsDataSource.kt b/vector/src/main/java/im/vector/riotx/core/contacts/ContactsDataSource.kt index 2160216d5d..b7762dd135 100644 --- a/vector/src/main/java/im/vector/riotx/core/contacts/ContactsDataSource.kt +++ b/vector/src/main/java/im/vector/riotx/core/contacts/ContactsDataSource.kt @@ -28,8 +28,8 @@ class ContactsDataSource @Inject constructor( ) { @WorkerThread - fun getContacts(): List { - val result = mutableListOf() + fun getContacts(): List { + val result = mutableListOf() val contentResolver = context.contentResolver contentResolver.query( @@ -56,7 +56,7 @@ class ContactsDataSource @Inject constructor( val id = cursor.getLong(ContactsContract.Contacts._ID) ?: continue val displayName = cursor.getString(ContactsContract.Contacts.DISPLAY_NAME) ?: continue - val currentContact = ContactModelBuilder( + val currentContact = MappedContactBuilder( id = id, displayName = displayName ) @@ -108,7 +108,7 @@ class ContactsDataSource @Inject constructor( } } - result.add(currentContact.toContactModel()) + result.add(currentContact.build()) } } } diff --git a/vector/src/main/java/im/vector/riotx/core/contacts/ContactModel.kt b/vector/src/main/java/im/vector/riotx/core/contacts/MappedContact.kt similarity index 87% rename from vector/src/main/java/im/vector/riotx/core/contacts/ContactModel.kt rename to vector/src/main/java/im/vector/riotx/core/contacts/MappedContact.kt index 589c3030c3..c89a3d4b01 100644 --- a/vector/src/main/java/im/vector/riotx/core/contacts/ContactModel.kt +++ b/vector/src/main/java/im/vector/riotx/core/contacts/MappedContact.kt @@ -18,18 +18,16 @@ package im.vector.riotx.core.contacts import android.net.Uri -/* TODO Rename to MxContact? */ - -class ContactModelBuilder( +class MappedContactBuilder( val id: Long, - val displayName: String) { - + val displayName: String +) { var photoURI: Uri? = null val msisdns = mutableListOf() val emails = mutableListOf() - fun toContactModel(): ContactModel { - return ContactModel( + fun build(): MappedContact { + return MappedContact( id = id, displayName = displayName, photoURI = photoURI, @@ -39,7 +37,7 @@ class ContactModelBuilder( } } -data class ContactModel( +data class MappedContact( val id: Long, val displayName: String, val photoURI: Uri? = null, diff --git a/vector/src/main/java/im/vector/riotx/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/riotx/features/home/AvatarRenderer.kt index e0d41ca445..3bf2f13d48 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/AvatarRenderer.kt @@ -30,7 +30,7 @@ import com.bumptech.glide.request.target.DrawableImageViewTarget import com.bumptech.glide.request.target.Target import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.matrix.android.api.util.MatrixItem -import im.vector.riotx.core.contacts.ContactModel +import im.vector.riotx.core.contacts.MappedContact import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.glide.GlideApp import im.vector.riotx.core.glide.GlideRequest @@ -65,17 +65,17 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active } @UiThread - fun render(contactModel: ContactModel, imageView: ImageView) { + fun render(mappedContact: MappedContact, imageView: ImageView) { // Create a Fake MatrixItem, for the placeholder val matrixItem = MatrixItem.UserItem( // Need an id starting with @ - id = "@${contactModel.displayName}", - displayName = contactModel.displayName + id = "@${mappedContact.displayName}", + displayName = mappedContact.displayName ) val placeholder = getPlaceholderDrawable(imageView.context, matrixItem) GlideApp.with(imageView) - .load(contactModel.photoURI) + .load(mappedContact.photoURI) .apply(RequestOptions.circleCropTransform()) .placeholder(placeholder) .into(imageView) diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/ContactItem.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/ContactItem.kt index 67d762b4b2..157ce9c7f6 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/ContactItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/ContactItem.kt @@ -21,7 +21,7 @@ import android.widget.TextView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R -import im.vector.riotx.core.contacts.ContactModel +import im.vector.riotx.core.contacts.MappedContact import im.vector.riotx.core.epoxy.VectorEpoxyHolder import im.vector.riotx.core.epoxy.VectorEpoxyModel import im.vector.riotx.features.home.AvatarRenderer @@ -30,13 +30,13 @@ import im.vector.riotx.features.home.AvatarRenderer abstract class ContactItem : VectorEpoxyModel() { @EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer - @EpoxyAttribute lateinit var contact: ContactModel + @EpoxyAttribute lateinit var mappedContact: MappedContact override fun bind(holder: Holder) { super.bind(holder) // If name is empty, use userId as name and force it being centered - holder.nameView.text = contact.displayName - avatarRenderer.render(contact, holder.avatarImageView) + holder.nameView.text = mappedContact.displayName + avatarRenderer.render(mappedContact, holder.avatarImageView) } class Holder : VectorEpoxyHolder() { diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookController.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookController.kt index e4266183df..4f33a4fa8f 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookController.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookController.kt @@ -23,7 +23,7 @@ import com.airbnb.mvrx.Success import com.airbnb.mvrx.Uninitialized import im.vector.matrix.android.api.session.identity.ThreePid import im.vector.riotx.R -import im.vector.riotx.core.contacts.ContactModel +import im.vector.riotx.core.contacts.MappedContact import im.vector.riotx.core.epoxy.errorWithRetryItem import im.vector.riotx.core.epoxy.loadingItem import im.vector.riotx.core.epoxy.noResultItem @@ -74,7 +74,7 @@ class PhoneBookController @Inject constructor( } } - private fun renderSuccess(mappedContacts: List, + private fun renderSuccess(mappedContacts: List, hasSearch: Boolean, onlyBoundContacts: Boolean) { if (mappedContacts.isEmpty()) { @@ -84,11 +84,11 @@ class PhoneBookController @Inject constructor( } } - private fun renderContacts(mappedContacts: List, onlyBoundContacts: Boolean) { + private fun renderContacts(mappedContacts: List, onlyBoundContacts: Boolean) { for (mappedContact in mappedContacts) { contactItem { id(mappedContact.id) - contact(mappedContact) + mappedContact(mappedContact) avatarRenderer(avatarRenderer) } mappedContact.emails diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewModel.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewModel.kt index d78932ccf2..d76c36847d 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewModel.kt @@ -30,8 +30,8 @@ import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.identity.FoundThreePid import im.vector.matrix.android.api.session.identity.ThreePid -import im.vector.riotx.core.contacts.ContactModel import im.vector.riotx.core.contacts.ContactsDataSource +import im.vector.riotx.core.contacts.MappedContact import im.vector.riotx.core.extensions.exhaustive import im.vector.riotx.core.platform.EmptyViewEvents import im.vector.riotx.core.platform.VectorViewModel @@ -71,8 +71,8 @@ class PhoneBookViewModel @AssistedInject constructor(@Assisted } } - private var allContacts: List = emptyList() - private var mappedContacts: List = emptyList() + private var allContacts: List = emptyList() + private var mappedContacts: List = emptyList() init { loadContacts() @@ -104,7 +104,7 @@ class PhoneBookViewModel @AssistedInject constructor(@Assisted } } - private fun performLookup(data: List) { + private fun performLookup(data: List) { viewModelScope.launch { val threePids = data.flatMap { contact -> contact.emails.map { ThreePid.Email(it.email) } + diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewState.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewState.kt index bfca2bc6b0..60603b8785 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/PhoneBookViewState.kt @@ -19,17 +19,17 @@ package im.vector.riotx.features.userdirectory import com.airbnb.mvrx.Async import com.airbnb.mvrx.Loading import com.airbnb.mvrx.MvRxState -import im.vector.riotx.core.contacts.ContactModel +import im.vector.riotx.core.contacts.MappedContact data class PhoneBookViewState( // All the contacts on the phone - val mappedContacts: Async> = Loading(), + val mappedContacts: Async> = Loading(), // Use to filter contacts by display name val searchTerm: String = "", // Tru to display only bound contacts with their bound 2pid val onlyBoundContacts: Boolean = false, // All contacts, filtered by searchTerm and onlyBoundContacts - val filteredMappedContacts: List = emptyList(), + val filteredMappedContacts: List = emptyList(), // True when the identity service has return some data val isBoundRetrieved: Boolean = false ) : MvRxState