Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c3510dd
Сделал половину первого пункта
nazarovNV Jul 3, 2024
b186eee
Сделал круглую аватарку
nazarovNV Jul 3, 2024
b98367e
Сделал круглую аватарку, добавил иконку и стили
nazarovNV Jul 3, 2024
d17aaa7
Реализовал вьюхолдер
nazarovNV Jul 5, 2024
0757b7f
Делаю реализацию ItemDecoration
nazarovNV Jul 5, 2024
6cb8267
реализация ItemDecoration
Jul 5, 2024
7073f8f
Сделал полосу
Jul 5, 2024
82b236f
Сделал полосу
Jul 5, 2024
61cabd5
Сделал полосу
Jul 5, 2024
5b517c3
Не работает анимация свайпа
Jul 5, 2024
02556d2
Сделал кривую анимацию свайпа
Jul 5, 2024
e3a7275
Поменял иконку
Jul 5, 2024
e5450ed
Делаю пагинацию
Jul 5, 2024
e02b548
Делаю пагинацию
Jul 5, 2024
4304823
Делаю пагинацию
Jul 11, 2024
1f1907b
Переписал логику обновления айтемов, теперь при удалении не появляютс…
Jul 11, 2024
8159fd6
Написал пейджскролллистенер
Jul 11, 2024
ed6f926
Применяю в активити
Jul 11, 2024
7b88cbb
Сделал прогрузку при скролле но теперь падаю когда список заканчивается
Jul 11, 2024
4f0d442
Сделал дз
Jul 11, 2024
77b67ff
Делаю как по макету
Jul 12, 2024
c45106a
Добавил иконку мута
Jul 12, 2024
ca7a61d
Добавил иконку скама
Jul 12, 2024
532ea55
Добавил иконку превью картинки
Jul 12, 2024
b3fcc4d
Делаю каунтер сообщений
Jul 12, 2024
ca38f2e
Правлю баги
Jul 12, 2024
d8d3519
Правлю баги
Jul 13, 2024
a58eb9e
Убрал лишний код
Jul 13, 2024
a3b2d31
Готово
Jul 13, 2024
2dc74aa
Готово
Jul 13, 2024
6047310
Готово
Jul 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions app/src/main/java/otus/gpb/recyclerview/ChatAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package otus.gpb.recyclerview

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView

enum class MessageState {
IS_READ,
IS_SENT,
IS_INCOMING
}

class ChatAdapter(private val items: MutableList<ChatItem>) : RecyclerView.Adapter<ChatAdapter.ChatViewHolder>() {
class ChatViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val name: TextView by lazy { itemView.findViewById(R.id.nameTV) }
private val isMuted: ImageView by lazy { itemView.findViewById(R.id.MutedIcon) }
private val isVerified: ImageView by lazy { itemView.findViewById(R.id.VerifiedIcon) }
private val isScam: TextView by lazy { itemView.findViewById(R.id.ScamIcon) }
private val title: TextView by lazy { itemView.findViewById(R.id.titleTV) }
private val hasPrevPic: ImageView by lazy { itemView.findViewById(R.id.prevPic) }
private val message: TextView by lazy { itemView.findViewById(R.id.messageTV) }
private val messageState: ImageView by lazy { itemView.findViewById(R.id.messageState) }
private val time: TextView by lazy { itemView.findViewById(R.id.timeTV) }
private val messageCounter: TextView by lazy { itemView.findViewById(R.id.messageCounter) }
private val image: ImageView by lazy { itemView.findViewById(R.id.imageAvatar) }
fun bind(item: ChatItem){
name.text = item.name
if (item.isMuted) {
isMuted.visibility = View.VISIBLE
isMuted.setImageResource(R.drawable.volume_off)
}
else isMuted.visibility = View.GONE
if (item.isVerified) isVerified.setImageResource(R.drawable.check_decagram)
if (!item.isScam) isScam.visibility = View.GONE
else isScam.visibility = View.VISIBLE
if (item.hasPrevPic) {
val params = message.layoutParams as ConstraintLayout.LayoutParams
params.marginStart = 6
message.layoutParams = params
hasPrevPic.visibility = View.VISIBLE
hasPrevPic.setImageResource(R.drawable.prevpic)
}
else {
hasPrevPic.visibility = View.GONE
val params = message.layoutParams as ConstraintLayout.LayoutParams
params.marginStart = 0
message.layoutParams = params
}

if (item.title.isNullOrEmpty()) {
title.visibility = View.GONE
}
else {
title.text = item.title
}
message.text = item.message

if (item.messageState == MessageState.IS_SENT) messageState.setImageResource(R.drawable.check_svgrepo_com)
if (item.messageState == MessageState.IS_READ) messageState.setImageResource(R.drawable.check_read_svgrepo_com)
if (item.messageState == MessageState.IS_INCOMING) messageState.visibility = View.GONE
time.text = item.time
if (item.messageCounter != null) {
messageCounter.visibility = View.VISIBLE
messageCounter.text = item.messageCounter.toString()
}
else messageCounter.visibility = View.GONE
image.setImageResource(item.image)

}
}
// init {
// setHasStableIds(true)
// }

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChatViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.dialog_view_item, parent, false)
return ChatViewHolder(view)
}

