Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Simple-Sms
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangchengbo
Simple-Sms
Commits
8c3c5511
Commit
8c3c5511
authored
Nov 29, 2024
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:1.获取最新短信 与通话记录中对比数据进行掩码操作 2.更新列表最新一条的数据
parent
1d680f4e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
71 deletions
+77
-71
MainActivity.kt
...c/main/kotlin/com/secspace/sms/activities/MainActivity.kt
+77
-71
No files found.
app/src/main/kotlin/com/secspace/sms/activities/MainActivity.kt
View file @
8c3c5511
...
...
@@ -305,7 +305,7 @@ class MainActivity : SimpleActivity() {
updateUnreadCountBadge
(
conversations
)
// runOnUiThread {
// setupConversations(conversations, cached = true)
getNewConversations
((
conversations
+
archived
).
toMutableList
()
as
ArrayList
<
Conversation
>)
getNewConversations
((
conversations
+
archived
).
toMutableList
()
as
ArrayList
<
Conversation
>)
// }
conversations
.
forEach
{
clearExpiredScheduledMessages
(
it
.
threadId
)
...
...
@@ -316,74 +316,74 @@ class MainActivity : SimpleActivity() {
private
fun
getNewConversations
(
cachedConversations
:
ArrayList
<
Conversation
>)
{
val
privateCursor
=
getMyContactsCursor
(
favoritesOnly
=
false
,
withPhoneNumbersOnly
=
true
)
val
privateContacts
=
MyContactsContentProvider
.
getSimpleContacts
(
this
@MainActivity
,
privateCursor
)
val
privateContacts
=
MyContactsContentProvider
.
getSimpleContacts
(
this
@MainActivity
,
privateCursor
)
// Log.e(TAG, " getNewConversations privateContacts:${GsonUtil.parseListToJson(privateContacts)}")
//获取系统SMS DB短信列表
val
conversations
:
java
.
util
.
ArrayList
<
Conversation
>
=
getConversations
(
privateContacts
=
privateContacts
)
//获取系统SMS DB短信列表
val
conversations
:
java
.
util
.
ArrayList
<
Conversation
>
=
getConversations
(
privateContacts
=
privateContacts
)
// Log.e(TAG, " getNewConversations 获取系统SMS DB短信列表(脏数据) conversations:${GsonUtil.parseListToJson(conversations)}")
//通过DB数据与cache对比threadID
conversations
.
forEach
{
clonedConversation
->
val
threadIds
=
cachedConversations
.
map
{
it
.
threadId
}
if
(!
threadIds
.
contains
(
clonedConversation
.
threadId
))
{
conversationsDB
.
insertOrUpdate
(
clonedConversation
)
cachedConversations
.
add
(
clonedConversation
)
}
//通过DB数据与cache对比threadID
conversations
.
forEach
{
clonedConversation
->
val
threadIds
=
cachedConversations
.
map
{
it
.
threadId
}
if
(!
threadIds
.
contains
(
clonedConversation
.
threadId
))
{
conversationsDB
.
insertOrUpdate
(
clonedConversation
)
cachedConversations
.
add
(
clonedConversation
)
}
}
cachedConversations
.
forEach
{
cachedConversation
->
val
threadId
=
cachedConversation
.
threadId
cachedConversations
.
forEach
{
cachedConversation
->
val
threadId
=
cachedConversation
.
threadId
val
isTemporaryThread
=
cachedConversation
.
isScheduled
val
isConversationDeleted
=
!
conversations
.
map
{
it
.
threadId
}.
contains
(
threadId
)
if
(
isConversationDeleted
&&
!
isTemporaryThread
)
{
conversationsDB
.
deleteThreadId
(
threadId
)
}
val
isTemporaryThread
=
cachedConversation
.
isScheduled
val
isConversationDeleted
=
!
conversations
.
map
{
it
.
threadId
}.
contains
(
threadId
)
if
(
isConversationDeleted
&&
!
isTemporaryThread
)
{
conversationsDB
.
deleteThreadId
(
threadId
)
}
val
newConversation
:
Conversation
?
=
conversations
.
find
{
it
.
phoneNumber
==
cachedConversation
.
phoneNumber
}
if
(
isTemporaryThread
&&
newConversation
!=
null
)
{
// delete the original temporary thread and move any scheduled messages to the new thread
conversationsDB
.
deleteThreadId
(
threadId
)
messagesDB
.
getScheduledThreadMessages
(
threadId
)
.
forEach
{
message
->
messagesDB
.
insertOrUpdate
(
message
.
copy
(
threadId
=
newConversation
.
threadId
))
}
insertOrUpdateConversation
(
newConversation
,
cachedConversation
)
}
val
newConversation
:
Conversation
?
=
conversations
.
find
{
it
.
phoneNumber
==
cachedConversation
.
phoneNumber
}
if
(
isTemporaryThread
&&
newConversation
!=
null
)
{
// delete the original temporary thread and move any scheduled messages to the new thread
conversationsDB
.
deleteThreadId
(
threadId
)
messagesDB
.
getScheduledThreadMessages
(
threadId
)
.
forEach
{
message
->
messagesDB
.
insertOrUpdate
(
message
.
copy
(
threadId
=
newConversation
.
threadId
))
}
insertOrUpdateConversation
(
newConversation
,
cachedConversation
)
}
}
cachedConversations
.
forEach
{
cachedConv
->
val
conv
=
conversations
.
find
{
it
.
threadId
==
cachedConv
.
threadId
&&
!
Conversation
.
areContentsTheSame
(
cachedConv
,
it
)
}
cachedConversations
.
forEach
{
cachedConv
->
val
conv
=
conversations
.
find
{
it
.
threadId
==
cachedConv
.
threadId
&&
!
Conversation
.
areContentsTheSame
(
cachedConv
,
it
)
}
// Log.e(TAG, " getNewConversations 对比后的结果(新数据)222 find conv:${GsonUtil.parseBeanToJson(conv)}")
if
(
conv
!=
null
&&
conv
.
isSFNumber
)
{
if
(
conv
!=
null
&&
conv
.
isSFNumber
)
{
// Log.e(TAG, " conversations find it conv:${GsonUtil.parseBeanToJson(conv)}")
val
lastModified
=
maxOf
(
cachedConv
.
date
,
conv
.
date
)
val
conversation
=
conv
.
copy
(
date
=
lastModified
)
val
lastModified
=
maxOf
(
cachedConv
.
date
,
conv
.
date
)
val
conversation
=
conv
.
copy
(
date
=
lastModified
)
// Log.e(
// TAG,
// " getNewConversations 对比后的结果(新数据) isSFNumber=${conv.isSFNumber} find conversation:${GsonUtil.parseBeanToJson(conversation)}"
// )
insertOrUpdateConversation
(
conversation
)
}
insertOrUpdateConversation
(
conversation
)
}
val
allConversations
=
conversationsDB
.
getNonArchived
()
as
ArrayList
<
Conversation
>
}
val
allConversations
=
conversationsDB
.
getNonArchived
()
as
ArrayList
<
Conversation
>
// Log.e(TAG, "----MainActivity----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}")
// runOnUiThread {
setupConversations
(
allConversations
)
setupConversations
(
allConversations
)
// }
// Log.e(TAG, "----MainActivity----handleMessage appRunCount:${config.appRunCount}")
if
(
config
.
appRunCount
==
1
)
{
conversations
.
map
{
it
.
threadId
}.
forEach
{
threadId
->
val
messages
=
getMessages
(
threadId
,
getImageResolutions
=
false
,
includeScheduledMessages
=
false
)
messages
.
chunked
(
30
).
forEach
{
currentMessages
:
List
<
Message
>
->
messagesDB
.
insertMessages
(*
currentMessages
.
toTypedArray
())
}
if
(
config
.
appRunCount
==
1
)
{
conversations
.
map
{
it
.
threadId
}.
forEach
{
threadId
->
val
messages
=
getMessages
(
threadId
,
getImageResolutions
=
false
,
includeScheduledMessages
=
false
)
messages
.
chunked
(
30
).
forEach
{
currentMessages
:
List
<
Message
>
->
messagesDB
.
insertMessages
(*
currentMessages
.
toTypedArray
())
}
}
}
}
private
fun
getOrCreateConversationsAdapter
():
ConversationsAdapter
{
var
currAdapter
=
binding
.
conversationsList
.
adapter
...
...
@@ -404,41 +404,31 @@ class MainActivity : SimpleActivity() {
return
currAdapter
as
ConversationsAdapter
}
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
>
//确保排序后的短信列表是有数据的
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)}")
// }
/**
* 1.获取最新短信 与通话记录中对比数据进行掩码操作
* 2.更新列表最新一条的数据
*/
private
fun
setFirstConversationAndUpdateData
(
sortedConversations
:
ArrayList
<
Conversation
>)
{
val
hasPerMissionResult
=
this
@MainActivity
.
hasPermission
(
PERMISSION_READ_CALL_LOG
)
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
(
" "
,
""
)
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
>
->
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
}
Log
.
d
(
TAG
,
"----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}"
)
//从最近通话记录中找到了号码 进行掩码操作
if
(
findResult
!=
null
)
{
PhoneUtils
.
phoneNumberFormat
(
phoneNumber
)
{
itNumber
->
firstConversation
.
phoneNumber
=
itNumber
firstConversation
.
isSFNumber
=
true
conversationsDB
.
insertOrUpdate
(
firstConversation
)
Log
.
d
(
TAG
,
"----MainActivity----手机号掩码操作 itNumber:${itNumber} phoneNumber:${firstConversation.phoneNumber} threadId:${firstConversation.threadId} "
...
...
@@ -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
)
{
// delay(1_000)
Log
.
d
(
TAG
,
" MainActivity setupConversations() 修改后显示短信列表数据 =: ${GsonUtil.parseListToJson(sortedConversations)}"
)
Log
.
d
(
TAG
,
" MainActivity setupConversations() 修改后显示短信列表数据 =: ${GsonUtil.parseListToJson(sortedConversations)}"
)
// runOnUiThread {
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
showOrHideProgress
(
conversations
.
isEmpty
())
...
...
@@ -634,7 +641,6 @@ class MainActivity : SimpleActivity() {
startActivity
(
Intent
(
applicationContext
,
SettingsActivity
::
class
.
java
))
}
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
fun
refreshMessages
(
event
:
Events
.
RefreshMessages
)
{
// Log.e(TAG, "----MainActivity----refreshMessages EventBus")
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment