Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 committed Jun 20, 2021
2 parents a22d671 + 5139ccb commit 4744148
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 38 deletions.
49 changes: 14 additions & 35 deletions app/src/main/java/kr/ac/konkuk/koogle/Adapter/ChatAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import kr.ac.konkuk.koogle.DBKeys.Companion.LEFT_CHAT
import kr.ac.konkuk.koogle.DBKeys.Companion.RIGHT_CHAT
import kr.ac.konkuk.koogle.Model.ChatModel
import kr.ac.konkuk.koogle.R
import kr.ac.konkuk.koogle.databinding.ItemCardBinding
import kr.ac.konkuk.koogle.databinding.ItemLeftChatBinding
import kr.ac.konkuk.koogle.databinding.ItemRightChatBinding
import java.text.SimpleDateFormat
import java.util.*

Expand All @@ -23,45 +26,36 @@ class ChatAdapter(val context: Context, private val chatList: MutableList<ChatMo
abstract fun bind(item: T)
}

inner class LeftViewHolder(itemView: View) : BaseViewHolder<ChatModel>(itemView) {
inner class LeftViewHolder(private val binding: ItemLeftChatBinding) : BaseViewHolder<ChatModel>(binding.root) {

@SuppressLint("SimpleDateFormat")
val format = SimpleDateFormat("a HH:mm", Locale.KOREA)

val tv_writerName = itemView.findViewById<TextView>(R.id.writerNameTextView)
val tv_chatContent = itemView.findViewById<TextView>(R.id.contentTextView)
val tv_createTime = itemView.findViewById<TextView>(R.id.timeTextView)
val iv_writerProfileImage = itemView.findViewById<CircleImageView>(R.id.writerProfileImage)


override fun bind(chatModel: ChatModel) {
val time = Date(chatModel.chatCreatedAt)

tv_writerName.text = chatModel.writerName
tv_chatContent.text = chatModel.chatContent
tv_createTime.text = format.format(time).toString()
binding.writerNameTextView.text = chatModel.writerName
binding.contentTextView.text = chatModel.chatContent
binding.timeTextView.text = format.format(time).toString()

if (chatModel.writerProfileImageUrl.isNotEmpty()) {
Glide.with(iv_writerProfileImage)
Glide.with(binding.writerProfileImage)
.load(chatModel.writerProfileImageUrl)
.into(iv_writerProfileImage)
.into(binding.writerProfileImage)
}
}
}

inner class RightViewHolder(itemView: View) : BaseViewHolder<ChatModel>(itemView) {
inner class RightViewHolder(private val binding: ItemRightChatBinding) : BaseViewHolder<ChatModel>(binding.root) {

@SuppressLint("SimpleDateFormat")
val format = SimpleDateFormat("a HH:mm", Locale.KOREA)


val tv_chatContent = itemView.findViewById<TextView>(R.id.contentTextView)
val tv_createTime = itemView.findViewById<TextView>(R.id.timeTextView)
override fun bind(chatModel: ChatModel) {
val time = Date(chatModel.chatCreatedAt)

tv_chatContent.text = chatModel.chatContent
tv_createTime.text = format.format(time).toString()
binding.contentTextView.text = chatModel.chatContent
binding.timeTextView.text = format.format(time).toString()
}
}

Expand All @@ -70,14 +64,10 @@ class ChatAdapter(val context: Context, private val chatList: MutableList<ChatMo
//context 는 parent 에 있다
return when (viewType) {
LEFT_CHAT -> {
val view =
LayoutInflater.from(context).inflate(R.layout.item_left_chat, parent, false)
LeftViewHolder(view)
LeftViewHolder(ItemLeftChatBinding.inflate(LayoutInflater.from(parent.context),parent,false))
}
RIGHT_CHAT -> {
val view =
LayoutInflater.from(context).inflate(R.layout.item_right_chat, parent, false)
RightViewHolder(view)
RightViewHolder(ItemRightChatBinding.inflate(LayoutInflater.from(parent.context),parent,false))
}
else -> throw IllegalArgumentException("Invalid view type")
}
Expand All @@ -103,17 +93,6 @@ class ChatAdapter(val context: Context, private val chatList: MutableList<ChatMo
return chatList[position].viewType
}

// companion object {
// val diffUtil = object : DiffUtil.ItemCallback<ChatModel>() {
// override fun areItemsTheSame(oldModel: ChatModel, newModel: ChatModel): Boolean {
// return oldModel.chatCreatedAt == newModel.chatCreatedAt
// }
//
// override fun areContentsTheSame(oldModel: ChatModel, newModel: ChatModel): Boolean {
// return oldModel == newModel
// }
// }
// }

override fun getItemCount(): Int {
return chatList.size
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/row_user_tag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:layout_weight="2"
android:gravity="left"
android:text="TextView"
android:textColor="@color/black" />
android:textColor="#FFFFFF"/>

<LinearLayout
android:id="@+id/subTagView"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TAG_STYLE">
<item name="android:textSize">10sp</item>
<item name="android:textSize">15sp</item>
<item name="android:textColor">@color/black</item>
<item name="android:background">@drawable/layout_tag_background</item>
</style>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/tag_style_selected.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TAG_STYLE_SELECTED">
<item name="android:textSize">10sp</item>
<item name="android:textSize">15sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:background">@drawable/layout_tag_selected_background</item>
</style>
Expand Down

0 comments on commit 4744148

Please sign in to comment.