Skip to content

Homework_RecyclerView#55

Open
AnGuru-60 wants to merge 1 commit intoAndroid-Developer-Basic:masterfrom
AnGuru-60:master
Open

Homework_RecyclerView#55
AnGuru-60 wants to merge 1 commit intoAndroid-Developer-Basic:masterfrom
AnGuru-60:master

Conversation

@AnGuru-60
Copy link

No description provided.

val list = currentList.toMutableList()
list.removeAt(position)
submitList(list)
notifyDataSetChanged()

Choose a reason for hiding this comment

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

ListAdapter автоматически обновляет список через DiffUtil при вызове submitList, поэтому notifyDataSetChanged здесь не нужен и может вызвать лишние перерисовки. Можно убрать из методов removeItem и addItems.

}

fun removeItem(position: Int){
val list = currentList.toMutableList()

Choose a reason for hiding this comment

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

Можно добавьте проверку валидности позиции перед удалением

val totalItemCount = layoutManager.itemCount
val lastVisibleItem = layoutManager.findLastVisibleItemPosition()

if (lastVisibleItem + 1 == totalItemCount) {

Choose a reason for hiding this comment

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

При быстром скролле пагинация может срабатывать несколько раз подряд, что приводит к множественным одновременным загрузкам данных. Можно использовать флаг isLoading, чтобы предотвратить повторные вызовы addItems до завершения текущей загрузки

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