forked from upstream-mirrors/quik
Correctly use ContainerView with ViewHolder
This commit is contained in:
@@ -33,7 +33,8 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.attachment_contact_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.attachment_contact_list_item.*
|
||||
import kotlinx.android.synthetic.main.attachment_image_list_item.*
|
||||
import kotlinx.android.synthetic.main.attachment_image_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -69,18 +70,17 @@ class AttachmentAdapter @Inject constructor(
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val attachment = getItem(position)
|
||||
val view = holder.containerView
|
||||
|
||||
when (attachment) {
|
||||
is Attachment.Image -> Glide.with(context)
|
||||
.load(attachment.getUri())
|
||||
.into(view.thumbnail)
|
||||
.into(holder.thumbnail)
|
||||
|
||||
is Attachment.Contact -> Observable.just(attachment.vCard)
|
||||
.mapNotNull { vCard -> Ezvcard.parse(vCard).first() }
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { vcard -> view.name?.text = vcard.formattedName.value }
|
||||
.subscribe { vcard -> holder.name?.text = vcard.formattedName.value }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,15 @@ import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.attachments
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.body
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.sim
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.simIndex
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.status
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.timestamp
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import kotlinx.android.synthetic.main.message_list_item_out.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
@@ -175,11 +183,10 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val message = getItem(position) ?: return
|
||||
val previous = if (position == 0) null else getItem(position - 1)
|
||||
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
||||
val view = viewHolder.containerView
|
||||
|
||||
val theme = when (message.isOutgoingMessage()) {
|
||||
true -> colors.theme()
|
||||
@@ -187,10 +194,10 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
// Update the selected state
|
||||
view.isActivated = isSelected(message.id) || highlight == message.id
|
||||
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
|
||||
|
||||
// Bind the cancel view
|
||||
view.findViewById<ProgressBar>(R.id.cancel)?.let { cancel ->
|
||||
holder.cancel?.let { cancel ->
|
||||
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
||||
cancel.setVisible(isCancellable)
|
||||
cancel.clicks().subscribe { cancelSending.onNext(message.id) }
|
||||
@@ -212,31 +219,31 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
// Bind the message status
|
||||
bindStatus(viewHolder, message, next)
|
||||
bindStatus(holder, message, next)
|
||||
|
||||
// Bind the timestamp
|
||||
val timeSincePrevious = TimeUnit.MILLISECONDS.toMinutes(message.date - (previous?.date ?: 0))
|
||||
val simIndex = subs.takeIf { it.size > 1 }?.indexOfFirst { it.subscriptionId == message.subId } ?: -1
|
||||
|
||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
view.simIndex.text = "${simIndex + 1}"
|
||||
holder.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
holder.simIndex.text = "${simIndex + 1}"
|
||||
|
||||
view.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD
|
||||
holder.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD
|
||||
|| message.subId != previous?.subId && simIndex != -1)
|
||||
view.sim.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
view.simIndex.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
holder.sim.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
holder.simIndex.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
|
||||
// Bind the grouping
|
||||
val media = message.parts.filter { !it.isSmil() && !it.isText() }
|
||||
view.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
||||
holder.containerView.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
||||
|
||||
// Bind the avatar and bubble colour
|
||||
if (!message.isMe()) {
|
||||
view.avatar.setRecipient(contactCache[message.address])
|
||||
view.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||
holder.avatar.setRecipient(contactCache[message.address])
|
||||
holder.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||
|
||||
view.body.setTextColor(theme.textPrimary)
|
||||
view.body.setBackgroundTint(theme.theme)
|
||||
holder.body.setTextColor(theme.textPrimary)
|
||||
holder.body.setBackgroundTint(theme.theme)
|
||||
}
|
||||
|
||||
// Bind the body text
|
||||
@@ -262,31 +269,29 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
val emojiOnly = messageText.isNotBlank() && messageText.matches(EMOJI_REGEX)
|
||||
textViewStyler.setTextSize(view.body, when (emojiOnly) {
|
||||
textViewStyler.setTextSize(holder.body, when (emojiOnly) {
|
||||
true -> TextViewStyler.SIZE_EMOJI
|
||||
false -> TextViewStyler.SIZE_PRIMARY
|
||||
})
|
||||
|
||||
view.body.text = messageText
|
||||
view.body.setVisible(message.isSms() || messageText.isNotBlank())
|
||||
view.body.setBackgroundResource(getBubble(
|
||||
holder.body.text = messageText
|
||||
holder.body.setVisible(message.isSms() || messageText.isNotBlank())
|
||||
holder.body.setBackgroundResource(getBubble(
|
||||
emojiOnly = emojiOnly,
|
||||
canGroupWithPrevious = canGroup(message, previous) || media.isNotEmpty(),
|
||||
canGroupWithNext = canGroup(message, next),
|
||||
isMe = message.isMe()))
|
||||
|
||||
// Bind the attachments
|
||||
val partsAdapter = view.attachments.adapter as PartsAdapter
|
||||
val partsAdapter = holder.attachments.adapter as PartsAdapter
|
||||
partsAdapter.theme = theme
|
||||
partsAdapter.setData(message, previous, next, view)
|
||||
partsAdapter.setData(message, previous, next, holder)
|
||||
}
|
||||
|
||||
private fun bindStatus(viewHolder: QkViewHolder, message: Message, next: Message?) {
|
||||
val view = viewHolder.containerView
|
||||
|
||||
private fun bindStatus(holder: QkViewHolder, message: Message, next: Message?) {
|
||||
val age = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - message.date)
|
||||
|
||||
view.status.text = when {
|
||||
holder.status.text = when {
|
||||
message.isSending() -> context.getString(R.string.message_status_sending)
|
||||
message.isDelivered() -> context.getString(R.string.message_status_delivered,
|
||||
dateFormatter.getTimestamp(message.dateSent))
|
||||
@@ -300,7 +305,7 @@ class MessagesAdapter @Inject constructor(
|
||||
else -> dateFormatter.getTimestamp(message.date)
|
||||
}
|
||||
|
||||
view.status.setVisible(when {
|
||||
holder.status.setVisible(when {
|
||||
expanded[message.id] == true -> true
|
||||
message.isSending() -> true
|
||||
message.isFailedMessage() -> true
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.contact_chip.*
|
||||
import kotlinx.android.synthetic.main.contact_chip.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Chip>() {
|
||||
@@ -59,10 +58,9 @@ class ChipsAdapter @Inject constructor() : QkAdapter<Chip>() {
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val chip = getItem(position)
|
||||
val view = holder.containerView
|
||||
|
||||
view.avatar.setRecipient(Recipient(id = -1, contact = chip.contact))
|
||||
view.name.text = chip.contact?.name?.takeIf { it.isNotBlank() } ?: chip.address
|
||||
holder.avatar.setRecipient(Recipient(id = -1, contact = chip.contact))
|
||||
holder.name.text = chip.contact?.name?.takeIf { it.isNotBlank() } ?: chip.address
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+51
-52
@@ -19,7 +19,6 @@
|
||||
package com.moez.QKSMS.feature.compose.editing
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -39,6 +38,7 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.contact_list_item.*
|
||||
import kotlinx.android.synthetic.main.contact_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -85,101 +85,100 @@ class ComposeItemAdapter @Inject constructor(
|
||||
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)
|
||||
is ComposeItem.New -> bindNew(holder, item.value)
|
||||
is ComposeItem.Recent -> bindRecent(holder, item.value, prevItem)
|
||||
is ComposeItem.Starred -> bindStarred(holder, item.value, prevItem)
|
||||
is ComposeItem.Person -> bindPerson(holder, item.value, prevItem)
|
||||
is ComposeItem.Group -> bindGroup(holder, item.value, prevItem)
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindNew(view: View, contact: Contact) {
|
||||
view.index.isVisible = false
|
||||
private fun bindNew(holder: QkViewHolder, contact: Contact) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = false
|
||||
holder.icon.isVisible = false
|
||||
|
||||
view.avatar.recipients = listOf(createRecipient(contact))
|
||||
holder.avatar.recipients = listOf(createRecipient(contact))
|
||||
|
||||
view.title.text = contact.numbers.joinToString { it.address }
|
||||
holder.title.text = contact.numbers.joinToString { it.address }
|
||||
|
||||
view.subtitle.isVisible = false
|
||||
holder.subtitle.isVisible = false
|
||||
|
||||
view.numbers.isVisible = false
|
||||
holder.numbers.isVisible = false
|
||||
}
|
||||
|
||||
private fun bindRecent(view: View, conversation: Conversation, prev: ComposeItem?) {
|
||||
view.index.isVisible = false
|
||||
private fun bindRecent(holder: QkViewHolder, conversation: Conversation, prev: ComposeItem?) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = prev !is ComposeItem.Recent
|
||||
view.icon.setImageResource(R.drawable.ic_history_black_24dp)
|
||||
holder.icon.isVisible = prev !is ComposeItem.Recent
|
||||
holder.icon.setImageResource(R.drawable.ic_history_black_24dp)
|
||||
|
||||
view.avatar.recipients = conversation.recipients
|
||||
holder.avatar.recipients = conversation.recipients
|
||||
|
||||
view.title.text = conversation.getTitle()
|
||||
holder.title.text = conversation.getTitle()
|
||||
|
||||
view.subtitle.isVisible = conversation.recipients.size > 1 && conversation.name.isBlank()
|
||||
view.subtitle.text = conversation.recipients.joinToString(", ") { recipient ->
|
||||
holder.subtitle.isVisible = conversation.recipients.size > 1 && conversation.name.isBlank()
|
||||
holder.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
|
||||
holder.numbers.isVisible = conversation.recipients.size == 1
|
||||
(holder.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
|
||||
private fun bindStarred(holder: QkViewHolder, contact: Contact, prev: ComposeItem?) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = prev !is ComposeItem.Starred
|
||||
view.icon.setImageResource(R.drawable.ic_star_black_24dp)
|
||||
holder.icon.isVisible = prev !is ComposeItem.Starred
|
||||
holder.icon.setImageResource(R.drawable.ic_star_black_24dp)
|
||||
|
||||
view.avatar.recipients = listOf(createRecipient(contact))
|
||||
holder.avatar.recipients = listOf(createRecipient(contact))
|
||||
|
||||
view.title.text = contact.name
|
||||
holder.title.text = contact.name
|
||||
|
||||
view.subtitle.isVisible = false
|
||||
holder.subtitle.isVisible = false
|
||||
|
||||
view.numbers.isVisible = true
|
||||
(view.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
holder.numbers.isVisible = true
|
||||
(holder.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
}
|
||||
|
||||
private fun bindGroup(view: View, group: ContactGroup, prev: ComposeItem?) {
|
||||
view.index.isVisible = false
|
||||
private fun bindGroup(holder: QkViewHolder, group: ContactGroup, prev: ComposeItem?) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
view.icon.isVisible = prev !is ComposeItem.Group
|
||||
view.icon.setImageResource(R.drawable.ic_people_black_24dp)
|
||||
holder.icon.isVisible = prev !is ComposeItem.Group
|
||||
holder.icon.setImageResource(R.drawable.ic_people_black_24dp)
|
||||
|
||||
view.avatar.recipients = group.contacts.map(::createRecipient)
|
||||
holder.avatar.recipients = group.contacts.map(::createRecipient)
|
||||
|
||||
view.title.text = group.title
|
||||
holder.title.text = group.title
|
||||
|
||||
view.subtitle.isVisible = true
|
||||
view.subtitle.text = group.contacts.joinToString(", ") { it.name }
|
||||
holder.subtitle.isVisible = true
|
||||
holder.subtitle.text = group.contacts.joinToString(", ") { it.name }
|
||||
|
||||
view.numbers.isVisible = false
|
||||
holder.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 ||
|
||||
private fun bindPerson(holder: QkViewHolder, contact: Contact, prev: ComposeItem?) {
|
||||
holder.index.isVisible = true
|
||||
holder.index.text = if (contact.name.getOrNull(0)?.isLetter() == true) contact.name[0].toString() else "#"
|
||||
holder.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
|
||||
holder.icon.isVisible = false
|
||||
|
||||
view.avatar.recipients = listOf(createRecipient(contact))
|
||||
holder.avatar.recipients = listOf(createRecipient(contact))
|
||||
|
||||
view.title.text = contact.name
|
||||
holder.title.text = contact.name
|
||||
|
||||
view.subtitle.isVisible = false
|
||||
holder.subtitle.isVisible = false
|
||||
|
||||
view.numbers.isVisible = true
|
||||
(view.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
holder.numbers.isVisible = true
|
||||
(holder.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
}
|
||||
|
||||
private fun createRecipient(contact: Contact): Recipient {
|
||||
|
||||
+3
-4
@@ -24,7 +24,7 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.model.PhoneNumber
|
||||
import kotlinx.android.synthetic.main.contact_number_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.contact_number_list_item.*
|
||||
|
||||
class PhoneNumberAdapter : QkAdapter<PhoneNumber>() {
|
||||
|
||||
@@ -36,10 +36,9 @@ class PhoneNumberAdapter : QkAdapter<PhoneNumber>() {
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val number = getItem(position)
|
||||
val view = holder.containerView
|
||||
|
||||
view.address.text = number.address
|
||||
view.type.text = number.type
|
||||
holder.address.text = number.address
|
||||
holder.type.text = number.type
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(old: PhoneNumber, new: PhoneNumber): Boolean {
|
||||
|
||||
@@ -21,9 +21,9 @@ package com.moez.QKSMS.feature.compose.part
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
@@ -34,7 +34,7 @@ import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.mms_file_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.mms_file_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class FileBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
@@ -47,16 +47,16 @@ class FileBinder @Inject constructor(colors: Colors, private val context: Contex
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun bindPart(
|
||||
view: View,
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
.let(view.fileBackground::setBackgroundResource)
|
||||
.let(holder.fileBackground::setBackgroundResource)
|
||||
|
||||
view.setOnClickListener { clicks.onNext(part.id) }
|
||||
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
|
||||
|
||||
Observable.just(part.getUri())
|
||||
.map(context.contentResolver::openInputStream)
|
||||
@@ -71,23 +71,23 @@ class FileBinder @Inject constructor(colors: Colors, private val context: Contex
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { size -> view.size.text = size }
|
||||
.subscribe { size -> holder.size.text = size }
|
||||
|
||||
view.filename.text = part.name
|
||||
holder.filename.text = part.name
|
||||
|
||||
val params = view.fileBackground.layoutParams as FrameLayout.LayoutParams
|
||||
val params = holder.fileBackground.layoutParams as FrameLayout.LayoutParams
|
||||
if (!message.isMe()) {
|
||||
view.fileBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
view.fileBackground.setBackgroundTint(theme.theme)
|
||||
view.icon.setTint(theme.textPrimary)
|
||||
view.filename.setTextColor(theme.textPrimary)
|
||||
view.size.setTextColor(theme.textTertiary)
|
||||
holder.fileBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.fileBackground.setBackgroundTint(theme.theme)
|
||||
holder.icon.setTint(theme.textPrimary)
|
||||
holder.filename.setTextColor(theme.textPrimary)
|
||||
holder.size.setTextColor(theme.textTertiary)
|
||||
} else {
|
||||
view.fileBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
view.fileBackground.setBackgroundTint(view.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
view.icon.setTint(view.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
view.filename.setTextColor(view.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
view.size.setTextColor(view.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
holder.fileBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.fileBackground.setBackgroundTint(holder.containerView.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.icon.setTint(holder.containerView.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.filename.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
holder.size.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.widget.BubbleImageView
|
||||
@@ -29,7 +29,7 @@ import com.moez.QKSMS.extensions.isVideo
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.mms_preview_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.mms_preview_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class MediaBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
@@ -40,23 +40,23 @@ class MediaBinder @Inject constructor(colors: Colors, private val context: Conte
|
||||
override fun canBindPart(part: MmsPart) = part.isImage() || part.isVideo()
|
||||
|
||||
override fun bindPart(
|
||||
view: View,
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
view.video.setVisible(part.isVideo())
|
||||
view.setOnClickListener { clicks.onNext(part.id) }
|
||||
holder.video.setVisible(part.isVideo())
|
||||
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
|
||||
|
||||
view.thumbnail.bubbleStyle = when {
|
||||
holder.thumbnail.bubbleStyle = when {
|
||||
!canGroupWithPrevious && canGroupWithNext -> if (message.isMe()) BubbleImageView.Style.OUT_FIRST else BubbleImageView.Style.IN_FIRST
|
||||
canGroupWithPrevious && canGroupWithNext -> if (message.isMe()) BubbleImageView.Style.OUT_MIDDLE else BubbleImageView.Style.IN_MIDDLE
|
||||
canGroupWithPrevious && !canGroupWithNext -> if (message.isMe()) BubbleImageView.Style.OUT_LAST else BubbleImageView.Style.IN_LAST
|
||||
else -> BubbleImageView.Style.ONLY
|
||||
}
|
||||
|
||||
GlideApp.with(context).load(part.getUri()).fitCenter().into(view.thumbnail)
|
||||
GlideApp.with(context).load(part.getUri()).fitCenter().into(holder.thumbnail)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
@@ -36,7 +36,7 @@ abstract class PartBinder {
|
||||
abstract fun canBindPart(part: MmsPart): Boolean
|
||||
|
||||
abstract fun bindPart(
|
||||
view: View,
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.moez.QKSMS.feature.compose.BubbleUtils.canGroup
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PartsAdapter @Inject constructor(
|
||||
@@ -54,35 +54,34 @@ class PartsAdapter @Inject constructor(
|
||||
private lateinit var message: Message
|
||||
private var previous: Message? = null
|
||||
private var next: Message? = null
|
||||
private var messageView: View? = null
|
||||
private var holder: QkViewHolder? = null
|
||||
private var bodyVisible: Boolean = true
|
||||
|
||||
fun setData(message: Message, previous: Message?, next: Message?, messageView: View) {
|
||||
fun setData(message: Message, previous: Message?, next: Message?, holder: QkViewHolder) {
|
||||
this.message = message
|
||||
this.previous = previous
|
||||
this.next = next
|
||||
this.messageView = messageView
|
||||
this.bodyVisible = messageView.body.visibility == View.VISIBLE
|
||||
this.holder = holder
|
||||
this.bodyVisible = holder.body.visibility == View.VISIBLE
|
||||
this.data = message.parts.filter { !it.isSmil() && !it.isText() }
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layout = partBinders.getOrNull(viewType)?.partLayout ?: 0
|
||||
val view = LayoutInflater.from(parent.context).inflate(layout, parent, false)
|
||||
messageView?.let(view::forwardTouches)
|
||||
holder?.containerView?.let(view::forwardTouches)
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val part = data[position]
|
||||
val view = holder.containerView
|
||||
|
||||
val canGroupWithPrevious = canGroup(message, previous) || position > 0
|
||||
val canGroupWithNext = canGroup(message, next) || position < itemCount - 1 || bodyVisible
|
||||
|
||||
partBinders
|
||||
.firstOrNull { it.canBindPart(part) }
|
||||
?.bindPart(view, part, message, canGroupWithPrevious, canGroupWithNext)
|
||||
?.bindPart(holder, part, message, canGroupWithPrevious, canGroupWithNext)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
|
||||
@@ -20,9 +20,9 @@ package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
@@ -36,7 +36,7 @@ import ezvcard.Ezvcard
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.mms_vcard_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.mms_vcard_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class VCardBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
@@ -47,37 +47,37 @@ class VCardBinder @Inject constructor(colors: Colors, private val context: Conte
|
||||
override fun canBindPart(part: MmsPart) = part.isVCard()
|
||||
|
||||
override fun bindPart(
|
||||
view: View,
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
.let(view.vCardBackground::setBackgroundResource)
|
||||
.let(holder.vCardBackground::setBackgroundResource)
|
||||
|
||||
view.setOnClickListener { clicks.onNext(part.id) }
|
||||
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
|
||||
|
||||
Observable.just(part.getUri())
|
||||
.map(context.contentResolver::openInputStream)
|
||||
.mapNotNull { inputStream -> inputStream.use { Ezvcard.parse(it).first() } }
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { vcard -> view.name?.text = vcard.formattedName.value }
|
||||
.subscribe { vcard -> holder.name?.text = vcard.formattedName.value }
|
||||
|
||||
val params = view.vCardBackground.layoutParams as FrameLayout.LayoutParams
|
||||
val params = holder.vCardBackground.layoutParams as FrameLayout.LayoutParams
|
||||
if (!message.isMe()) {
|
||||
view.vCardBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
view.vCardBackground.setBackgroundTint(theme.theme)
|
||||
view.vCardAvatar.setTint(theme.textPrimary)
|
||||
view.name.setTextColor(theme.textPrimary)
|
||||
view.label.setTextColor(theme.textTertiary)
|
||||
holder.vCardBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.vCardBackground.setBackgroundTint(theme.theme)
|
||||
holder.vCardAvatar.setTint(theme.textPrimary)
|
||||
holder.name.setTextColor(theme.textPrimary)
|
||||
holder.label.setTextColor(theme.textTertiary)
|
||||
} else {
|
||||
view.vCardBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
view.vCardBackground.setBackgroundTint(view.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
view.vCardAvatar.setTint(view.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
view.name.setTextColor(view.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
view.label.setTextColor(view.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
holder.vCardBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.vCardBackground.setBackgroundTint(holder.containerView.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.vCardAvatar.setTint(holder.containerView.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.name.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
holder.label.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user