forked from upstream-mirrors/quik
Correctly use ContainerView with ViewHolder
This commit is contained in:
+11
-9
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.scheduled
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
@@ -34,10 +35,12 @@ import com.moez.QKSMS.repository.ContactRepository
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.scheduled_message_list_item.*
|
||||
import kotlinx.android.synthetic.main.scheduled_message_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ScheduledMessageAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val contactRepo: ContactRepository,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
@@ -52,7 +55,7 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.scheduled_message_list_item, parent, false)
|
||||
|
||||
view.attachments.adapter = ScheduledMessageAttachmentAdapter()
|
||||
view.attachments.adapter = ScheduledMessageAttachmentAdapter(context)
|
||||
view.attachments.setRecycledViewPool(imagesViewPool)
|
||||
|
||||
return QkViewHolder(view).apply {
|
||||
@@ -65,21 +68,20 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val message = getItem(position) ?: return
|
||||
val view = holder.containerView
|
||||
|
||||
// GroupAvatarView only accepts recipients, so map the phone numbers to recipients
|
||||
view.avatars.recipients = message.recipients.map { address -> Recipient(address = address) }
|
||||
holder.avatars.recipients = message.recipients.map { address -> Recipient(address = address) }
|
||||
|
||||
view.recipients.text = message.recipients.joinToString(",") { address ->
|
||||
holder.recipients.text = message.recipients.joinToString(",") { address ->
|
||||
contactCache[address]?.name?.takeIf { it.isNotBlank() } ?: address
|
||||
}
|
||||
|
||||
view.date.text = dateFormatter.getScheduledTimestamp(message.date)
|
||||
view.body.text = message.body
|
||||
holder.date.text = dateFormatter.getScheduledTimestamp(message.date)
|
||||
holder.body.text = message.body
|
||||
|
||||
val adapter = view.attachments.adapter as ScheduledMessageAttachmentAdapter
|
||||
val adapter = holder.attachments.adapter as ScheduledMessageAttachmentAdapter
|
||||
adapter.data = message.attachments.map(Uri::parse)
|
||||
view.attachments.isVisible = message.attachments.isNotEmpty()
|
||||
holder.attachments.isVisible = message.attachments.isNotEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,4 +104,4 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.scheduled
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
@@ -26,9 +27,12 @@ import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.attachment_image_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.scheduled_message_image_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ScheduledMessageAttachmentAdapter @Inject constructor() : QkAdapter<Uri>() {
|
||||
class ScheduledMessageAttachmentAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
) : QkAdapter<Uri>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.scheduled_message_image_list_item, parent, false)
|
||||
@@ -39,9 +43,8 @@ class ScheduledMessageAttachmentAdapter @Inject constructor() : QkAdapter<Uri>()
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val attachment = getItem(position)
|
||||
val view = holder.containerView
|
||||
|
||||
GlideApp.with(view).load(attachment).into(view.thumbnail)
|
||||
GlideApp.with(context).load(attachment).into(holder.thumbnail)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user