mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-01-31 17:44:46 +01:00
adding message Id to search results
This commit is contained in:
parent
ad3812abb5
commit
2990f3be6e
@ -19,6 +19,8 @@ import com.simplemobiletools.smsmessenger.extensions.conversationsDB
|
|||||||
import com.simplemobiletools.smsmessenger.extensions.messagesDB
|
import com.simplemobiletools.smsmessenger.extensions.messagesDB
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_TITLE
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_TITLE
|
||||||
|
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||||
|
import com.simplemobiletools.smsmessenger.models.Message
|
||||||
import com.simplemobiletools.smsmessenger.models.SearchResult
|
import com.simplemobiletools.smsmessenger.models.SearchResult
|
||||||
import kotlinx.android.synthetic.main.activity_search.*
|
import kotlinx.android.synthetic.main.activity_search.*
|
||||||
|
|
||||||
@ -89,10 +91,21 @@ class SearchActivity : SimpleActivity() {
|
|||||||
val messages = messagesDB.getMessagesWithText(searchQuery)
|
val messages = messagesDB.getMessagesWithText(searchQuery)
|
||||||
val conversations = conversationsDB.getConversationsWithText(searchQuery)
|
val conversations = conversationsDB.getConversationsWithText(searchQuery)
|
||||||
if (text == mLastSearchedText) {
|
if (text == mLastSearchedText) {
|
||||||
|
showSearchResults(messages, conversations, text)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
search_placeholder.beVisible()
|
||||||
|
search_results_list.beGone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showSearchResults(messages: List<Message>, conversations: List<Conversation>, searchedText: String) {
|
||||||
val searchResults = ArrayList<SearchResult>()
|
val searchResults = ArrayList<SearchResult>()
|
||||||
conversations.forEach { conversation ->
|
conversations.forEach { conversation ->
|
||||||
val date = conversation.date.formatDateOrTime(this, true, true)
|
val date = conversation.date.formatDateOrTime(this, true, true)
|
||||||
val searchResult = SearchResult(conversation.title, conversation.phoneNumber, date, conversation.threadId, conversation.photoUri, conversation.isGroupConversation)
|
val searchResult = SearchResult(-1, conversation.title, conversation.phoneNumber, date, conversation.threadId, conversation.photoUri)
|
||||||
searchResults.add(searchResult)
|
searchResults.add(searchResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +117,7 @@ class SearchActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val date = message.date.formatDateOrTime(this, true, true)
|
val date = message.date.formatDateOrTime(this, true, true)
|
||||||
val searchResult = SearchResult(recipient, message.body, date, message.threadId, message.senderPhotoUri, false)
|
val searchResult = SearchResult(message.id, recipient, message.body, date, message.threadId, message.senderPhotoUri)
|
||||||
searchResults.add(searchResult)
|
searchResults.add(searchResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +127,7 @@ class SearchActivity : SimpleActivity() {
|
|||||||
|
|
||||||
val currAdapter = search_results_list.adapter
|
val currAdapter = search_results_list.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
SearchResultsAdapter(this, searchResults, search_results_list, text) {
|
SearchResultsAdapter(this, searchResults, search_results_list, searchedText) {
|
||||||
Intent(this, ThreadActivity::class.java).apply {
|
Intent(this, ThreadActivity::class.java).apply {
|
||||||
putExtra(THREAD_ID, (it as SearchResult).threadId)
|
putExtra(THREAD_ID, (it as SearchResult).threadId)
|
||||||
putExtra(THREAD_TITLE, it.title)
|
putExtra(THREAD_TITLE, it.title)
|
||||||
@ -124,14 +137,8 @@ class SearchActivity : SimpleActivity() {
|
|||||||
search_results_list.adapter = this
|
search_results_list.adapter = this
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(currAdapter as SearchResultsAdapter).updateItems(searchResults, text)
|
(currAdapter as SearchResultsAdapter).updateItems(searchResults, searchedText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
search_placeholder.beVisible()
|
|
||||||
search_results_list.beGone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
package com.simplemobiletools.smsmessenger.models
|
package com.simplemobiletools.smsmessenger.models
|
||||||
|
|
||||||
data class SearchResult(val title: String, val snippet: String, val date: String, val threadId: Long, var photoUri: String, var isGroupConversation: Boolean)
|
data class SearchResult(val messageId: Long, val title: String, val snippet: String, val date: String, val threadId: Long, var photoUri: String)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user