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
f6125494
Commit
f6125494
authored
Dec 10, 2025
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:处理重复加载数据,(有个别用户出现返回再打开后短信列表数据清空问题)
parent
d0f67c58
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
13 deletions
+21
-13
MainActivity.kt
...c/main/kotlin/com/secspace/sms/activities/MainActivity.kt
+21
-13
No files found.
app/src/main/kotlin/com/secspace/sms/activities/MainActivity.kt
View file @
f6125494
...
...
@@ -8,10 +8,8 @@ import android.content.pm.ShortcutInfo
import
android.database.Cursor
import
android.graphics.drawable.Icon
import
android.graphics.drawable.LayerDrawable
import
android.net.Uri
import
android.os.Build
import
android.os.Bundle
import
android.os.Handler
import
android.provider.Settings
import
android.provider.Telephony
import
android.text.TextUtils
...
...
@@ -27,7 +25,6 @@ import com.secspace.sms.databinding.ActivityMainBinding
import
com.secspace.sms.extensions.*
import
com.secspace.sms.helpers.*
import
com.secspace.sms.models.*
import
com.secspace.sms.receivers.SmsSendObserver
import
com.secspace.sms.shortcut.ShortCutActivity
import
com.secspace.sms.util.PhoneFromUtil
import
com.secspace.sms.util.PhoneUtils
...
...
@@ -76,9 +73,11 @@ class MainActivity : SimpleActivity() {
if
(
savedInstanceState
==
null
)
{
checkAndDeleteOldRecycleBinMessages
()
handleAppPasswordProtection
{
Log
.
d
(
TAG
,
"onCreate: handleAppPasswordProtection = $it"
)
wasProtectionHandled
=
it
if
(
it
)
{
clearAllMessagesIfNeeded
{
Log
.
d
(
TAG
,
"onCreate: clearAllMessagesIfNeeded"
)
loadMessages
()
}
}
else
{
...
...
@@ -111,7 +110,6 @@ class MainActivity : SimpleActivity() {
startActivity(intent)
}*/
initMessenger
()
updateMenuColors
()
refreshMenuItems
()
...
...
@@ -171,6 +169,7 @@ class MainActivity : SimpleActivity() {
override
fun
onRestoreInstanceState
(
savedInstanceState
:
Bundle
)
{
super
.
onRestoreInstanceState
(
savedInstanceState
)
wasProtectionHandled
=
savedInstanceState
.
getBoolean
(
WAS_PROTECTION_HANDLED
,
false
)
Log
.
d
(
TAG
,
"onRestoreInstanceState: wasProtectionHandled = $wasProtectionHandled "
)
if
(!
wasProtectionHandled
)
{
handleAppPasswordProtection
{
...
...
@@ -250,6 +249,7 @@ class MainActivity : SimpleActivity() {
@RequiresApi
(
Build
.
VERSION_CODES
.
Q
)
private
fun
loadMessages
()
{
Log
.
d
(
TAG
,
"loadMessages: isQPlus = ${isQPlus()}"
)
if
(
isQPlus
())
{
val
roleManager
=
getSystemService
(
RoleManager
::
class
.
java
)
if
(
roleManager
!!
.
isRoleAvailable
(
RoleManager
.
ROLE_SMS
))
{
...
...
@@ -290,7 +290,7 @@ class MainActivity : SimpleActivity() {
}
}
//
initMessenger()
initMessenger
()
bus
=
EventBus
.
getDefault
()
try
{
bus
!!
.
register
(
this
)
...
...
@@ -325,15 +325,20 @@ class MainActivity : SimpleActivity() {
val
conversations
=
try
{
conversationsDB
.
getNonArchived
().
toMutableList
()
as
ArrayList
<
Conversation
>
}
catch
(
e
:
Exception
)
{
Log
.
d
(
TAG
,
"getCachedConversations: catch 出问题了! 返回空数据 info = ${e.message}"
)
ArrayList
()
}
Log
.
d
(
TAG
,
"getCachedConversations: conversations = ${Gson().toJson(conversations)}"
)
Log
.
d
(
TAG
,
"getCachedConversations: 列表数据长度 = ${conversations.size} toJson conversations = ${Gson().toJson(conversations)}"
)
if
(
conversations
.
isEmpty
())
{
Log
.
e
(
TAG
,
"getCachedConversations: 当前短信列表数据为空 "
)
}
val
archived
=
try
{
conversationsDB
.
getAllArchived
()
}
catch
(
e
:
Exception
)
{
listOf
()
}
Log
.
d
(
TAG
,
"getCachedConversations: archived = ${Gson().toJson(archived)}"
)
if
(
archived
.
isNotEmpty
())
Log
.
d
(
TAG
,
"getCachedConversations: archived = ${Gson().toJson(archived)}"
)
// runOnUiThread {
// setupConversations(conversations, cached = true)
...
...
@@ -405,7 +410,7 @@ class MainActivity : SimpleActivity() {
}
val
allConversations
=
conversationsDB
.
getNonArchived
()
as
ArrayList
<
Conversation
>
Log
.
d
(
TAG
,
"getNewConversations allConversations = ${GsonUtil.parseListToJson(allConversations)} "
)
Log
.
d
(
TAG
,
"getNewConversations
获取所有列表长度 = ${allConversations.size} toJson
allConversations = ${GsonUtil.parseListToJson(allConversations)} "
)
setupConversations
(
allConversations
)
//未读消息 桌面Icon提示
...
...
@@ -515,7 +520,7 @@ class MainActivity : SimpleActivity() {
compareByDescending
<
Conversation
>
{
config
.
pinnedConversations
.
contains
(
it
.
threadId
.
toString
())
}
.
thenByDescending
{
it
.
date
}
).
toMutableList
()
as
ArrayList
<
Conversation
>
Log
.
d
(
TAG
,
"setupConversations: sortedConversations = ${sortedConversations.size}"
)
setFirstConversationAndUpdateData
(
sortedConversations
)
//根据记录被删除的会话手机号,从会话列表中判断手机号是否一致,满足就脱敏手机号(为了解决荣耀云备份后恢复,手机号未脱敏的情况)
...
...
@@ -548,7 +553,9 @@ class MainActivity : SimpleActivity() {
try
{
getOrCreateConversationsAdapter
().
apply
{
Log
.
d
(
TAG
,
"setupConversations: 短信列表数量 = ${sortedConversations.size}"
)
updateConversations
(
sortedConversations
)
{
Log
.
d
(
TAG
,
"setupConversations: cached = ${!cached}"
)
if
(!
cached
)
{
showOrHidePlaceholder
(
currentList
.
isEmpty
())
}
...
...
@@ -601,9 +608,9 @@ class MainActivity : SimpleActivity() {
val
listContains
:
List
<
Message
>
=
listMessageData
.
filter
{
msg
->
msg
.
body
.
contains
(
"\u200B"
)
}
Log
.
d
(
TAG
,
"handleConversationClick: 是否包含零宽度字符 = ${listContains.isNotEmpty()}"
)
if
(
listContains
.
isNotEmpty
()
||
conversation
.
isSFNumber
)
{
if
(
userName
.
isNotBlank
()
&&
!
PhoneFromUtil
.
isNumeric
(
userName
))
{
if
(
userName
.
isNotBlank
()
&&
!
PhoneFromUtil
.
isNumeric
(
userName
))
{
putExtra
(
THREAD_TITLE
,
userName
)
}
else
{
}
else
{
val
phoneNumber
=
conversation
.
title
if
(
phoneNumber
.
contains
(
"+86"
))
{
phoneNumber
.
replace
(
"+86"
,
""
)
...
...
@@ -690,7 +697,8 @@ class MainActivity : SimpleActivity() {
val
searchResults
=
ArrayList
<
SearchResult
>()
conversations
.
forEach
{
conversation
->
val
date
=
conversation
.
date
.
formatDateOrTime
(
this
,
true
,
true
)
val
searchResult
=
SearchResult
(-
1
,
conversation
.
title
,
conversation
.
phoneNumber
,
date
,
conversation
.
threadId
,
conversation
.
photoUri
,
conversation
.
isSFNumber
)
val
searchResult
=
SearchResult
(-
1
,
conversation
.
title
,
conversation
.
phoneNumber
,
date
,
conversation
.
threadId
,
conversation
.
photoUri
,
conversation
.
isSFNumber
)
searchResults
.
add
(
searchResult
)
}
Log
.
d
(
TAG
,
"setupOptionsMenu 搜索消息 conversations searchResults = ${GsonUtil.parseListToJson(searchResults)} "
)
...
...
@@ -766,7 +774,7 @@ class MainActivity : SimpleActivity() {
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
fun
refreshMessages
(
event
:
Events
.
RefreshMessages
)
{
// Log.d(TAG, "----MainActivity----refreshMessages EventBus
")
Log
.
d
(
TAG
,
"refreshMessages:
"
)
initMessenger
()
}
...
...
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