Skip to content

Done #1#35

Open
dmilkov97 wants to merge 3 commits intoAndroid-Developer-Basic:masterfrom
dmilkov97:master
Open

Done #1#35
dmilkov97 wants to merge 3 commits intoAndroid-Developer-Basic:masterfrom
dmilkov97:master

Conversation

@dmilkov97
Copy link

No description provided.


class ChatViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

private val mainImg: ShapeableImageView by lazy { itemView.findViewById(R.id.image_icon) }
Copy link
Contributor

Choose a reason for hiding this comment

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

здесь нет смысла использовать потокобезопасный lazy, это замедлит работу

Toast.makeText(this@MainActivity, "Load more", Toast.LENGTH_LONG).show()
val newChatItems = GenerateChatItems().getList().subList(0, 9).toMutableList()
items.addAll(newChatItems)
adapter.notifyDataSetChanged()
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Перенеси эту логику в адаптер
  2. Не используй метод notifyDataSetChanged, замени на notifyItemRangeInserted

val paging = PageScrollListener(manager).apply {
onLoadMore = {
Toast.makeText(this@MainActivity, "Load more", Toast.LENGTH_LONG).show()
val newChatItems = GenerateChatItems().getList().subList(0, 9).toMutableList()
Copy link
Contributor

Choose a reason for hiding this comment

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

просто добавляй новый список, без getList и саблиста

adapter = ChatAdapter(items)
recyclerView.adapter = adapter
recyclerView.layoutManager = manager
recyclerView.setItemViewCacheSize(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

А зачем тебе менять размер кеша?

}

fun onLoadMore(context: Context) {
Toast.makeText(context, "Load more", Toast.LENGTH_LONG).show()
Copy link
Contributor

Choose a reason for hiding this comment

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

Я бы это логику, и тост и запрос айтемов все таки вынес из адаптера, не его это отвественность

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