Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18b177e1 authored by cketti's avatar cketti
Browse files

Remove `MessageListItem.position`

parent e14ce585
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -55,9 +55,12 @@ class MessageListAdapter internal constructor(
    var messages: List<MessageListItem> = emptyList()
        set(value) {
            field = value
            messagesMap = value.associateBy { it.uniqueId }
            notifyDataSetChanged()
        }

    private var messagesMap = emptyMap<Long, MessageListItem>()

    var activeMessage: MessageReference? = null

    var selected: Set<Long> = emptySet()
@@ -71,14 +74,14 @@ class MessageListAdapter internal constructor(

    private val flagClickListener = OnClickListener { view: View ->
        val messageViewHolder = view.tag as MessageViewHolder
        val messageListItem = getItem(messageViewHolder.position)
        val messageListItem = getItemById(messageViewHolder.uniqueId)
        listItemListener.onToggleMessageFlag(messageListItem)
    }

    private val contactPictureClickListener = OnClickListener { view: View ->
        val parentView = view.parent.parent as View
        val messageViewHolder = parentView.tag as MessageViewHolder
        val messageListItem = getItem(messageViewHolder.position)
        val messageListItem = getItemById(messageViewHolder.uniqueId)
        listItemListener.onToggleMessageSelection(messageListItem)
    }

@@ -96,6 +99,10 @@ class MessageListAdapter internal constructor(

    override fun getItem(position: Int): MessageListItem = messages[position]

    private fun getItemById(uniqueId: Long): MessageListItem {
        return messagesMap[uniqueId]!!
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val message = getItem(position)
        val view: View = convertView ?: newView(parent)
@@ -163,7 +170,7 @@ class MessageListAdapter internal constructor(
            if (appearance.stars) {
                holder.flagged.isChecked = isStarred
            }
            holder.position = position
            holder.uniqueId = uniqueId
            if (appearance.showContactPicture && holder.contactPicture.isVisible) {
                setContactPicture(holder.contactPicture, displayAddress)
            }
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ import android.widget.TextView
import com.fsck.k9.ui.R

class MessageViewHolder(view: View) {
    var position = -1
    var uniqueId: Long = -1L

    val selected: View = view.findViewById(R.id.selected)
    val contactPicture: ImageView = view.findViewById(R.id.contact_picture)
+0 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ class MessageListExtractor(
        uniqueIdColumn: Int,
        threadCountIncluded: Boolean
    ): MessageListItem {
        val position = cursor.position
        val accountUuid = cursor.getString(MLFProjectionInfo.ACCOUNT_UUID_COLUMN)
        val account = preferences.getAccount(accountUuid) ?: error("Account $accountUuid not found")

@@ -60,7 +59,6 @@ class MessageListExtractor(
        }

        return MessageListItem(
            position,
            account,
            subject,
            threadCount,
+0 −1
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ import com.fsck.k9.Account
import com.fsck.k9.mail.Address

data class MessageListItem(
    val position: Int,
    val account: Account,
    val subject: String?,
    val threadCount: Int,
+0 −2
Original line number Diff line number Diff line
@@ -469,7 +469,6 @@ class MessageListAdapterTest : RobolectricTest() {
    }

    fun createMessageListItem(
        position: Int = 0,
        account: Account = Account(SOME_ACCOUNT_UUID),
        subject: String? = "irrelevant",
        threadCount: Int = 0,
@@ -492,7 +491,6 @@ class MessageListAdapterTest : RobolectricTest() {
        threadRoot: Long = 0L
    ): MessageListItem {
        return MessageListItem(
            position,
            account,
            subject,
            threadCount,