From b7b531f6d2f42b2ddd78a3534e295c48398c91a0 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 14 Mar 2024 21:47:31 +0300 Subject: [PATCH] chat: stabler with safe call operators (fixes #3242) (#3246) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../planet/myplanet/ui/chat/ChatDetailFragment.kt | 10 +++++----- .../myplanet/ui/chat/ChatHistoryListAdapter.kt | 14 +++++++------- .../myplanet/ui/chat/ChatHistoryListFragment.kt | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0122ed0e2a..129e5554ef 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1415 - versionName "0.14.15" + versionCode 1416 + versionName "0.14.16" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true 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 0dbde1e8e7..71c599d91a 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 @@ -158,11 +158,11 @@ class ChatDetailFragment : Fragment() { if (chatResponse != null) { mAdapter.responseSource = ChatAdapter.RESPONSE_SOURCE_NETWORK mAdapter.addResponse(chatResponse) - _id = response.body()!!.couchDBResponse!!.id.toString() - _rev = response.body()!!.couchDBResponse!!.rev.toString() + _id = "${response.body()?.couchDBResponse?.id}" + _rev = "${response.body()?.couchDBResponse?.rev}" val jsonObject = JsonObject() - jsonObject.addProperty("_rev", response.body()!!.couchDBResponse!!.rev.toString()) - jsonObject.addProperty("_id", response.body()!!.couchDBResponse!!.id.toString()) + jsonObject.addProperty("_rev", "${response.body()?.couchDBResponse?.rev}") + jsonObject.addProperty("_id", "${response.body()?.couchDBResponse?.id}") jsonObject.addProperty("time", "") jsonObject.addProperty("title", "") jsonObject.addProperty("updatedTime", "") @@ -265,7 +265,7 @@ class ChatDetailFragment : Fragment() { if (chatResponse != null) { mAdapter.responseSource = ChatAdapter.RESPONSE_SOURCE_NETWORK mAdapter.addResponse(chatResponse) - _rev = response.body()!!.couchDBResponse!!.rev.toString() + _rev = "${response.body()?.couchDBResponse?.rev}" continueConversationRealm(_id, query, chatResponse) } } else { 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 9a5797ab78..387fedbde0 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 @@ -16,7 +16,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List private var filteredChatHistory: List = chatHistory interface ChatHistoryItemClickListener { - fun onChatHistoryItemClicked(conversations: RealmList, _id: String, _rev: String) + fun onChatHistoryItemClicked(conversations: RealmList?, _id: String, _rev: String?) } fun setChatHistoryItemClickListener(listener: ChatHistoryItemClickListener) { @@ -25,10 +25,10 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List fun filter(query: String) { filteredChatHistory = chatHistory.filter { chat -> - if (chat.conversations != null && chat.conversations!!.isNotEmpty()) { + if (chat.conversations != null && chat.conversations?.isNotEmpty() == true) { chat.conversations!![0]?.query?.contains(query, ignoreCase = true) == true } else { - chat.title!!.contains(query, ignoreCase = true) + chat.title?.contains(query, ignoreCase = true) ==true } } notifyDataSetChanged() @@ -45,7 +45,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val viewHolderChat = holder as ViewHolderChat - if (filteredChatHistory[position].conversations != null && filteredChatHistory[position].conversations!!.isNotEmpty()) { + if (filteredChatHistory[position].conversations != null && filteredChatHistory[position].conversations?.isNotEmpty() == true) { viewHolderChat.rowChatHistoryBinding.chatTitle.text = filteredChatHistory[position].conversations?.get(0)!!.query viewHolderChat.rowChatHistoryBinding.chatCardView.contentDescription = filteredChatHistory[position].conversations?.get(0)!!.query } else { @@ -55,9 +55,9 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List viewHolderChat.rowChatHistoryBinding.root.setOnClickListener { chatHistoryItemClickListener?.onChatHistoryItemClicked( - filteredChatHistory[position].conversations!!, - filteredChatHistory[position]._id.toString(), - filteredChatHistory[position]._rev!! + filteredChatHistory[position].conversations, + "${filteredChatHistory[position]._id}", + filteredChatHistory[position]._rev ) } } 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 a0ac516385..995e76a315 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 @@ -64,10 +64,10 @@ class ChatHistoryListFragment : Fragment() { } val adapter = ChatHistoryListAdapter(requireContext(), list) adapter.setChatHistoryItemClickListener(object : ChatHistoryListAdapter.ChatHistoryItemClickListener { - override fun onChatHistoryItemClicked(conversations: RealmList, _id: String, _rev:String) { - sharedViewModel.setSelectedChatHistory(conversations) + override fun onChatHistoryItemClicked(conversations: RealmList?, _id: String, _rev:String?) { + conversations?.let { sharedViewModel.setSelectedChatHistory(it) } sharedViewModel.setSelected_id(_id) - sharedViewModel.setSelected_rev(_rev) + _rev?.let { sharedViewModel.setSelected_rev(it) } fragmentChatHistoryListBinding.slidingPaneLayout.openPane() }