forked from upstream-mirrors/quik
Use LayoutContainer api for ViewHolders
This commit is contained in:
@@ -83,7 +83,7 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val menuItem = getItem(position)
|
val menuItem = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
view.title.text = menuItem.title
|
view.title.text = menuItem.title
|
||||||
view.check.isActivated = (menuItem.actionId == selectedItem)
|
view.check.isActivated = (menuItem.actionId == selectedItem)
|
||||||
|
|||||||
@@ -20,5 +20,8 @@ package com.moez.QKSMS.common.base
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import kotlinx.android.extensions.LayoutContainer
|
||||||
|
|
||||||
class QkViewHolder(view: View) : RecyclerView.ViewHolder(view)
|
class QkViewHolder(view: View) : RecyclerView.ViewHolder(view), LayoutContainer {
|
||||||
|
override val containerView: View = view
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class BackupAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val backup = getItem(position)
|
val backup = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
val count = backup.messages
|
val count = backup.messages
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class BlockedAdapter @Inject constructor() : QkRealmAdapter<Conversation>() {
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val conversation = getItem(position)!!
|
val conversation = getItem(position)!!
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
view.avatars.contacts = conversation.recipients
|
view.avatars.contacts = conversation.recipients
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class AttachmentAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val attachment = getItem(position)
|
val attachment = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
when (attachment) {
|
when (attachment) {
|
||||||
is Attachment.Image -> Glide.with(context)
|
is Attachment.Image -> Glide.with(context)
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class ChipsAdapter @Inject constructor(private val context: Context) : QkAdapter
|
|||||||
when (getItemViewType(position)) {
|
when (getItemViewType(position)) {
|
||||||
TYPE_ITEM -> {
|
TYPE_ITEM -> {
|
||||||
val contact = getItem(position)
|
val contact = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
view.avatar.setContact(contact)
|
view.avatar.setContact(contact)
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class ContactAdapter @Inject constructor() : QkAdapter<Contact>() {
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val contact = getItem(position)
|
val contact = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
view.avatar.setContact(contact)
|
view.avatar.setContact(contact)
|
||||||
view.name.text = contact.name
|
view.name.text = contact.name
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
val message = getItem(position)!!
|
val message = getItem(position)!!
|
||||||
val previous = if (position == 0) null else getItem(position - 1)
|
val previous = if (position == 0) null else getItem(position - 1)
|
||||||
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
||||||
val view = viewHolder.itemView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
|
|
||||||
// Update the selected state
|
// Update the selected state
|
||||||
@@ -267,7 +267,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun bindStatus(viewHolder: QkViewHolder, message: Message, next: Message?) {
|
private fun bindStatus(viewHolder: QkViewHolder, message: Message, next: Message?) {
|
||||||
val view = viewHolder.itemView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
val age = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - message.date)
|
val age = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - message.date)
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class PhoneNumberAdapter(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val number = getItem(position)
|
val number = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
// Setting this in onCreateViewHolder causes a crash sometimes. [contact] returns the
|
// Setting this in onCreateViewHolder causes a crash sometimes. [contact] returns the
|
||||||
// contact from a different row, I'm not sure why
|
// contact from a different row, I'm not sure why
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class PartsAdapter(context: Context, navigator: Navigator, theme: Colors.Theme)
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val part = data[position]
|
val part = data[position]
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
val canGroupWithPrevious = canGroup(message, previous) || position > 0
|
val canGroupWithPrevious = canGroup(message, previous) || position > 0
|
||||||
val canGroupWithNext = canGroup(message, next) || position < itemCount - 1 || bodyVisible
|
val canGroupWithNext = canGroup(message, next) || position < itemCount - 1 || bodyVisible
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ class ConversationMediaAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val part = getItem(position)!!
|
val part = getItem(position)!!
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
GlideApp.with(context)
|
GlideApp.with(context)
|
||||||
.load(part.getUri())
|
.load(part.getUri())
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ class ConversationRecipientAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val recipient = getItem(position)!!
|
val recipient = getItem(position)!!
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
view.avatar.threadId = threadId
|
view.avatar.threadId = threadId
|
||||||
view.avatar.setContact(recipient)
|
view.avatar.setContact(recipient)
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||||
val conversation = getItem(position)!!
|
val conversation = getItem(position)!!
|
||||||
val view = viewHolder.itemView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
view.isActivated = isSelected(conversation.id)
|
view.isActivated = isSelected(conversation.id)
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class SearchAdapter @Inject constructor(
|
|||||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||||
val previous = data.getOrNull(position - 1)
|
val previous = data.getOrNull(position - 1)
|
||||||
val result = getItem(position)
|
val result = getItem(position)
|
||||||
val view = viewHolder.itemView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
view.resultsHeader.setVisible(result.messages > 0 && previous?.messages == 0)
|
view.resultsHeader.setVisible(result.messages > 0 && previous?.messages == 0)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ class ScheduledMessageAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val message = getItem(position)!!
|
val message = getItem(position)!!
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
// GroupAvatarView only accepts recipients, so map the phone numbers to recipients
|
// GroupAvatarView only accepts recipients, so map the phone numbers to recipients
|
||||||
view.avatars.contacts = message.recipients.map { address -> Recipient(address = address) }
|
view.avatars.contacts = message.recipients.map { address -> Recipient(address = address) }
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ class ScheduledMessageAttachmentAdapter @Inject constructor() : QkAdapter<Uri>()
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val attachment = getItem(position)
|
val attachment = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
GlideApp.with(view).load(attachment).into(view.thumbnail)
|
GlideApp.with(view).load(attachment).into(view.thumbnail)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class ThemeAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||||
val palette = getItem(position)
|
val palette = getItem(position)
|
||||||
val view = holder.itemView
|
val view = holder.containerView
|
||||||
|
|
||||||
val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
||||||
val minPadding = (16 * 6).dpToPx(context)
|
val minPadding = (16 * 6).dpToPx(context)
|
||||||
|
|||||||
Reference in New Issue
Block a user