Rename classes

This commit is contained in:
Benoit Marty 2020-07-09 09:55:33 +02:00
parent f51568b331
commit cc4603b61f
7 changed files with 30 additions and 32 deletions

View file

@ -28,8 +28,8 @@ class ContactsDataSource @Inject constructor(
) { ) {
@WorkerThread @WorkerThread
fun getContacts(): List<ContactModel> { fun getContacts(): List<MappedContact> {
val result = mutableListOf<ContactModel>() val result = mutableListOf<MappedContact>()
val contentResolver = context.contentResolver val contentResolver = context.contentResolver
contentResolver.query( contentResolver.query(
@ -56,7 +56,7 @@ class ContactsDataSource @Inject constructor(
val id = cursor.getLong(ContactsContract.Contacts._ID) ?: continue val id = cursor.getLong(ContactsContract.Contacts._ID) ?: continue
val displayName = cursor.getString(ContactsContract.Contacts.DISPLAY_NAME) ?: continue val displayName = cursor.getString(ContactsContract.Contacts.DISPLAY_NAME) ?: continue
val currentContact = ContactModelBuilder( val currentContact = MappedContactBuilder(
id = id, id = id,
displayName = displayName displayName = displayName
) )
@ -108,7 +108,7 @@ class ContactsDataSource @Inject constructor(
} }
} }
result.add(currentContact.toContactModel()) result.add(currentContact.build())
} }
} }
} }

View file

