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
e5636151
Commit
e5636151
authored
Aug 05, 2025
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:注册 Observe
parent
3ff54263
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
22 deletions
+13
-22
MainActivity.kt
...c/main/kotlin/com/secspace/sms/activities/MainActivity.kt
+13
-22
No files found.
app/src/main/kotlin/com/secspace/sms/activities/MainActivity.kt
View file @
e5636151
...
@@ -5,8 +5,10 @@ import android.app.Activity
...
@@ -5,8 +5,10 @@ import android.app.Activity
import
android.app.role.RoleManager
import
android.app.role.RoleManager
import
android.content.Intent
import
android.content.Intent
import
android.database.Cursor
import
android.database.Cursor
import
android.net.Uri
import
android.os.Build
import
android.os.Build
import
android.os.Bundle
import
android.os.Bundle
import
android.os.Handler
import
android.provider.Settings
import
android.provider.Settings
import
android.provider.Telephony
import
android.provider.Telephony
import
android.text.TextUtils
import
android.text.TextUtils
...
@@ -24,6 +26,7 @@ import com.secspace.sms.helpers.SEARCHED_MESSAGE_ID
...
@@ -24,6 +26,7 @@ import com.secspace.sms.helpers.SEARCHED_MESSAGE_ID
import
com.secspace.sms.helpers.THREAD_ID
import
com.secspace.sms.helpers.THREAD_ID
import
com.secspace.sms.helpers.THREAD_TITLE
import
com.secspace.sms.helpers.THREAD_TITLE
import
com.secspace.sms.models.*
import
com.secspace.sms.models.*
import
com.secspace.sms.receivers.SmsSendObserver
import
com.secspace.sms.util.PhoneUtils
import
com.secspace.sms.util.PhoneUtils
import
com.secspace.sms.util.SmsCountUtil
import
com.secspace.sms.util.SmsCountUtil
import
com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
import
com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
...
@@ -57,6 +60,8 @@ class MainActivity : SimpleActivity() {
...
@@ -57,6 +60,8 @@ class MainActivity : SimpleActivity() {
setupOptionsMenu
()
setupOptionsMenu
()
refreshMenuItems
()
refreshMenuItems
()
contentResolver
.
registerContentObserver
(
Uri
.
parse
(
"content://sms"
),
true
,
SmsSendObserver
(
this
,
Handler
()))
updateMaterialActivityViews
(
updateMaterialActivityViews
(
mainCoordinatorLayout
=
binding
.
mainCoordinator
,
mainCoordinatorLayout
=
binding
.
mainCoordinator
,
nestedView
=
binding
.
conversationsList
,
nestedView
=
binding
.
conversationsList
,
...
@@ -141,6 +146,7 @@ class MainActivity : SimpleActivity() {
...
@@ -141,6 +146,7 @@ class MainActivity : SimpleActivity() {
override
fun
onDestroy
()
{
override
fun
onDestroy
()
{
super
.
onDestroy
()
super
.
onDestroy
()
bus
?.
unregister
(
this
)
bus
?.
unregister
(
this
)
contentResolver
.
unregisterContentObserver
(
SmsSendObserver
(
this
,
Handler
()))
}
}
override
fun
onBackPressed
()
{
override
fun
onBackPressed
()
{
...
@@ -443,29 +449,11 @@ class MainActivity : SimpleActivity() {
...
@@ -443,29 +449,11 @@ class MainActivity : SimpleActivity() {
val
firstConversation
=
sortedConversations
.
firstOrNull
()
?:
return
//获取第一条未掩码会话
val
firstConversation
=
sortedConversations
.
firstOrNull
()
?:
return
//获取第一条未掩码会话
Log
.
d
(
TAG
,
" MainActivity firstConversation() 获取第一条会话 =: ${GsonUtil.parseBeanToJson(firstConversation)}"
)
Log
.
d
(
TAG
,
" MainActivity firstConversation() 获取第一条会话 =: ${GsonUtil.parseBeanToJson(firstConversation)}"
)
va
r
phoneNumber
=
firstConversation
.
title
.
replace
(
" "
,
""
)
va
l
phoneNumber
=
firstConversation
.
title
.
replace
(
" "
,
""
)
//只针对手机号
//只针对手机号
if
(
phoneNumber
.
length
<
11
)
return
if
(
phoneNumber
.
length
<
11
)
return
if
(!
firstConversation
.
isSFNumber
)
{
if
(!
firstConversation
.
isSFNumber
)
{
// Log.d(TAG, "----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber")
// Log.d(TAG, "----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber")
// val phoneNumberResult = CallHistoryManager.getInstance(this@MainActivity).phoneNumber
// if (phoneNumberResult.isNotEmpty()) {
//// Log.d(TAG, "----MainActivity---- phoneNumberResult :$phoneNumberResult")
// val listResult: List<String> = phoneNumberResult.split(",")
//// Log.d(TAG, "----MainActivity---- listResult :$listResult")
// if (listResult.isNotEmpty()) {
// for (item in listResult.distinct()) {
// if (item.length < 11) continue
// PhoneUtils.phoneNumberFormat(item) { itNumber ->
// firstConversation.phoneNumber = itNumber
// firstConversation.isSFNumber = true
// }
// }
// CallHistoryManager.getInstance(this@MainActivity).clearPhoneNumber()
// }
// } else {
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)}"
)
...
@@ -480,16 +468,19 @@ class MainActivity : SimpleActivity() {
...
@@ -480,16 +468,19 @@ class MainActivity : SimpleActivity() {
}
}
}
}
}
}
// }
//根据最新的短信threadId 获取所有短信列表 取最新一条记录
//根据最新的短信threadId 获取所有短信列表 取最新一条记录
val
messages
:
java
.
util
.
ArrayList
<
Message
>
=
getMessages
(
firstConversation
.
threadId
,
true
)
val
messages
:
java
.
util
.
ArrayList
<
Message
>
=
getMessages
(
firstConversation
.
threadId
,
true
)
// Log.e(TAG, " MainActivity getMessages() 执行查询会话 messages 数据库 =:${GsonUtil.parseListToJson(messages)} ")
// Log.e(TAG, " MainActivity getMessages() 执行查询会话 messages 数据库 =:${GsonUtil.parseListToJson(messages)} ")
Log
.
d
(
TAG
,
" MainActivity getMessages() lastMsg 数据库 =:${GsonUtil.parseBeanToJson(messages.last())} "
)
val
lastMsg
=
messages
.
last
()
val
lastMsg
=
messages
.
last
()
firstConversation
.
snippet
=
lastMsg
.
body
firstConversation
.
snippet
=
lastMsg
.
body
firstConversation
.
date
=
lastMsg
.
date
firstConversation
.
date
=
lastMsg
.
date
Log
.
e
(
TAG
,
" MainActivity getMessages() firstConversation 数据库 =:${GsonUtil.parseBeanToJson(firstConversation)} "
)
// Log.d
(TAG, " MainActivity getMessages() firstConversation 数据库 =:${GsonUtil.parseBeanToJson(firstConversation)} ")
conversationsDB
.
insertOrUpdate
(
firstConversation
)
conversationsDB
.
insertOrUpdate
(
firstConversation
)
// Log.d(TAG, " MainActivity getMessages() lastMsg 数据库 =:${GsonUtil.parseBeanToJson(lastMsg)} ")
// messagesDB.insertOrUpdate(lastMsg)
}
}
}
}
...
@@ -504,7 +495,7 @@ class MainActivity : SimpleActivity() {
...
@@ -504,7 +495,7 @@ class MainActivity : SimpleActivity() {
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
...
...
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