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
fa7e3e63
Commit
fa7e3e63
authored
Nov 28, 2024
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:添加根据通话记录对顺丰号码进行掩码功能
parent
b343c5fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
40 deletions
+87
-40
MainActivity.kt
...c/main/kotlin/com/secspace/sms/activities/MainActivity.kt
+87
-40
No files found.
app/src/main/kotlin/com/secspace/sms/activities/MainActivity.kt
View file @
fa7e3e63
...
...
@@ -8,25 +8,27 @@ import android.os.Build
import
android.os.Bundle
import
android.provider.Telephony
import
android.text.TextUtils
import
android.util.Log
import
androidx.annotation.RequiresApi
import
androidx.coordinatorlayout.widget.CoordinatorLayout
import
com.secspace.log.Log
import
androidx.lifecycle.lifecycleScope
import
com.secspace.sms.R
import
com.secspace.sms.adapters.ConversationsAdapter
import
com.secspace.sms.adapters.SearchResultsAdapter
import
com.secspace.sms.databinding.ActivityMainBinding
import
com.secspace.sms.extensions.*
import
com.secspace.sms.helpers.RecentsHelper
import
com.secspace.sms.helpers.SEARCHED_MESSAGE_ID
import
com.secspace.sms.helpers.THREAD_ID
import
com.secspace.sms.helpers.THREAD_TITLE
import
com.secspace.sms.models.Conversation
import
com.secspace.sms.models.Events
import
com.secspace.sms.models.Message
import
com.secspace.sms.models.SearchResult
import
com.secspace.sms.models.*
import
com.secspace.sms.util.PhoneUtils
import
com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
import
com.simplemobiletools.commons.extensions.*
import
com.simplemobiletools.commons.helpers.*
import
com.simplemobiletools.commons.util.GsonUtil
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
org.greenrobot.eventbus.EventBus
import
org.greenrobot.eventbus.Subscribe
import
org.greenrobot.eventbus.ThreadMode
...
...
@@ -79,6 +81,8 @@ class MainActivity : SimpleActivity() {
override
fun
onResume
()
{
super
.
onResume
()
initMessenger
()
updateMenuColors
()
refreshMenuItems
()
...
...
@@ -170,17 +174,17 @@ class MainActivity : SimpleActivity() {
searchTextChanged
(
text
)
}
/* binding.mainMenu.getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.show_recycle_bin -> launchRecycleBin()
R.id.show_archived -> launchArchivedConversations()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
}*/
/* binding.mainMenu.getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.show_recycle_bin -> launchRecycleBin()
R.id.show_archived -> launchArchivedConversations()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
}*/
}
private
fun
refreshMenuItems
()
{
...
...
@@ -254,7 +258,7 @@ class MainActivity : SimpleActivity() {
}
}
initMessenger
()
//
initMessenger()
bus
=
EventBus
.
getDefault
()
try
{
bus
!!
.
register
(
this
)
...
...
@@ -285,7 +289,7 @@ class MainActivity : SimpleActivity() {
}
private
fun
getCachedConversations
()
{
ensureBackgroundThread
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
conversations
=
try
{
conversationsDB
.
getNonArchived
().
toMutableList
()
as
ArrayList
<
Conversation
>
}
catch
(
e
:
Exception
)
{
...
...
@@ -299,10 +303,10 @@ class MainActivity : SimpleActivity() {
}
updateUnreadCountBadge
(
conversations
)
runOnUiThread
{
//
runOnUiThread {
// setupConversations(conversations, cached = true)
getNewConversations
((
conversations
+
archived
).
toMutableList
()
as
ArrayList
<
Conversation
>)
}
//
}
conversations
.
forEach
{
clearExpiredScheduledMessages
(
it
.
threadId
)
}
...
...
@@ -311,8 +315,8 @@ class MainActivity : SimpleActivity() {
private
fun
getNewConversations
(
cachedConversations
:
ArrayList
<
Conversation
>)
{
val
privateCursor
=
getMyContactsCursor
(
favoritesOnly
=
false
,
withPhoneNumbersOnly
=
true
)
ensureBackgroundThread
{
val
privateContacts
=
MyContactsContentProvider
.
getSimpleContacts
(
this
,
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
)
...
...
@@ -366,9 +370,9 @@ class MainActivity : SimpleActivity() {
}
val
allConversations
=
conversationsDB
.
getNonArchived
()
as
ArrayList
<
Conversation
>
// Log.e(TAG, "----MainActivity----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}")
runOnUiThread
{
//
runOnUiThread {
setupConversations
(
allConversations
)
}
//
}
// Log.e(TAG, "----MainActivity----handleMessage appRunCount:${config.appRunCount}")
if
(
config
.
appRunCount
==
1
)
{
...
...
@@ -380,7 +384,6 @@ class MainActivity : SimpleActivity() {
}
}
}
}
private
fun
getOrCreateConversationsAdapter
():
ConversationsAdapter
{
var
currAdapter
=
binding
.
conversationsList
.
adapter
...
...
@@ -402,29 +405,73 @@ class MainActivity : SimpleActivity() {
}
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
>
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
())
}
else
{
showOrHideProgress
(
false
)
showOrHidePlaceholder
(
conversations
.
isEmpty
())
//确保排序后的短信列表是有数据的
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
)
if
(
hasPerMissionResult
)
{
Log
.
d
(
TAG
,
" MainActivity firstConversation() 根据线程Id查询会话 threadID=:${firstConversation.threadId} "
)
val
phoneNumber
=
firstConversation
.
title
.
replace
(
" "
,
""
)
if
(!
firstConversation
.
isSFNumber
&&
phoneNumber
.
length
==
11
)
{
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)}"
)
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} "
)
}
}
}
}
}
// Log.e(TAG, " MainActivity setupConversations() 显示短信列表数据 =: ${GsonUtil.parseListToJson(sortedConversations)}")
try
{
getOrCreateConversationsAdapter
().
apply
{
updateConversations
(
sortedConversations
)
{
if
(!
cached
)
{
showOrHidePlaceholder
(
currentList
.
isEmpty
())
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
// delay(1_000)
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
())
}
else
{
showOrHideProgress
(
false
)
showOrHidePlaceholder
(
conversations
.
isEmpty
())
}
try
{
getOrCreateConversationsAdapter
().
apply
{
updateConversations
(
sortedConversations
)
{
if
(!
cached
)
{
showOrHidePlaceholder
(
currentList
.
isEmpty
())
}
}
}
}
catch
(
ignored
:
Exception
)
{
}
}
catch
(
ignored
:
Exception
)
{
}
}
...
...
@@ -590,8 +637,8 @@ class MainActivity : SimpleActivity() {
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
fun
refreshMessages
(
event
:
Events
.
RefreshMessages
)
{
Log
.
e
(
TAG
,
"----MainActivity----refreshMessages EventBus"
)
initMessenger
()
//
Log.e(TAG, "----MainActivity----refreshMessages EventBus")
//
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