Remove MessageListItem.position

This commit is contained in:
cketti 2022-08-30 16:32:41 +02:00
parent e14ce585a5
commit 18b177e18e
5 changed files with 11 additions and 9 deletions

View file

@ -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)
}

View file

@ -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)

View file

@ -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,

View file

@ -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,

View file

@ -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,