check if no message came from a privately stored contact in Simple Contacts
This commit is contained in:
parent
910aa365ac
commit
db90f0f08c
3 changed files with 13 additions and 1 deletions
|
|
@ -144,8 +144,19 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
private fun initMessenger() {
|
||||
storeStateVariables()
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
|
||||
ensureBackgroundThread {
|
||||
val conversations = getConversations()
|
||||
|
||||
// check if no message came from a privately stored contact in Simple Contacts
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
conversations.filter { it.title == it.phoneNumber }.forEach { conversation ->
|
||||
privateContacts.firstOrNull { it.phoneNumber == conversation.phoneNumber }?.apply {
|
||||
conversation.title = name
|
||||
}
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
val hasConversations = conversations.isNotEmpty()
|
||||
conversations_list.beVisibleIf(hasConversations)
|
||||
|
|
|
|||
|
|
@ -186,6 +186,7 @@ fun Context.getConversations(): ArrayList<Conversation> {
|
|||
val selection = "${Threads.MESSAGE_COUNT} > ?"
|
||||
val selectionArgs = arrayOf("0")
|
||||
val sortOrder = "${Threads.DATE} DESC"
|
||||
|
||||
val conversations = ArrayList<Conversation>()
|
||||
queryCursor(uri, projection, selection, selectionArgs, sortOrder, true) { cursor ->
|
||||
val id = cursor.getIntValue(Threads._ID)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package com.simplemobiletools.smsmessenger.models
|
||||
|
||||
data class Conversation(
|
||||
val id: Int, val snippet: String, val date: Int, val read: Boolean, val title: String, val photoUri: String,
|
||||
val id: Int, val snippet: String, val date: Int, val read: Boolean, var title: String, val photoUri: String,
|
||||
val isGroupConversation: Boolean, val phoneNumber: String)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue