Commit 9cadb3d2 by zhangchengbo

fix:1.优先加载缓存数据,会话详情页标题优先取通讯录备注名称

2.点击跳转对DB操作 在子线程闭包执行
parent 480a52e2
...@@ -340,10 +340,8 @@ class MainActivity : SimpleActivity() { ...@@ -340,10 +340,8 @@ class MainActivity : SimpleActivity() {
if (archived.isNotEmpty()) if (archived.isNotEmpty())
Log.d(TAG, "getCachedConversations: archived = ${Gson().toJson(archived)}") Log.d(TAG, "getCachedConversations: archived = ${Gson().toJson(archived)}")
// runOnUiThread { setupConversations(conversations, cached = true)
// setupConversations(conversations, cached = true)
getNewConversations((conversations + archived).toMutableList() as ArrayList<Conversation>) getNewConversations((conversations + archived).toMutableList() as ArrayList<Conversation>)
// }
conversations.forEach { conversations.forEach {
clearExpiredScheduledMessages(it.threadId) clearExpiredScheduledMessages(it.threadId)
} }
...@@ -358,7 +356,7 @@ class MainActivity : SimpleActivity() { ...@@ -358,7 +356,7 @@ class MainActivity : SimpleActivity() {
val privateContacts = MyContactsContentProvider.getSimpleContacts(this@MainActivity, privateCursor) val privateContacts = MyContactsContentProvider.getSimpleContacts(this@MainActivity, privateCursor)
Log.d(TAG, " getNewConversations privateContacts:${GsonUtil.parseListToJson(privateContacts)}") Log.d(TAG, " getNewConversations privateContacts:${GsonUtil.parseListToJson(privateContacts)}")
//获取系统SMS DB短信列表 //获取系统SMS DB短信列表,根据手机号检测通讯录备注名称
val conversations: java.util.ArrayList<Conversation> = getConversations(privateContacts = privateContacts) val conversations: java.util.ArrayList<Conversation> = getConversations(privateContacts = privateContacts)
Log.d(TAG, " getNewConversations 获取系统SMS DB短信列表(脏数据) conversations:${GsonUtil.parseListToJson(conversations)}") Log.d(TAG, " getNewConversations 获取系统SMS DB短信列表(脏数据) conversations:${GsonUtil.parseListToJson(conversations)}")
...@@ -520,7 +518,11 @@ class MainActivity : SimpleActivity() { ...@@ -520,7 +518,11 @@ class MainActivity : SimpleActivity() {
compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) } compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) }
.thenByDescending { it.date } .thenByDescending { it.date }
).toMutableList() as ArrayList<Conversation> ).toMutableList() as ArrayList<Conversation>
Log.d(TAG, "setupConversations: sortedConversations = ${sortedConversations.size}") Log.d(TAG, "setupConversations: sortedConversations = ${sortedConversations.size} toJson = ${Gson().toJson(sortedConversations)}")
//加载缓存数据不执行此处
if (!cached) {
//根据最新的短信 是否需要对手机号掩码及db bean修改
setFirstConversationAndUpdateData(sortedConversations) setFirstConversationAndUpdateData(sortedConversations)
//根据记录被删除的会话手机号,从会话列表中判断手机号是否一致,满足就脱敏手机号(为了解决荣耀云备份后恢复,手机号未脱敏的情况) //根据记录被删除的会话手机号,从会话列表中判断手机号是否一致,满足就脱敏手机号(为了解决荣耀云备份后恢复,手机号未脱敏的情况)
...@@ -534,13 +536,13 @@ class MainActivity : SimpleActivity() { ...@@ -534,13 +536,13 @@ class MainActivity : SimpleActivity() {
Log.d(TAG, "setupConversations 云备份 找到被删除的 ListConversation 会话 = ${Gson().toJson(listConversationData)}") Log.d(TAG, "setupConversations 云备份 找到被删除的 ListConversation 会话 = ${Gson().toJson(listConversationData)}")
if (listConversationData.isNotEmpty()) { if (listConversationData.isNotEmpty()) {
listConversationData.forEach { conversation -> listConversationData.forEach { conversation ->
// Constant.listThreadData.remove(conversation.phoneNumber)
conversation.isSFNumber = true conversation.isSFNumber = true
conversationsDB.insertOrUpdate(conversation) conversationsDB.insertOrUpdate(conversation)
} }
} }
} }
} }
}
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
if (cached && config.appRunCount == 1) { if (cached && config.appRunCount == 1) {
...@@ -553,7 +555,7 @@ class MainActivity : SimpleActivity() { ...@@ -553,7 +555,7 @@ class MainActivity : SimpleActivity() {
try { try {
getOrCreateConversationsAdapter().apply { getOrCreateConversationsAdapter().apply {
Log.d(TAG, "setupConversations: 短信列表数量 = ${sortedConversations.size}") Log.d(TAG, "setupConversations: 短信列表数量 = ${sortedConversations.size} toJson = ${Gson().toJson(sortedConversations)}")
updateConversations(sortedConversations) { updateConversations(sortedConversations) {
Log.d(TAG, "setupConversations: cached = ${!cached}") Log.d(TAG, "setupConversations: cached = ${!cached}")
if (!cached) { if (!cached) {
...@@ -602,6 +604,7 @@ class MainActivity : SimpleActivity() { ...@@ -602,6 +604,7 @@ class MainActivity : SimpleActivity() {
Log.d(TAG, "handleConversationClick: conversation = ${Gson().toJson(conversation)}") Log.d(TAG, "handleConversationClick: conversation = ${Gson().toJson(conversation)}")
val userName = conversation.userName val userName = conversation.userName
Log.d(TAG, "handleConversationClick: 通讯录备注名称 = $userName 短信内容 = ${conversation.snippet} threadId = ${conversation.threadId}") Log.d(TAG, "handleConversationClick: 通讯录备注名称 = $userName 短信内容 = ${conversation.snippet} threadId = ${conversation.threadId}")
ensureBackgroundThread {
val listMessageData = getMessages(conversation.threadId, false) val listMessageData = getMessages(conversation.threadId, false)
Log.d(TAG, "handleConversationClick: listMessageData是否为空 = ${listMessageData.isNotEmpty()}") Log.d(TAG, "handleConversationClick: listMessageData是否为空 = ${listMessageData.isNotEmpty()}")
if (listMessageData.isNotEmpty()) { if (listMessageData.isNotEmpty()) {
...@@ -619,16 +622,27 @@ class MainActivity : SimpleActivity() { ...@@ -619,16 +622,27 @@ class MainActivity : SimpleActivity() {
putExtra(THREAD_TITLE, itNumber) putExtra(THREAD_TITLE, itNumber)
} }
} }
} else {
if (userName.isNotBlank()) {
putExtra(THREAD_TITLE, userName)
} else {
putExtra(THREAD_TITLE, conversation.title)
}
} }
} else { } else {
if (userName.isNotBlank()) {
putExtra(THREAD_TITLE, userName)
} else {
putExtra(THREAD_TITLE, conversation.title) putExtra(THREAD_TITLE, conversation.title)
} }
}
putExtra(THREAD_ID, conversation.threadId) putExtra(THREAD_ID, conversation.threadId)
putExtra(WAS_PROTECTION_HANDLED, wasProtectionHandled) putExtra(WAS_PROTECTION_HANDLED, wasProtectionHandled)
startActivity(this) startActivity(this)
} }
} }
}
private fun launchNewConversation() { private fun launchNewConversation() {
hideKeyboard() hideKeyboard()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment