diff --git a/presentation/src/main/java/com/moez/QKSMS/common/base/QkRealmAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/common/base/QkRealmAdapter.kt index 093635fe..6934ead8 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/base/QkRealmAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/base/QkRealmAdapter.kt @@ -28,6 +28,7 @@ import io.realm.RealmList import io.realm.RealmModel import io.realm.RealmRecyclerViewAdapter import io.realm.RealmResults +import timber.log.Timber abstract class QkRealmAdapter : RealmRecyclerViewAdapter(null, true) { @@ -79,6 +80,15 @@ abstract class QkRealmAdapter : RealmRecyclerViewAdapter= 0 are allowed. Input was: $index") + return null + } + + return super.getItem(index) + } + override fun updateData(data: OrderedRealmCollection?) { if (getData() === data) return diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedAdapter.kt index c3ad52de..f6c1df30 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedAdapter.kt @@ -36,14 +36,14 @@ class BlockedAdapter @Inject constructor() : QkRealmAdapter() { val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false) return QkViewHolder(view).apply { view.setOnClickListener { - val conversation = getItem(adapterPosition)!! + val conversation = getItem(adapterPosition) ?: return@setOnClickListener unblock.onNext(conversation.id) } } } override fun onBindViewHolder(holder: QkViewHolder, position: Int) { - val conversation = getItem(position)!! + val conversation = getItem(position) ?: return val view = holder.containerView view.avatars.contacts = conversation.recipients diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt index 201d9494..df60bbee 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt @@ -151,7 +151,7 @@ class MessagesAdapter @Inject constructor( return QkViewHolder(view).apply { view.setOnClickListener { - val message = getItem(adapterPosition)!! + val message = getItem(adapterPosition) ?: return@setOnClickListener when (toggleSelection(message.id, false)) { true -> view.isActivated = isSelected(message.id) false -> { @@ -162,7 +162,7 @@ class MessagesAdapter @Inject constructor( } } view.setOnLongClickListener { - val message = getItem(adapterPosition)!! + val message = getItem(adapterPosition) ?: return@setOnLongClickListener true toggleSelection(message.id) view.isActivated = isSelected(message.id) true @@ -171,7 +171,7 @@ class MessagesAdapter @Inject constructor( } override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) { - val message = getItem(position)!! + 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 @@ -296,7 +296,7 @@ class MessagesAdapter @Inject constructor( } override fun getItemViewType(position: Int): Int { - val message = getItem(position)!! + val message = getItem(position) ?: return -1 return when (message.isMe()) { true -> VIEW_TYPE_MESSAGE_OUT false -> VIEW_TYPE_MESSAGE_IN diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationMediaAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationMediaAdapter.kt index 777acf57..e34063c0 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationMediaAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationMediaAdapter.kt @@ -42,14 +42,14 @@ class ConversationMediaAdapter @Inject constructor( val view = inflater.inflate(R.layout.conversation_media_list_item, parent, false) return QkViewHolder(view).apply { view.thumbnail.setOnClickListener { - val part = getItem(adapterPosition)!! + val part = getItem(adapterPosition) ?: return@setOnClickListener navigator.showMedia(part.id) } } } override fun onBindViewHolder(holder: QkViewHolder, position: Int) { - val part = getItem(position)!! + val part = getItem(position) ?: return val view = holder.containerView GlideApp.with(context) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationRecipientAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationRecipientAdapter.kt index 20a804a6..83c67013 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationRecipientAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationRecipientAdapter.kt @@ -44,7 +44,7 @@ class ConversationRecipientAdapter @Inject constructor( val view = layoutInflater.inflate(R.layout.conversation_recipient_list_item, parent, false) return QkViewHolder(view).apply { view.setOnClickListener { - val recipient = getItem(adapterPosition)!! + val recipient = getItem(adapterPosition) ?: return@setOnClickListener if (recipient.contact == null) { navigator.addContact(recipient.address) } else { @@ -55,7 +55,7 @@ class ConversationRecipientAdapter @Inject constructor( } override fun onBindViewHolder(holder: QkViewHolder, position: Int) { - val recipient = getItem(position)!! + val recipient = getItem(position) ?: return val view = holder.containerView view.avatar.threadId = threadId diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt index 9a96e34c..5413f231 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt @@ -62,14 +62,14 @@ class ConversationsAdapter @Inject constructor( return QkViewHolder(view).apply { view.setOnClickListener { - val conversation = getItem(adapterPosition)!! + val conversation = getItem(adapterPosition) ?: return@setOnClickListener when (toggleSelection(conversation.id, false)) { true -> view.isActivated = isSelected(conversation.id) false -> navigator.showConversation(conversation.id) } } view.setOnLongClickListener { - val conversation = getItem(adapterPosition)!! + val conversation = getItem(adapterPosition) ?: return@setOnLongClickListener true toggleSelection(conversation.id) view.isActivated = isSelected(conversation.id) true @@ -78,7 +78,7 @@ class ConversationsAdapter @Inject constructor( } override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) { - val conversation = getItem(position)!! + val conversation = getItem(position) ?: return val view = viewHolder.containerView view.isActivated = isSelected(conversation.id) @@ -98,6 +98,6 @@ class ConversationsAdapter @Inject constructor( } override fun getItemViewType(position: Int): Int { - return if (getItem(position)!!.read) 0 else 1 + return if (getItem(position)?.read == true) 0 else 1 } } \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryPagerAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryPagerAdapter.kt index e78c7750..2569a6c0 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryPagerAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryPagerAdapter.kt @@ -89,7 +89,7 @@ class GalleryPagerAdapter @Inject constructor(private val context: Context) : Qk } override fun onBindViewHolder(holder: QkViewHolder, position: Int) { - val part = getItem(position)!! + val part = getItem(position) ?: return val view = holder.containerView when (getItemViewType(position)) { VIEW_TYPE_IMAGE -> { diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/scheduled/ScheduledMessageAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/scheduled/ScheduledMessageAdapter.kt index 9071c203..0ac1abc4 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/scheduled/ScheduledMessageAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/scheduled/ScheduledMessageAdapter.kt @@ -56,14 +56,14 @@ class ScheduledMessageAdapter @Inject constructor( return QkViewHolder(view).apply { view.setOnClickListener { - val message = getItem(adapterPosition)!! + val message = getItem(adapterPosition) ?: return@setOnClickListener clicks.onNext(message.id) } } } override fun onBindViewHolder(holder: QkViewHolder, position: Int) { - val message = getItem(position)!! + val message = getItem(position) ?: return val view = holder.containerView // GroupAvatarView only accepts recipients, so map the phone numbers to recipients