mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-12 18:22:22 +00:00
delete chatliststore and chatstoreadapter
This commit is contained in:
@ -1,96 +0,0 @@
|
|||||||
//package com.alya.ecommerce_serang.ui.profile.mystore.chat
|
|
||||||
//
|
|
||||||
//import android.os.Bundle
|
|
||||||
//import android.view.LayoutInflater
|
|
||||||
//import android.view.View
|
|
||||||
//import android.view.ViewGroup
|
|
||||||
//import android.widget.Toast
|
|
||||||
//import androidx.fragment.app.Fragment
|
|
||||||
//import androidx.fragment.app.viewModels
|
|
||||||
//import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig
|
|
||||||
//import com.alya.ecommerce_serang.data.repository.ChatRepository
|
|
||||||
//import com.alya.ecommerce_serang.data.repository.Result
|
|
||||||
//import com.alya.ecommerce_serang.databinding.FragmentChatListBinding
|
|
||||||
//import com.alya.ecommerce_serang.ui.chat.ChatViewModel
|
|
||||||
//import com.alya.ecommerce_serang.ui.chat.SocketIOService
|
|
||||||
//import com.alya.ecommerce_serang.utils.BaseViewModelFactory
|
|
||||||
//import com.alya.ecommerce_serang.utils.SessionManager
|
|
||||||
//
|
|
||||||
//class ChatListStoreFragment : Fragment() {
|
|
||||||
//
|
|
||||||
// private var _binding: FragmentChatListBinding? = null
|
|
||||||
//
|
|
||||||
// private val binding get() = _binding!!
|
|
||||||
// private lateinit var socketService: SocketIOService
|
|
||||||
// private lateinit var sessionManager: SessionManager
|
|
||||||
//
|
|
||||||
// private val viewModel: com.alya.ecommerce_serang.ui.chat.ChatViewModel by viewModels {
|
|
||||||
// BaseViewModelFactory {
|
|
||||||
// val apiService = ApiConfig.getApiService(sessionManager)
|
|
||||||
// val chatRepository = ChatRepository(apiService)
|
|
||||||
// ChatViewModel(chatRepository, socketService, sessionManager)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
// super.onCreate(savedInstanceState)
|
|
||||||
// sessionManager = SessionManager(requireContext())
|
|
||||||
// socketService = SocketIOService(sessionManager)
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onCreateView(
|
|
||||||
// inflater: LayoutInflater, container: ViewGroup?,
|
|
||||||
// savedInstanceState: Bundle?
|
|
||||||
// ): View {
|
|
||||||
// _binding = FragmentChatListBinding.inflate(inflater, container, false)
|
|
||||||
// return _binding!!.root
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
// super.onViewCreated(view, savedInstanceState)
|
|
||||||
//
|
|
||||||
// viewModel.getChatListStore()
|
|
||||||
// observeChatList()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private fun observeChatList() {
|
|
||||||
// viewModel.chatListStore.observe(viewLifecycleOwner) { result ->
|
|
||||||
// when (result) {
|
|
||||||
// is Result.Success -> {
|
|
||||||
// val adapter = ChatListAdapter(result.data) { chatItem ->
|
|
||||||
// // Use the ChatActivity.createIntent factory method for proper navigation
|
|
||||||
// ChatStoreActivity.createIntent(
|
|
||||||
// context = requireActivity(),
|
|
||||||
// storeId = chatItem.storeId,
|
|
||||||
// productId = 0, // Default value since we don't have it in ChatListItem
|
|
||||||
// productName = null, // Null is acceptable as per ChatActivity
|
|
||||||
// productPrice = "",
|
|
||||||
// productImage = null,
|
|
||||||
// productRating = null,
|
|
||||||
// storeName = chatItem.storeName,
|
|
||||||
// chatRoomId = chatItem.chatRoomId,
|
|
||||||
// storeImage = chatItem.storeImage
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// binding.chatListRecyclerView.adapter = adapter
|
|
||||||
// }
|
|
||||||
// is Result.Error -> {
|
|
||||||
// Toast.makeText(requireContext(), "Failed to load chats", Toast.LENGTH_SHORT).show()
|
|
||||||
// }
|
|
||||||
// Result.Loading -> {
|
|
||||||
// // Optional: show progress bar
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// override fun onDestroyView() {
|
|
||||||
// super.onDestroyView()
|
|
||||||
// _binding = null
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// companion object{
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -1,152 +0,0 @@
|
|||||||
package com.alya.ecommerce_serang.ui.profile.mystore.chat
|
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import com.alya.ecommerce_serang.BuildConfig.BASE_URL
|
|
||||||
import com.alya.ecommerce_serang.R
|
|
||||||
import com.alya.ecommerce_serang.databinding.ItemMessageReceivedBinding
|
|
||||||
import com.alya.ecommerce_serang.databinding.ItemMessageSentBinding
|
|
||||||
import com.alya.ecommerce_serang.ui.chat.ChatUiMessage
|
|
||||||
import com.alya.ecommerce_serang.utils.Constants
|
|
||||||
import com.bumptech.glide.Glide
|
|
||||||
|
|
||||||
class ChatStoreAdapter : ListAdapter<ChatUiMessage, RecyclerView.ViewHolder>(ChatMessageDiffCallback()) {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val VIEW_TYPE_MESSAGE_SENT = 1
|
|
||||||
private const val VIEW_TYPE_MESSAGE_RECEIVED = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
|
||||||
return if (viewType == VIEW_TYPE_MESSAGE_SENT) {
|
|
||||||
val binding = ItemMessageSentBinding.inflate(
|
|
||||||
LayoutInflater.from(parent.context),
|
|
||||||
parent,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
SentMessageViewHolder(binding)
|
|
||||||
} else {
|
|
||||||
val binding = ItemMessageReceivedBinding.inflate(
|
|
||||||
LayoutInflater.from(parent.context),
|
|
||||||
parent,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
ReceivedMessageViewHolder(binding)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
|
||||||
val message = getItem(position)
|
|
||||||
|
|
||||||
when (holder.itemViewType) {
|
|
||||||
VIEW_TYPE_MESSAGE_SENT -> (holder as SentMessageViewHolder).bind(message)
|
|
||||||
VIEW_TYPE_MESSAGE_RECEIVED -> (holder as ReceivedMessageViewHolder).bind(message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
|
||||||
val message = getItem(position)
|
|
||||||
return if (message.isSentByMe) {
|
|
||||||
VIEW_TYPE_MESSAGE_SENT
|
|
||||||
} else {
|
|
||||||
VIEW_TYPE_MESSAGE_RECEIVED
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ViewHolder for messages sent by the current user
|
|
||||||
*/
|
|
||||||
inner class SentMessageViewHolder(private val binding: ItemMessageSentBinding) :
|
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
|
||||||
|
|
||||||
fun bind(message: ChatUiMessage) {
|
|
||||||
binding.tvMessage.text = message.message
|
|
||||||
binding.tvTimestamp.text = message.time
|
|
||||||
|
|
||||||
// Show message status
|
|
||||||
val statusIcon = when (message.status) {
|
|
||||||
Constants.STATUS_SENT -> R.drawable.check_single_24
|
|
||||||
Constants.STATUS_DELIVERED -> R.drawable.check_double_24
|
|
||||||
Constants.STATUS_READ -> R.drawable.check_double_read_24
|
|
||||||
else -> R.drawable.check_single_24
|
|
||||||
}
|
|
||||||
binding.imgStatus.setImageResource(statusIcon)
|
|
||||||
|
|
||||||
// Handle attachment if exists
|
|
||||||
if (message.attachment?.isNotEmpty() == true) {
|
|
||||||
binding.imgAttachment.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
val fullImageUrl = when (val img = message.attachment) {
|
|
||||||
is String -> {
|
|
||||||
if (img.startsWith("/")) BASE_URL + img.substring(1) else img
|
|
||||||
}
|
|
||||||
else -> R.drawable.placeholder_image
|
|
||||||
}
|
|
||||||
|
|
||||||
Glide.with(binding.root.context)
|
|
||||||
.load(fullImageUrl)
|
|
||||||
.centerCrop()
|
|
||||||
.placeholder(R.drawable.placeholder_image)
|
|
||||||
.error(R.drawable.placeholder_image)
|
|
||||||
.into(binding.imgAttachment)
|
|
||||||
} else {
|
|
||||||
binding.imgAttachment.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ViewHolder for messages received from other users
|
|
||||||
*/
|
|
||||||
inner class ReceivedMessageViewHolder(private val binding: ItemMessageReceivedBinding) :
|
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
|
||||||
|
|
||||||
fun bind(message: ChatUiMessage) {
|
|
||||||
binding.tvMessage.text = message.message
|
|
||||||
binding.tvTimestamp.text = message.time
|
|
||||||
|
|
||||||
// Handle attachment if exists
|
|
||||||
val fullImageUrl = when (val img = message.attachment) {
|
|
||||||
is String -> {
|
|
||||||
if (img.startsWith("/")) BASE_URL + img.substring(1) else img
|
|
||||||
}
|
|
||||||
else -> R.drawable.placeholder_image
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.attachment?.isNotEmpty() == true) {
|
|
||||||
binding.imgAttachment.visibility = View.VISIBLE
|
|
||||||
Glide.with(binding.root.context)
|
|
||||||
.load(fullImageUrl)
|
|
||||||
.centerCrop()
|
|
||||||
.placeholder(R.drawable.placeholder_image)
|
|
||||||
.error(R.drawable.placeholder_image)
|
|
||||||
.into(binding.imgAttachment)
|
|
||||||
} else {
|
|
||||||
binding.imgAttachment.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load avatar image
|
|
||||||
Glide.with(binding.root.context)
|
|
||||||
.load(R.drawable.placeholder_image) // Replace with actual avatar URL if available
|
|
||||||
.circleCrop()
|
|
||||||
.into(binding.imgAvatar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DiffUtil callback for optimizing RecyclerView updates
|
|
||||||
*/
|
|
||||||
class ChatMessageDiffCallback : DiffUtil.ItemCallback<ChatUiMessage>() {
|
|
||||||
override fun areItemsTheSame(oldItem: ChatUiMessage, newItem: ChatUiMessage): Boolean {
|
|
||||||
return oldItem.id == newItem.id
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: ChatUiMessage, newItem: ChatUiMessage): Boolean {
|
|
||||||
return oldItem == newItem
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user