diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt index 61ce6f0bd5..921069ee5a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt @@ -8,6 +8,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView +import org.ole.planet.myplanet.R import org.ole.planet.myplanet.databinding.ItemAiResponseMessageBinding import org.ole.planet.myplanet.databinding.ItemUserMessageBinding @@ -16,8 +17,8 @@ class ChatAdapter(private val chatList: ArrayList, val context: Context, private lateinit var textAiMessageBinding: ItemAiResponseMessageBinding var responseSource: Int = RESPONSE_SOURCE_UNKNOWN - private val VIEW_TYPE_QUERY = 1 - private val VIEW_TYPE_RESPONSE = 2 + private val viewTypeQuery = 1 + private val viewTypeResponse = 2 companion object { const val RESPONSE_SOURCE_SHARED_VIEW_MODEL = 1 const val RESPONSE_SOURCE_NETWORK = 2 @@ -29,17 +30,17 @@ class ChatAdapter(private val chatList: ArrayList, val context: Context, } } - class ResponseViewHolder(private val textAiMessageBinding: ItemAiResponseMessageBinding) : RecyclerView.ViewHolder(textAiMessageBinding.root) { + class ResponseViewHolder(private val textAiMessageBinding: ItemAiResponseMessageBinding, val context: Context) : RecyclerView.ViewHolder(textAiMessageBinding.root) { fun bind(response: String, responseSource: Int) { if(responseSource == RESPONSE_SOURCE_NETWORK){ val typingDelayMillis = 10L val typingAnimationDurationMillis = response.length * typingDelayMillis - textAiMessageBinding.textGchatMessageOther.text = "" + textAiMessageBinding.textGchatMessageOther.text = context.getString(R.string.empty_text) Handler(Looper.getMainLooper()).postDelayed({ - animateTyping(response, typingDelayMillis) + animateTyping(response) }, typingAnimationDurationMillis) } else if(responseSource == RESPONSE_SOURCE_SHARED_VIEW_MODEL){ - if (response != "") { + if (response.isNotEmpty()) { textAiMessageBinding.textGchatMessageOther.text = response } else{ textAiMessageBinding.textGchatMessageOther.visibility = View.GONE @@ -47,18 +48,18 @@ class ChatAdapter(private val chatList: ArrayList, val context: Context, } } - private fun animateTyping(response: String, typingDelayMillis: Long) { + private fun animateTyping(response: String) { var currentIndex = 0 val typingRunnable = object : Runnable { override fun run() { if (currentIndex < response.length) { textAiMessageBinding.textGchatMessageOther.text = response.substring(0, currentIndex + 1) currentIndex++ - Handler(Looper.getMainLooper()).postDelayed(this, typingDelayMillis) + Handler(Looper.getMainLooper()).postDelayed(this, 10L) } } } - Handler(Looper.getMainLooper()).postDelayed(typingRunnable, typingDelayMillis) + Handler(Looper.getMainLooper()).postDelayed(typingRunnable, 10L) } } @@ -90,18 +91,18 @@ class ChatAdapter(private val chatList: ArrayList, val context: Context, } override fun getItemViewType(position: Int): Int { - return if (position % 2 == 0) VIEW_TYPE_QUERY else VIEW_TYPE_RESPONSE + return if (position % 2 == 0) viewTypeQuery else viewTypeResponse } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return when (viewType) { - VIEW_TYPE_QUERY -> { + viewTypeQuery -> { textUserMessageBinding = ItemUserMessageBinding.inflate(LayoutInflater.from(context), parent, false) QueryViewHolder(textUserMessageBinding) } - VIEW_TYPE_RESPONSE -> { + viewTypeResponse -> { textAiMessageBinding = ItemAiResponseMessageBinding.inflate(LayoutInflater.from(context), parent, false) - ResponseViewHolder(textAiMessageBinding) + ResponseViewHolder(textAiMessageBinding, context) } else -> throw IllegalArgumentException("Invalid view type") } @@ -111,11 +112,11 @@ class ChatAdapter(private val chatList: ArrayList, val context: Context, val chatItem = chatList[position] Log.d("ChatAdapter", "chatList: $chatList") when (holder.itemViewType) { - VIEW_TYPE_QUERY -> { + viewTypeQuery -> { val queryViewHolder = holder as QueryViewHolder queryViewHolder.bind(chatItem) } - VIEW_TYPE_RESPONSE -> { + viewTypeResponse -> { val responseViewHolder = holder as ResponseViewHolder responseViewHolder.bind(chatItem, responseSource) } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt index 91e62b18b4..f5cc74baec 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt @@ -123,12 +123,12 @@ class ChatDetailFragment : Fragment() { } } - sharedViewModel.getSelected_id().observe(viewLifecycleOwner) { selected_id -> - _id = selected_id + sharedViewModel.getSelected_id().observe(viewLifecycleOwner) { selectedId -> + _id = selectedId } - sharedViewModel.getSelected_rev().observe(viewLifecycleOwner) { selected_rev -> - _rev = selected_rev + sharedViewModel.getSelected_rev().observe(viewLifecycleOwner) { selectedRev -> + _rev = selectedRev } view.post { clearChatDetail() @@ -292,7 +292,7 @@ class ChatDetailFragment : Fragment() { } } else { fragmentChatDetailBinding.textGchatIndicator.visibility = View.VISIBLE - fragmentChatDetailBinding.textGchatIndicator.text = "${responseBody.message}" + fragmentChatDetailBinding.textGchatIndicator.text = context?.getString(R.string.message_placeholder, responseBody.message) val jsonObject = JsonObject() jsonObject.addProperty("_rev", "") jsonObject.addProperty("_id", "") @@ -361,7 +361,7 @@ class ChatDetailFragment : Fragment() { RealmChatHistory.insert(mRealm, jsonObject) } fragmentChatDetailBinding.textGchatIndicator.visibility = View.VISIBLE - fragmentChatDetailBinding.textGchatIndicator.text = "${t.message}" + fragmentChatDetailBinding.textGchatIndicator.text = context?.getString(R.string.message_placeholder, t.message) fragmentChatDetailBinding.buttonGchatSend.isEnabled = true fragmentChatDetailBinding.editGchatMessage.isEnabled = true fragmentChatDetailBinding.imageGchatLoading.visibility = View.INVISIBLE @@ -369,7 +369,7 @@ class ChatDetailFragment : Fragment() { }) } - private fun continueChatRequest(content: RequestBody, _id: String, query: String) { + private fun continueChatRequest(content: RequestBody, id: String, query: String) { fragmentChatDetailBinding.buttonGchatSend.isEnabled = false fragmentChatDetailBinding.editGchatMessage.isEnabled = false fragmentChatDetailBinding.imageGchatLoading.visibility = View.VISIBLE @@ -385,16 +385,16 @@ class ChatDetailFragment : Fragment() { mAdapter.responseSource = ChatAdapter.RESPONSE_SOURCE_NETWORK mAdapter.addResponse(chatResponse) _rev = "${response.body()?.couchDBResponse?.rev}" - continueConversationRealm(_id, query, chatResponse) + continueConversationRealm(id, query, chatResponse) } } else { fragmentChatDetailBinding.textGchatIndicator.visibility = View.VISIBLE - fragmentChatDetailBinding.textGchatIndicator.text = "${responseBody.message}" + fragmentChatDetailBinding.textGchatIndicator.text = context?.getString(R.string.message_placeholder, responseBody.message) } } else { fragmentChatDetailBinding.textGchatIndicator.visibility = View.VISIBLE fragmentChatDetailBinding.textGchatIndicator.text = getString(R.string.request_failed_please_retry) - continueConversationRealm(_id, query, "") + continueConversationRealm(id, query, "") } fragmentChatDetailBinding.buttonGchatSend.isEnabled = true @@ -403,9 +403,9 @@ class ChatDetailFragment : Fragment() { } override fun onFailure(call: Call, t: Throwable) { - continueConversationRealm(_id, query, "") + continueConversationRealm(id, query, "") fragmentChatDetailBinding.textGchatIndicator.visibility = View.VISIBLE - fragmentChatDetailBinding.textGchatIndicator.text = "${t.message}" + fragmentChatDetailBinding.textGchatIndicator.text = context?.getString(R.string.message_placeholder, t.message) fragmentChatDetailBinding.buttonGchatSend.isEnabled = true fragmentChatDetailBinding.editGchatMessage.isEnabled = true fragmentChatDetailBinding.imageGchatLoading.visibility = View.INVISIBLE @@ -413,9 +413,9 @@ class ChatDetailFragment : Fragment() { }) } - private fun continueConversationRealm(_id:String, query:String, chatResponse:String) { + private fun continueConversationRealm(id:String, query:String, chatResponse:String) { try { - addConversationToChatHistory(mRealm, _id, query, chatResponse) + addConversationToChatHistory(mRealm, id, query, chatResponse) mRealm.commitTransaction() } catch (e: Exception) { e.printStackTrace() diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt index b7998da7ea..82e78c7f30 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt @@ -43,7 +43,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List private var newsList: RealmResults? = null interface ChatHistoryItemClickListener { - fun onChatHistoryItemClicked(conversations: RealmList?, _id: String, _rev: String?) + fun onChatHistoryItemClicked(conversations: RealmList?, id: String, rev: String?) } fun setChatHistoryItemClickListener(listener: ChatHistoryItemClickListener) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt index f4702e943d..513d47cb2f 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt @@ -75,10 +75,10 @@ class ChatHistoryListFragment : Fragment() { } val adapter = ChatHistoryListAdapter(requireContext(), list, this) adapter.setChatHistoryItemClickListener(object : ChatHistoryListAdapter.ChatHistoryItemClickListener { - override fun onChatHistoryItemClicked(conversations: RealmList?, _id: String, _rev:String?) { + override fun onChatHistoryItemClicked(conversations: RealmList?, id: String, rev:String?) { conversations?.let { sharedViewModel.setSelectedChatHistory(it) } - sharedViewModel.setSelected_id(_id) - _rev?.let { sharedViewModel.setSelected_rev(it) } + sharedViewModel.setSelected_id(id) + rev?.let { sharedViewModel.setSelected_rev(it) } fragmentChatHistoryListBinding.slidingPaneLayout.openPane() } diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 54d288486b..12621c23b2 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1049,5 +1049,7 @@ كوكب %s التقديمات غير متاحة لا توجد محادثات سابقة + + %s diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index ebcda27391..5b7df5ca27 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1049,5 +1049,7 @@ %s Planeta envíos no disponibles no hay chats anteriores + + %s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9c41b60a23..7abaebbc3f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1049,5 +1049,7 @@ %s planète soumissions non disponibles aucune discussion précédente + + %s diff --git a/app/src/main/res/values-ne/strings.xml b/app/src/main/res/values-ne/strings.xml index 6795dd2fa4..cab8145524 100644 --- a/app/src/main/res/values-ne/strings.xml +++ b/app/src/main/res/values-ne/strings.xml @@ -1049,5 +1049,7 @@ %s ग्रह पेशाहरू उपलब्ध छैनन् अघिल्ला कुराकानीहरू छैनन् + + %s diff --git a/app/src/main/res/values-so/strings.xml b/app/src/main/res/values-so/strings.xml index 379bd4d1f9..bc94dbb2aa 100644 --- a/app/src/main/res/values-so/strings.xml +++ b/app/src/main/res/values-so/strings.xml @@ -1049,5 +1049,7 @@ %s Meerah soo gudbin lama heli karo ma jiraan wada sheekaysi hore + + %s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 045423963f..a3feec73c9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1049,5 +1049,7 @@ %s\'s Planet submissions not available no previous chats + + %s