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,23 +518,27 @@ class MainActivity : SimpleActivity() { ...@@ -520,23 +518,27 @@ 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)}")
setFirstConversationAndUpdateData(sortedConversations)
//加载缓存数据不执行此处
//根据记录被删除的会话手机号,从会话列表中判断手机号是否一致,满足就脱敏手机号(为了解决荣耀云备份后恢复,手机号未脱敏的情况) if (!cached) {
val listMsgIdAll: String? = Config.newInstance(this@MainActivity).listDeleteMsgIdAllData //根据最新的短信 是否需要对手机号掩码及db bean修改
Log.d(TAG, "setupConversations 云备份 获取被删除的会话集合 listMsgIdAll 不等于空 = ${!listMsgIdAll.isNullOrEmpty()}") setFirstConversationAndUpdateData(sortedConversations)
if (!listMsgIdAll.isNullOrEmpty()) {
val listData: ArrayList<String> = listMsgIdAll.split(",").toArrayList() //根据记录被删除的会话手机号,从会话列表中判断手机号是否一致,满足就脱敏手机号(为了解决荣耀云备份后恢复,手机号未脱敏的情况)
Log.d(TAG, "setupConversations 云备份 split listData = ${listData}") val listMsgIdAll: String? = Config.newInstance(this@MainActivity).listDeleteMsgIdAllData
if (listData.isNotEmpty()) { Log.d(TAG, "setupConversations 云备份 获取被删除的会话集合 listMsgIdAll 不等于空 = ${!listMsgIdAll.isNullOrEmpty()}")
val listConversationData: List<Conversation> = conversations.filter { listData.contains(it.phoneNumber) } if (!listMsgIdAll.isNullOrEmpty()) {
Log.d(TAG, "setupConversations 云备份 找到被删除的 ListConversation 会话 = ${Gson().toJson(listConversationData)}") val listData: ArrayList<String> = listMsgIdAll.split(",").toArrayList()
if (listConversationData.isNotEmpty()) { Log.d(TAG, "setupConversations 云备份 split listData = ${listData}")
listConversationData.forEach { conversation -> if (listData.isNotEmpty()) {
// Constant.listThreadData.remove(conversation.phoneNumber) val listConversationData: List<Conversation> = conversations.filter { listData.contains(it.phoneNumber) }
conversation.isSFNumber = true Log.d(TAG, "setupConversations 云备份 找到被删除的 ListConversation 会话 = ${Gson().toJson(listConversationData)}")
conversationsDB.insertOrUpdate(conversation) if (listConversationData.isNotEmpty()) {
listConversationData.forEach { conversation ->
conversation.isSFNumber = true
conversationsDB.insertOrUpdate(conversation)
}
} }
} }
} }
...@@ -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,31 +604,43 @@ class MainActivity : SimpleActivity() { ...@@ -602,31 +604,43 @@ 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}")
val listMessageData = getMessages(conversation.threadId, false) ensureBackgroundThread {
Log.d(TAG, "handleConversationClick: listMessageData是否为空 = ${listMessageData.isNotEmpty()}") val listMessageData = getMessages(conversation.threadId, false)
if (listMessageData.isNotEmpty()) { Log.d(TAG, "handleConversationClick: listMessageData是否为空 = ${listMessageData.isNotEmpty()}")
val listContains: List<Message> = listMessageData.filter { msg -> msg.body.contains("\u200B") } if (listMessageData.isNotEmpty()) {
Log.d(TAG, "handleConversationClick: 是否包含零宽度字符 = ${listContains.isNotEmpty()}") val listContains: List<Message> = listMessageData.filter { msg -> msg.body.contains("\u200B") }
if (listContains.isNotEmpty() || conversation.isSFNumber) { Log.d(TAG, "handleConversationClick: 是否包含零宽度字符 = ${listContains.isNotEmpty()}")
if (userName.isNotBlank() && !PhoneFromUtil.isNumeric(userName)) { if (listContains.isNotEmpty() || conversation.isSFNumber) {
putExtra(THREAD_TITLE, userName) if (userName.isNotBlank() && !PhoneFromUtil.isNumeric(userName)) {
} else { putExtra(THREAD_TITLE, userName)
val phoneNumber = conversation.title } else {
if (phoneNumber.contains("+86")) { val phoneNumber = conversation.title
phoneNumber.replace("+86", "") if (phoneNumber.contains("+86")) {
phoneNumber.replace("+86", "")
}
PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber ->
putExtra(THREAD_TITLE, itNumber)
}
} }
PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber -> } else {
putExtra(THREAD_TITLE, itNumber) if (userName.isNotBlank()) {
putExtra(THREAD_TITLE, userName)
} else {
putExtra(THREAD_TITLE, conversation.title)
} }
} }
} else {
if (userName.isNotBlank()) {
putExtra(THREAD_TITLE, userName)
} else {
putExtra(THREAD_TITLE, conversation.title)
}
} }
} else {
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)
}
} }
} }
......
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