Skip to content

Commit

Permalink
chat: stabler with safe call operators (fixes #3242) (#3246)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Mar 14, 2024
1 parent 5abd7d7 commit b7b531f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List
private var filteredChatHistory: List<RealmChatHistory> = chatHistory

interface ChatHistoryItemClickListener {
fun onChatHistoryItemClicked(conversations: RealmList<Conversation>, _id: String, _rev: String)
fun onChatHistoryItemClicked(conversations: RealmList<Conversation>?, _id: String, _rev: String?)
}

fun setChatHistoryItemClickListener(listener: ChatHistoryItemClickListener) {
Expand All @@ -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()
Expand All @@ -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 {
Expand All @@ -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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class ChatHistoryListFragment : Fragment() {
}
val adapter = ChatHistoryListAdapter(requireContext(), list)
adapter.setChatHistoryItemClickListener(object : ChatHistoryListAdapter.ChatHistoryItemClickListener {
override fun onChatHistoryItemClicked(conversations: RealmList<Conversation>, _id: String, _rev:String) {
sharedViewModel.setSelectedChatHistory(conversations)
override fun onChatHistoryItemClicked(conversations: RealmList<Conversation>?, _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()
}
Expand Down

0 comments on commit b7b531f

Please sign in to comment.