override fun getItemCount(): Int {
return items.size
}

override fun onBindViewHolder(holder: ChatViewHolder, position: Int) {
holder.bind(items[position])
}

fun deleteItem(position: Int) {
items.removeAt(position)
notifyItemRemoved(position)

}

}
18 changes: 18 additions & 0 deletions app/src/main/java/otus/gpb/recyclerview/ChatItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package otus.gpb.recyclerview

data class ChatItem(
val id: Int,
val name: String,
val isMuted: Boolean,
val isVerified: Boolean,
val isScam: Boolean,
val hasPrevPic: Boolean,
val messageState: MessageState,
val title: String?,
val message: String,
val time: String,
val messageCounter: Int?,
val image: Int
)


25 changes: 25 additions & 0 deletions app/src/main/java/otus/gpb/recyclerview/ChatViewHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package otus.gpb.recyclerview

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class ChatViewHolder (
private val view: View) : RecyclerView.ViewHolder(view) {
private val name: TextView by lazy { view.findViewById(R.id.nameTV) }
private val title: TextView by lazy { view.findViewById(R.id.titleTV) }
private val message: TextView by lazy { view.findViewById(R.id.messageTV) }
private val time: TextView by lazy { view.findViewById(R.id.timeTV) }
private val image: ImageView by lazy { view.findViewById(R.id.imageAvatar) }
fun bind(item: ChatItem){
name.text = item.name
title.text = item.title
message.text = item.message
time.text = item.time
image.setImageResource(item.image)

}


}
140 changes: 140 additions & 0 deletions app/src/main/java/otus/gpb/recyclerview/Dialogs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package otus.gpb.recyclerview

class Dialogs {

companion object {
fun generateList() : List<ChatItem> {
val list = mutableListOf<ChatItem>()
var person = ChatItem(
id = 1,
name = "Pizza",
isMuted = true,
isVerified = false,
isScam = false,
hasPrevPic = true,
title = "jija",
message = "Yes, they are necessary",
messageState = MessageState.IS_INCOMING,
time = "11:38 AM",
messageCounter = null,
image = R.drawable.avatar1
)
list.add(person)

person = ChatItem(
id = 2,
name = "Elon",
isMuted = true,
isVerified = false,
isScam = false,
hasPrevPic = false,
title = "",
message = "I love /r/Reddit!",
messageState = MessageState.IS_INCOMING,
time = "12:44 AM",
messageCounter = null,
image = R.drawable.avatar2
)
list.add(person)

person = ChatItem(
id = 3,
name = "Pasha",
isMuted = true,
isVerified = true,
isScam = false,
hasPrevPic = false,
title = null,
message = "How are u?",
messageState = MessageState.IS_INCOMING,
time = "Fri",
messageCounter = null,
image = R.drawable.avatar3
)
list.add(person)

person = ChatItem(
id = 4,
name = "Tim Cook",
isMuted = true,
isVerified = true,
isScam = false,
hasPrevPic = false,
title = "Boss of Apple",
message = "Android is better",
messageState = MessageState.IS_READ,
time = "15:02 AM",
messageCounter = null,
image = R.drawable.avatar4
)
list.add(person)

person = ChatItem(
id = 5,
name = "Telegram Support",
isMuted = false,
isVerified = true,
isScam = false,
hasPrevPic = false,
title = "Support",
message = "Yes it happened.",
messageState = MessageState.IS_INCOMING,
time = "Thu",
messageCounter = 1,
image = R.drawable.avatar5
)
list.add(person)

person = ChatItem(
id = 6,
name = "Karina",
isMuted = false,
isVerified = false,
isScam = false,
hasPrevPic = false,
title = "",
message = "Okay",
messageState = MessageState.IS_SENT,
time = "Wed",
messageCounter = null,
image = R.drawable.avatar6
)
list.add(person)

person = ChatItem(
id = 7,
name = "Marilyn",
isMuted = false,
isVerified = false,
isScam = true,
hasPrevPic = false,
title = "",
message = "Will it ever happen",
messageState = MessageState.IS_READ,
time = "May 02",
messageCounter = null,
image = R.drawable.avatar7
)
list.add(person)

repeat(43){
val person = ChatItem(
id = it + 8,
name = "Name ${it + 8}",
isMuted = false,
isVerified = true,
isScam = true,
hasPrevPic = false,
title = "Name title $it",
message = "This is message $it",
messageState = MessageState.IS_SENT,
time = "12:12 AM",
messageCounter = null,
image = R.drawable.default_avatar
)
list.add(person)
}
return list.toList()
}
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/otus/gpb/recyclerview/DividerItemDecoration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import otus.gpb.recyclerview.R

class DividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
private val dividerPaint: Paint = Paint()

init {
dividerPaint.color = ContextCompat.getColor(context, R.color.divider_color) // Цвет полосы
dividerPaint.strokeWidth = 1F // Ширина полосы
}

override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val left = parent.paddingLeft
val right = parent.width - parent.paddingRight

for (i in 0 until parent.childCount - 1) {
val child = parent.getChildAt(i)
val params = child.layoutParams as RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
val bottom = top + dividerPaint.strokeWidth
c.drawRect(left.toFloat(), top.toFloat(), right.toFloat(), bottom, dividerPaint)
}
}
}
Loading