mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
QkRealmAdapter binding support
This commit is contained in:
@@ -30,7 +30,7 @@ import io.realm.RealmRecyclerViewAdapter
|
||||
import io.realm.RealmResults
|
||||
import timber.log.Timber
|
||||
|
||||
abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkViewHolder>(null, true) {
|
||||
abstract class QkRealmAdapter<T : RealmModel, VH : QkViewHolder> : RealmRecyclerViewAdapter<T, VH>(null, true) {
|
||||
|
||||
/**
|
||||
* This view can be set, and the adapter will automatically control the visibility of this view
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.message_content_filter_list_item.*
|
||||
import kotlinx.android.synthetic.main.message_content_filter_list_item.view.*
|
||||
|
||||
class MessageContentFiltersAdapter : QkRealmAdapter<MessageContentFilter>() {
|
||||
class MessageContentFiltersAdapter : QkRealmAdapter<MessageContentFilter, QkViewHolder>() {
|
||||
|
||||
val removeMessageContentFilter: Subject<Long> = PublishSubject.create()
|
||||
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import javax.inject.Inject
|
||||
class BlockedMessagesAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val dateFormatter: DateFormatter
|
||||
) : QkRealmAdapter<Conversation>() {
|
||||
) : QkRealmAdapter<Conversation, QkViewHolder>() {
|
||||
|
||||
val clicks: PublishSubject<Long> = PublishSubject.create()
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.blocked_number_list_item.*
|
||||
import kotlinx.android.synthetic.main.blocked_number_list_item.view.*
|
||||
|
||||
class BlockedNumbersAdapter : QkRealmAdapter<BlockedNumber>() {
|
||||
class BlockedNumbersAdapter : QkRealmAdapter<BlockedNumber, QkViewHolder>() {
|
||||
|
||||
val unblockAddress: Subject<Long> = PublishSubject.create()
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ class MessagesAdapter @Inject constructor(
|
||||
private val prefs: Preferences,
|
||||
private val textViewStyler: TextViewStyler,
|
||||
private val navigator: Navigator,
|
||||
) : QkRealmAdapter<Message>() {
|
||||
) : QkRealmAdapter<Message, QkViewHolder>() {
|
||||
class AudioState(
|
||||
var partId: Long = -1,
|
||||
var state: QkMediaPlayer.PlayingState = QkMediaPlayer.PlayingState.Stopped,
|
||||
|
||||
@@ -23,36 +23,34 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.base.QkAdapter
|
||||
import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||
import dev.octoshrimpy.quik.common.base.QkBindingViewHolder
|
||||
import dev.octoshrimpy.quik.common.util.extensions.dpToPx
|
||||
import dev.octoshrimpy.quik.databinding.ContactChipBinding
|
||||
import dev.octoshrimpy.quik.model.Recipient
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.contact_chip.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Recipient, QkViewHolder>() {
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Recipient, QkBindingViewHolder<ContactChipBinding>>() {
|
||||
|
||||
var view: RecyclerView? = null
|
||||
val chipDeleted: PublishSubject<Recipient> = PublishSubject.create<Recipient>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.contact_chip, parent, false)
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkBindingViewHolder<ContactChipBinding> {
|
||||
val binding = ContactChipBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return QkBindingViewHolder(binding).apply {
|
||||
binding.root.setOnClickListener {
|
||||
val chip = getItem(adapterPosition)
|
||||
showDetailedChip(view.context, chip)
|
||||
showDetailedChip(binding.root.context, chip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkBindingViewHolder<ContactChipBinding>, position: Int) {
|
||||
val recipient = getItem(position)
|
||||
|
||||
holder.avatar.setRecipient(recipient)
|
||||
holder.name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
holder.binding.avatar.setRecipient(recipient)
|
||||
holder.binding.name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+9
-10
@@ -22,23 +22,22 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.base.QkAdapter
|
||||
import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||
import dev.octoshrimpy.quik.common.base.QkBindingViewHolder
|
||||
import dev.octoshrimpy.quik.databinding.ContactNumberListItemBinding
|
||||
import dev.octoshrimpy.quik.model.PhoneNumber
|
||||
import kotlinx.android.synthetic.main.contact_number_list_item.*
|
||||
|
||||
class PhoneNumberAdapter : QkAdapter<PhoneNumber, QkViewHolder>() {
|
||||
class PhoneNumberAdapter : QkAdapter<PhoneNumber, QkBindingViewHolder<ContactNumberListItemBinding>>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.contact_number_list_item, parent, false)
|
||||
return QkViewHolder(view)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkBindingViewHolder<ContactNumberListItemBinding> {
|
||||
val binding = ContactNumberListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return QkBindingViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkBindingViewHolder<ContactNumberListItemBinding>, position: Int) {
|
||||
val number = getItem(position)
|
||||
|
||||
holder.address.text = number.address
|
||||
holder.type.text = number.type
|
||||
holder.binding.address.text = number.address
|
||||
holder.binding.type.text = number.type
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(old: PhoneNumber, new: PhoneNumber): Boolean {
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ class ConversationsAdapter @Inject constructor(
|
||||
private val scheduledMessageRepo: ScheduledMessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : QkRealmAdapter<Conversation>() {
|
||||
) : QkRealmAdapter<Conversation, QkViewHolder>() {
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
init {
|
||||
|
||||
@@ -45,7 +45,7 @@ import kotlinx.android.synthetic.main.gallery_video_page.*
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class GalleryPagerAdapter @Inject constructor(private val context: Context) : QkRealmAdapter<MmsPart>() {
|
||||
class GalleryPagerAdapter @Inject constructor(private val context: Context) : QkRealmAdapter<MmsPart, QkViewHolder>() {
|
||||
|
||||
companion object {
|
||||
private const val VIEW_TYPE_INVALID = 0
|
||||
|
||||
+22
-22
@@ -26,7 +26,8 @@ import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.base.QkRealmAdapter
|
||||
import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||
import dev.octoshrimpy.quik.common.base.QkBindingViewHolder
|
||||
import dev.octoshrimpy.quik.databinding.ScheduledMessageListItemBinding
|
||||
import dev.octoshrimpy.quik.common.util.DateFormatter
|
||||
import dev.octoshrimpy.quik.model.Contact
|
||||
import dev.octoshrimpy.quik.model.Recipient
|
||||
@@ -35,8 +36,6 @@ import dev.octoshrimpy.quik.repository.ContactRepository
|
||||
import dev.octoshrimpy.quik.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(
|
||||
@@ -44,7 +43,7 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
private val contactRepo: ContactRepository,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : QkRealmAdapter<ScheduledMessage>() {
|
||||
) : QkRealmAdapter<ScheduledMessage, QkBindingViewHolder<ScheduledMessageListItemBinding>>() {
|
||||
|
||||
private val contacts by lazy { contactRepo.getContacts() }
|
||||
private val contactCache = ContactCache()
|
||||
@@ -52,47 +51,48 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.scheduled_message_list_item, parent, false)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkBindingViewHolder<ScheduledMessageListItemBinding> {
|
||||
val binding = ScheduledMessageListItemBinding.inflate(
|
||||
LayoutInflater.from(parent.context), parent, false
|
||||
)
|
||||
|
||||
view.attachments.adapter = ScheduledMessageAttachmentAdapter(context)
|
||||
view.attachments.setRecycledViewPool(imagesViewPool)
|
||||
binding.attachments.adapter = ScheduledMessageAttachmentAdapter(context)
|
||||
binding.attachments.setRecycledViewPool(imagesViewPool)
|
||||
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
return QkBindingViewHolder(binding).apply {
|
||||
binding.root.setOnClickListener {
|
||||
val message = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
if (toggleSelection(message.id, false))
|
||||
view.isActivated = isSelected(message.id)
|
||||
binding.root.isActivated = isSelected(message.id)
|
||||
}
|
||||
view.setOnClickListener {
|
||||
binding.root.setOnClickListener {
|
||||
val message = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
toggleSelection(message.id)
|
||||
view.isActivated = isSelected(message.id)
|
||||
binding.root.isActivated = isSelected(message.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkBindingViewHolder<ScheduledMessageListItemBinding>, position: Int) {
|
||||
val message = getItem(position) ?: return
|
||||
|
||||
// GroupAvatarView only accepts recipients, so map the phone numbers to recipients
|
||||
holder.avatars.recipients =
|
||||
holder.binding.avatars.recipients =
|
||||
message.recipients.map { address -> Recipient(address = address) }
|
||||
|
||||
holder.recipients.text = message.recipients.joinToString(",") { address ->
|
||||
holder.binding.recipients.text = message.recipients.joinToString(",") { address ->
|
||||
contactCache[address]?.name?.takeIf { it.isNotBlank() } ?: address
|
||||
}
|
||||
|
||||
holder.date.text = dateFormatter.getScheduledTimestamp(message.date)
|
||||
holder.body.text = message.body
|
||||
holder.binding.date.text = dateFormatter.getScheduledTimestamp(message.date)
|
||||
holder.binding.body.text = message.body
|
||||
|
||||
// update the selected/highlighted state
|
||||
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
|
||||
holder.binding.root.isActivated = isSelected(message.id) || highlight == message.id
|
||||
|
||||
val adapter = holder.attachments.adapter as ScheduledMessageAttachmentAdapter
|
||||
val adapter = holder.binding.attachments.adapter as ScheduledMessageAttachmentAdapter
|
||||
adapter.data = message.attachments.map(Uri::parse)
|
||||
holder.attachments.isVisible = message.attachments.isNotEmpty()
|
||||
holder.binding.attachments.isVisible = message.attachments.isNotEmpty()
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
|
||||
Reference in New Issue
Block a user