@ -18,18 +18,16 @@ package im.vector.riotx.core.contacts
import android.net.Uri import android.net.Uri
/* TODO Rename to MxContact? */ class MappedContactBuilder(
class ContactModelBuilder(
val id: Long, val id: Long,
val displayName: String) { val displayName: String
) {
var photoURI: Uri? = null var photoURI: Uri? = null
val msisdns = mutableListOf<MappedMsisdn>() val msisdns = mutableListOf<MappedMsisdn>()
val emails = mutableListOf<MappedEmail>() val emails = mutableListOf<MappedEmail>()
fun toContactModel(): ContactModel { fun build(): MappedContact {
return ContactModel( return MappedContact(
id = id, id = id,
displayName = displayName, displayName = displayName,
photoURI = photoURI, photoURI = photoURI,
@ -39,7 +37,7 @@ class ContactModelBuilder(
} }
} }
data class ContactModel( data class MappedContact(
val id: Long, val id: Long,
val displayName: String, val displayName: String,
val photoURI: Uri? = null, val photoURI: Uri? = null,

View file

@ -30,7 +30,7 @@ import com.bumptech.glide.request.target.DrawableImageViewTarget
import com.bumptech.glide.request.target.Target import com.bumptech.glide.request.target.Target
import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.matrix.android.api.session.content.ContentUrlResolver
import im.vector.matrix.android.api.util.MatrixItem 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.di.ActiveSessionHolder
import im.vector.riotx.core.glide.GlideApp import im.vector.riotx.core.glide.GlideApp
import im.vector.riotx.core.glide.GlideRequest import im.vector.riotx.core.glide.GlideRequest
@ -65,17 +65,17 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active
} }
@UiThread @UiThread
fun render(contactModel: ContactModel, imageView: ImageView) { fun render(mappedContact: MappedContact, imageView: ImageView) {
// Create a Fake MatrixItem, for the placeholder // Create a Fake MatrixItem, for the placeholder
val matrixItem = MatrixItem.UserItem( val matrixItem = MatrixItem.UserItem(
// Need an id starting with @ // Need an id starting with @
id = "@${contactModel.displayName}", id = "@${mappedContact.displayName}",
displayName = contactModel.displayName displayName = mappedContact.displayName
) )
val placeholder = getPlaceholderDrawable(imageView.context, matrixItem) val placeholder = getPlaceholderDrawable(imageView.context, matrixItem)
GlideApp.with(imageView) GlideApp.with(imageView)
.load(contactModel.photoURI) .load(mappedContact.photoURI)
.apply(RequestOptions.circleCropTransform()) .apply(RequestOptions.circleCropTransform())
.placeholder(placeholder) .placeholder(placeholder)
.into(imageView) .into(imageView)

View file

@ -21,7 +21,7 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.riotx.R 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.VectorEpoxyHolder
import im.vector.riotx.core.epoxy.VectorEpoxyModel import im.vector.riotx.core.epoxy.VectorEpoxyModel
import im.vector.riotx.features.home.AvatarRenderer import im.vector.riotx.features.home.AvatarRenderer
@ -30,13 +30,13 @@ import im.vector.riotx.features.home.AvatarRenderer
abstract class ContactItem : VectorEpoxyModel<ContactItem.Holder>() { abstract class ContactItem : VectorEpoxyModel<ContactItem.Holder>() {
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer @EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var contact: ContactModel @EpoxyAttribute lateinit var mappedContact: MappedContact
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
// If name is empty, use userId as name and force it being centered // If name is empty, use userId as name and force it being centered
holder.nameView.text = contact.displayName holder.nameView.text = mappedContact.displayName
avatarRenderer.render(contact, holder.avatarImageView) avatarRenderer.render(mappedContact, holder.avatarImageView)
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {

View file

@ -23,7 +23,7 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.Uninitialized
import im.vector.matrix.android.api.session.identity.ThreePid import im.vector.matrix.android.api.session.identity.ThreePid
import im.vector.riotx.R 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.errorWithRetryItem
import im.vector.riotx.core.epoxy.loadingItem import im.vector.riotx.core.epoxy.loadingItem
import im.vector.riotx.core.epoxy.noResultItem import im.vector.riotx.core.epoxy.noResultItem
@ -74,7 +74,7 @@ class PhoneBookController @Inject constructor(
} }
} }
private fun renderSuccess(mappedContacts: List<ContactModel>, private fun renderSuccess(mappedContacts: List<MappedContact>,
hasSearch: Boolean, hasSearch: Boolean,
onlyBoundContacts: Boolean) { onlyBoundContacts: Boolean) {
if (mappedContacts.isEmpty()) { if (mappedContacts.isEmpty()) {
@ -84,11 +84,11 @@ class PhoneBookController @Inject constructor(
} }
} }
private fun renderContacts(mappedContacts: List<ContactModel>, onlyBoundContacts: Boolean) { private fun renderContacts(mappedContacts: List<MappedContact>, onlyBoundContacts: Boolean) {
for (mappedContact in mappedContacts) { for (mappedContact in mappedContacts) {
contactItem { contactItem {
id(mappedContact.id) id(mappedContact.id)
contact(mappedContact) mappedContact(mappedContact)
avatarRenderer(avatarRenderer) avatarRenderer(avatarRenderer)
} }
mappedContact.emails mappedContact.emails

View file

@ -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.Session
import im.vector.matrix.android.api.session.identity.FoundThreePid import im.vector.matrix.android.api.session.identity.FoundThreePid
import im.vector.matrix.android.api.session.identity.ThreePid 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.ContactsDataSource
import im.vector.riotx.core.contacts.MappedContact
import im.vector.riotx.core.extensions.exhaustive import im.vector.riotx.core.extensions.exhaustive
import im.vector.riotx.core.platform.EmptyViewEvents import im.vector.riotx.core.platform.EmptyViewEvents
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
@ -71,8 +71,8 @@ class PhoneBookViewModel @AssistedInject constructor(@Assisted
} }
} }
private var allContacts: List<ContactModel> = emptyList() private var allContacts: List<MappedContact> = emptyList()
private var mappedContacts: List<ContactModel> = emptyList() private var mappedContacts: List<MappedContact> = emptyList()
init { init {
loadContacts() loadContacts()
@ -104,7 +104,7 @@ class PhoneBookViewModel @AssistedInject constructor(@Assisted
} }
} }
private fun performLookup(data: List<ContactModel>) { private fun performLookup(data: List<MappedContact>) {
viewModelScope.launch { viewModelScope.launch {
val threePids = data.flatMap { contact -> val threePids = data.flatMap { contact ->
contact.emails.map { ThreePid.Email(it.email) } + contact.emails.map { ThreePid.Email(it.email) } +

View file

@ -19,17 +19,17 @@ package im.vector.riotx.features.userdirectory
import com.airbnb.mvrx.Async import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxState
import im.vector.riotx.core.contacts.ContactModel import im.vector.riotx.core.contacts.MappedContact
data class PhoneBookViewState( data class PhoneBookViewState(
// All the contacts on the phone // All the contacts on the phone
val mappedContacts: Async<List<ContactModel>> = Loading(), val mappedContacts: Async<List<MappedContact>> = Loading(),
// Use to filter contacts by display name // Use to filter contacts by display name
val searchTerm: String = "", val searchTerm: String = "",
// Tru to display only bound contacts with their bound 2pid // Tru to display only bound contacts with their bound 2pid
val onlyBoundContacts: Boolean = false, val onlyBoundContacts: Boolean = false,
// All contacts, filtered by searchTerm and onlyBoundContacts // All contacts, filtered by searchTerm and onlyBoundContacts
val filteredMappedContacts: List<ContactModel> = emptyList(), val filteredMappedContacts: List<MappedContact> = emptyList(),
// True when the identity service has return some data // True when the identity service has return some data
val isBoundRetrieved: Boolean = false val isBoundRetrieved: Boolean = false
) : MvRxState ) : MvRxState