forked from upstream-mirrors/quik
Only store necessary strings in AvatarView, instead of realm model (contact or recipient)
This commit is contained in:
@@ -26,9 +26,7 @@ import common.base.QkRealmAdapter
|
||||
import common.base.QkViewHolder
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.blocked_list_item.view.*
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.PhoneNumber
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedAdapter @Inject constructor(private val context: Context) : QkRealmAdapter<Conversation>() {
|
||||
@@ -45,10 +43,7 @@ class BlockedAdapter @Inject constructor(private val context: Context) : QkRealm
|
||||
|
||||
view.setOnClickListener { unblock.onNext(conversation.id) }
|
||||
|
||||
view.avatars.contacts = conversation.recipients.map { recipient ->
|
||||
recipient.contact ?: Contact().apply { numbers.add(PhoneNumber().apply { address = recipient.address }) }
|
||||
}
|
||||
|
||||
view.avatars.contacts = conversation.recipients
|
||||
view.title.text = conversation.getTitle()
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ class ChipsAdapter @Inject constructor(private val context: Context, private val
|
||||
val contact = getItem(position)
|
||||
val view = holder.itemView
|
||||
|
||||
view.avatar.contact = contact
|
||||
view.avatar.setContact(contact)
|
||||
|
||||
// If the contact's name is empty, try to display a phone number instead
|
||||
// The contacts provided here should only have one number
|
||||
|
||||
@@ -24,13 +24,13 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import common.base.QkAdapter
|
||||
import common.base.QkViewHolder
|
||||
import common.util.extensions.setVisible
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.contact_list_item.view.*
|
||||
import model.Contact
|
||||
import common.base.QkAdapter
|
||||
import common.base.QkViewHolder
|
||||
import javax.inject.Inject
|
||||
|
||||
class ContactAdapter @Inject constructor(private val context: Context) : QkAdapter<Contact>() {
|
||||
@@ -50,7 +50,7 @@ class ContactAdapter @Inject constructor(private val context: Context) : QkAdapt
|
||||
|
||||
view.primary.clicks().subscribe { contactSelected.onNext(copyContact(contact, 0)) }
|
||||
|
||||
view.avatar.contact = contact
|
||||
view.avatar.setContact(contact)
|
||||
view.name.text = contact.name
|
||||
view.name.setVisible(view.name.text.isNotEmpty())
|
||||
view.address.text = contact.numbers.first()?.address ?: ""
|
||||
|
||||
@@ -25,9 +25,9 @@ import android.widget.RelativeLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import injection.appComponent
|
||||
import common.util.Colors
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import injection.appComponent
|
||||
import kotlinx.android.synthetic.main.contact_chip_detailed.view.*
|
||||
import model.Contact
|
||||
import javax.inject.Inject
|
||||
@@ -58,7 +58,7 @@ class DetailedChipView(context: Context) : RelativeLayout(context) {
|
||||
}
|
||||
|
||||
fun setContact(contact: Contact) {
|
||||
avatar.contact = contact
|
||||
avatar.setContact(contact)
|
||||
name.text = contact.name
|
||||
info.text = contact.numbers.map { it.address }.toString()
|
||||
}
|
||||
|
||||
@@ -37,14 +37,12 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmRecyclerViewAdapter
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import model.PhoneNumber
|
||||
import model.Recipient
|
||||
import util.extensions.isImage
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
@@ -79,7 +77,7 @@ class MessagesAdapter @Inject constructor(
|
||||
updateData(value?.second)
|
||||
}
|
||||
|
||||
private val contactMap = HashMap<String, Contact>()
|
||||
private val contactMap = HashMap<String, Recipient?>()
|
||||
private val selected = HashMap<Long, Boolean>()
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
@@ -149,13 +147,12 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
val address = message.address
|
||||
if (contactMap[address]?.isValid != true) {
|
||||
contactMap[address] = data?.first?.recipients?.mapNotNull { it.contact } // Map the conversation to its contacts
|
||||
?.firstOrNull { it.numbers.any { PhoneNumberUtils.compare(it.address, address) } } // See if any of the phone numbers match
|
||||
?: Contact(numbers = RealmList(PhoneNumber(address = address))) // Fallback to a fake contact
|
||||
contactMap[address] = data?.first?.recipients
|
||||
?.firstOrNull { PhoneNumberUtils.compare(it.address, address) } // See if any of the phone numbers match
|
||||
}
|
||||
|
||||
view.avatar.threadId = data?.first?.id ?: 0
|
||||
view.avatar.contact = contactMap[address]
|
||||
view.avatar.setContact(contactMap[address])
|
||||
}
|
||||
|
||||
private fun bindStatus(view: View, position: Int) {
|
||||
@@ -169,7 +166,7 @@ class MessagesAdapter @Inject constructor(
|
||||
message.isSending() -> context.getString(R.string.message_status_sending)
|
||||
message.isDelivered() -> context.getString(R.string.message_status_delivered, timestamp)
|
||||
message.isFailedMessage() -> context.getString(R.string.message_status_failed)
|
||||
!message.isMe() && data?.first?.recipients?.size ?: 0 > 1 -> "${contactMap[message.address]?.name} • $timestamp"
|
||||
!message.isMe() && data?.first?.recipients?.size ?: 0 > 1 -> "${contactMap[message.address]?.getDisplayName()} • $timestamp"
|
||||
else -> timestamp
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class ConversationRecipientAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
view.avatar.threadId = threadId
|
||||
view.avatar.contact = recipient.contact
|
||||
view.avatar.setContact(recipient)
|
||||
|
||||
view.name.text = recipient.contact?.name ?: recipient.address
|
||||
|
||||
|
||||
@@ -32,9 +32,7 @@ import common.util.DateFormatter
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.conversation_list_item.view.*
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.PhoneNumber
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationsAdapter @Inject constructor(
|
||||
@@ -75,9 +73,7 @@ class ConversationsAdapter @Inject constructor(
|
||||
view.clicks().subscribe { clicks.onNext(conversation.id) }
|
||||
view.longClicks().subscribe { longClicks.onNext(conversation.id) }
|
||||
|
||||
view.avatars.contacts = conversation.recipients.map { recipient ->
|
||||
recipient.contact ?: Contact().apply { numbers.add(PhoneNumber().apply { address = recipient.address }) }
|
||||
}
|
||||
view.avatars.contacts = conversation.recipients
|
||||
view.title.text = conversation.getTitle()
|
||||
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
||||
view.snippet.text = if (conversation.me) "You: ${conversation.snippet}" else conversation.snippet
|
||||
|
||||
Reference in New Issue
Block a user