Commit 8c3c5511 by zhangchengbo

fix:1.获取最新短信 与通话记录中对比数据进行掩码操作 2.更新列表最新一条的数据

parent 1d680f4e
...@@ -404,41 +404,31 @@ class MainActivity : SimpleActivity() { ...@@ -404,41 +404,31 @@ class MainActivity : SimpleActivity() {
return currAdapter as ConversationsAdapter return currAdapter as ConversationsAdapter
} }
private fun setupConversations(conversations: ArrayList<Conversation>, cached: Boolean = false) { /**
if (conversations.size == 0) return * 1.获取最新短信 与通话记录中对比数据进行掩码操作
* 2.更新列表最新一条的数据
val sortedConversations = conversations.sortedWith( */
compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) } private fun setFirstConversationAndUpdateData(sortedConversations: ArrayList<Conversation>) {
.thenByDescending { it.date }
).toMutableList() as ArrayList<Conversation>
//确保排序后的短信列表是有数据的
val firstConversation = sortedConversations.first()//获取第一条未掩码会话
Log.d(TAG, " MainActivity firstConversation() 获取第一条会话 =: ${GsonUtil.parseBeanToJson(firstConversation)}")
// val smsDraft: String? = getSmsDraft(firstConversation.threadId)
// ensureBackgroundThread {
// val newConv = conversationsDB.getNonArchived()
// Log.d(TAG, " MainActivity firstConversation() newConv 获取第一条会话 =: ${GsonUtil.parseBeanToJson(newConv)}")
// }
val hasPerMissionResult = this@MainActivity.hasPermission(PERMISSION_READ_CALL_LOG) val hasPerMissionResult = this@MainActivity.hasPermission(PERMISSION_READ_CALL_LOG)
if (hasPerMissionResult) { if (hasPerMissionResult) {
Log.d(TAG, " MainActivity firstConversation() 根据线程Id查询会话 threadID=:${firstConversation.threadId} ") val firstConversation = sortedConversations.first()//获取第一条未掩码会话
Log.d(TAG, " MainActivity firstConversation() 获取第一条会话 =: ${GsonUtil.parseBeanToJson(firstConversation)}")
val phoneNumber = firstConversation.title.replace(" ", "") val phoneNumber = firstConversation.title.replace(" ", "")
if (!firstConversation.isSFNumber && phoneNumber.length == 11) { //只针对手机号
Log.d(TAG, "----MainActivity----获取第一条会话 phoneNumber:$phoneNumber") if (phoneNumber.length != 11) return
if (!firstConversation.isSFNumber) {
Log.d(TAG, "----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber")
RecentsHelper(context = this@MainActivity).getRecentCalls(false, Int.MAX_VALUE) { recents: List<RecentCall> -> RecentsHelper(context = this@MainActivity).getRecentCalls(false, Int.MAX_VALUE) { recents: List<RecentCall> ->
val listCallRecent: List<RecentCall> = recents.distinctBy { it.phoneNumber } val listCallRecent: List<RecentCall> = recents.distinctBy { it.phoneNumber }
Log.d(TAG, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}") // Log.d(TAG, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}")
val findResult: RecentCall = listCallRecent.first { it.phoneNumber.trim() == phoneNumber && it.isShunFeng } val findResult: RecentCall = listCallRecent.first { it.phoneNumber.trim() == phoneNumber && it.isShunFeng }
Log.d(TAG, "----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}") Log.d(TAG, "----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}")
//从最近通话记录中找到了号码 进行掩码操作 //从最近通话记录中找到了号码 进行掩码操作
if (findResult != null) { if (findResult != null) {
PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber -> PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber ->
firstConversation.phoneNumber = itNumber firstConversation.phoneNumber = itNumber
firstConversation.isSFNumber = true firstConversation.isSFNumber = true
conversationsDB.insertOrUpdate(firstConversation)
Log.d( Log.d(
TAG, TAG,
"----MainActivity----手机号掩码操作 itNumber:${itNumber} phoneNumber:${firstConversation.phoneNumber} threadId:${firstConversation.threadId} " "----MainActivity----手机号掩码操作 itNumber:${itNumber} phoneNumber:${firstConversation.phoneNumber} threadId:${firstConversation.threadId} "
...@@ -447,13 +437,30 @@ class MainActivity : SimpleActivity() { ...@@ -447,13 +437,30 @@ class MainActivity : SimpleActivity() {
} }
} }
} }
//根据最新的短信threadId 获取所有短信列表 取最新一条记录
val messages: java.util.ArrayList<Message> = getMessages(firstConversation.threadId, true)
Log.e(TAG, " MainActivity getMessages() 执行查询会话 messages 数据库 =:${GsonUtil.parseListToJson(messages)} ")
val lastMsg = messages.last()
firstConversation.snippet = lastMsg.body
firstConversation.date = lastMsg.date
conversationsDB.insertOrUpdate(firstConversation)
}
} }
private fun setupConversations(conversations: ArrayList<Conversation>, cached: Boolean = false) {
if (conversations.size == 0) return
val sortedConversations = conversations.sortedWith(
compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) }
.thenByDescending { it.date }
).toMutableList() as ArrayList<Conversation>
setFirstConversationAndUpdateData(conversations)
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
// delay(1_000) // delay(1_000)
Log.d(TAG, " MainActivity setupConversations() 修改后显示短信列表数据 =: ${GsonUtil.parseListToJson(sortedConversations)}") Log.d(TAG, " MainActivity setupConversations() 修改后显示短信列表数据 =: ${GsonUtil.parseListToJson(sortedConversations)}")
// runOnUiThread { // runOnUiThread {
if (cached && config.appRunCount == 1) { if (cached && config.appRunCount == 1) {
// there are no cached conversations on the first run so we show the loading placeholder and progress until we are done loading from telephony // there are no cached conversations on the first run so we show the loading placeholder and progress until we are done loading from telephony
showOrHideProgress(conversations.isEmpty()) showOrHideProgress(conversations.isEmpty())
...@@ -634,7 +641,6 @@ class MainActivity : SimpleActivity() { ...@@ -634,7 +641,6 @@ class MainActivity : SimpleActivity() {
startActivity(Intent(applicationContext, SettingsActivity::class.java)) startActivity(Intent(applicationContext, SettingsActivity::class.java))
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun refreshMessages(event: Events.RefreshMessages) { fun refreshMessages(event: Events.RefreshMessages) {
// Log.e(TAG, "----MainActivity----refreshMessages EventBus") // Log.e(TAG, "----MainActivity----refreshMessages EventBus")
......
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