Skip to content

Homework#56

Open
aksenovasmail-git wants to merge 1 commit intoAndroid-Developer-Basic:masterfrom
aksenovasmail-git:master
Open

Homework#56
aksenovasmail-git wants to merge 1 commit intoAndroid-Developer-Basic:masterfrom
aksenovasmail-git:master

Conversation

@aksenovasmail-git
Copy link

No description provided.

) = false

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
val position = viewHolder.adapterPosition

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

При использовании DiffUtil и анимаций adapterPosition может возвращать NO_POSITION или некорректное значение. bindingAdapterPosition учитывает текущее состояние адаптера

fun bind(chat: Chat) {
val title = itemView.findViewById<TextView>(R.id.Title)
val statusIcon = itemView.findViewById<ImageView>(R.id.Delivered)
val avatarImageView = itemView.findViewById<ImageView>(R.id.Avatar)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Каждый раз вызывается findViewById для поиска title, statusIcon и avatarImageView, хотя часть View уже найдена в конструкторе. Это неэффективно при прокрутке списка.

Вынесите поиск всех View (title, statusIcon, avatarImageView) в конструктор ChatViewHolder и сохраните их как поля класса. В bind() просто используйте уже найденные ссылки. Это стандартная практика оптимизации ViewHolder в RecyclerView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants