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
605f0cc8
Commit
605f0cc8
authored
Jun 16, 2025
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:新增消息内容手机号检测并高亮显示
parent
2f3b994a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
4 deletions
+122
-4
ThreadAdapter.kt
...rc/main/kotlin/com/secspace/sms/adapters/ThreadAdapter.kt
+53
-4
SpannableStringUtil.kt
.../main/kotlin/com/secspace/sms/util/SpannableStringUtil.kt
+69
-0
No files found.
app/src/main/kotlin/com/secspace/sms/adapters/ThreadAdapter.kt
View file @
605f0cc8
...
@@ -6,6 +6,7 @@ import android.graphics.Typeface
...
@@ -6,6 +6,7 @@ import android.graphics.Typeface
import
android.graphics.drawable.BitmapDrawable
import
android.graphics.drawable.BitmapDrawable
import
android.graphics.drawable.ColorDrawable
import
android.graphics.drawable.ColorDrawable
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.Drawable
import
android.util.Log
import
android.util.Size
import
android.util.Size
import
android.util.TypedValue
import
android.util.TypedValue
import
android.view.Menu
import
android.view.Menu
...
@@ -35,10 +36,13 @@ import com.secspace.sms.helpers.*
...
@@ -35,10 +36,13 @@ import com.secspace.sms.helpers.*
import
com.secspace.sms.models.Attachment
import
com.secspace.sms.models.Attachment
import
com.secspace.sms.models.Message
import
com.secspace.sms.models.Message
import
com.secspace.sms.models.ThreadItem
import
com.secspace.sms.models.ThreadItem
import
com.secspace.sms.popup.TipPopup
import
com.secspace.sms.util.SpannableStringUtil
import
com.simplemobiletools.commons.adapters.MyRecyclerViewListAdapter
import
com.simplemobiletools.commons.adapters.MyRecyclerViewListAdapter
import
com.simplemobiletools.commons.extensions.*
import
com.simplemobiletools.commons.extensions.*
import
com.simplemobiletools.commons.helpers.SimpleContactsHelper
import
com.simplemobiletools.commons.helpers.SimpleContactsHelper
import
com.simplemobiletools.commons.views.MyRecyclerView
import
com.simplemobiletools.commons.views.MyRecyclerView
import
java.util.regex.Pattern
class
ThreadAdapter
(
class
ThreadAdapter
(
activity
:
SimpleActivity
,
activity
:
SimpleActivity
,
...
@@ -53,6 +57,28 @@ class ThreadAdapter(
...
@@ -53,6 +57,28 @@ class ThreadAdapter(
private
val
hasMultipleSIMCards
=
(
activity
.
subscriptionManagerCompat
().
activeSubscriptionInfoList
?.
size
?:
0
)
>
1
private
val
hasMultipleSIMCards
=
(
activity
.
subscriptionManagerCompat
().
activeSubscriptionInfoList
?.
size
?:
0
)
>
1
private
val
maxChatBubbleWidth
=
activity
.
usableScreenSize
.
x
*
0.8f
private
val
maxChatBubbleWidth
=
activity
.
usableScreenSize
.
x
*
0.8f
private
val
tipsPop
:
TipPopup
by
lazy
{
TipPopup
(
activity
)
{
it
:
Int
,
phoneNumber
->
when
(
it
){
1
->{
activity
.
startCallIntent
(
phoneNumber
)
}
2
->{
activity
.
dialNumber
(
phoneNumber
)
}
3
->{
activity
.
launchSendSMSIntent
(
phoneNumber
)
}
4
->{
activity
.
copyToClipboard
(
phoneNumber
)
}
5
->{
activity
.
addNumberToContact
(
phoneNumber
)
}
}
}
}
init
{
init
{
setupDragListener
(
false
)
setupDragListener
(
false
)
setHasStableIds
(
true
)
setHasStableIds
(
true
)
...
@@ -153,7 +179,6 @@ class ThreadAdapter(
...
@@ -153,7 +179,6 @@ class ThreadAdapter(
}
}
}
}
private
fun
isThreadDateTime
(
position
:
Int
)
=
currentList
.
getOrNull
(
position
)
is
ThreadItem
.
ThreadDateTime
private
fun
isThreadDateTime
(
position
:
Int
)
=
currentList
.
getOrNull
(
position
)
is
ThreadItem
.
ThreadDateTime
fun
updateMessages
(
newMessages
:
ArrayList
<
ThreadItem
>,
scrollPosition
:
Int
=
-
1
)
{
fun
updateMessages
(
newMessages
:
ArrayList
<
ThreadItem
>,
scrollPosition
:
Int
=
-
1
)
{
...
@@ -165,20 +190,43 @@ class ThreadAdapter(
...
@@ -165,20 +190,43 @@ class ThreadAdapter(
}
}
}
}
private
fun
checkCellphone
(
bodyInfo
:
String
):
String
{
if
(
bodyInfo
.
isEmpty
())
return
""
// val str = "请关注公众号,开发工具为Android Studio 有问题请联系18698888888。"
// 将给定的正则表达式编译到模式中
val
pattern
=
Pattern
.
compile
(
"(\\d{11})"
)
// 创建匹配给定输入与此模式的匹配器。
val
matcher
=
pattern
.
matcher
(
bodyInfo
)
//查找字符串中是否有符合的子字符串
while
(
matcher
.
find
())
{
//查找到符合的即输出
Log
.
d
(
"TAG"
,
"查询到一个符合的手机号码 = ${matcher.group()}"
)
return
matcher
.
group
()
}
return
""
}
private
fun
setupView
(
holder
:
ViewHolder
,
view
:
View
,
message
:
Message
)
{
private
fun
setupView
(
holder
:
ViewHolder
,
view
:
View
,
message
:
Message
)
{
ItemMessageBinding
.
bind
(
view
).
apply
{
ItemMessageBinding
.
bind
(
view
).
apply
{
threadMessageHolder
.
isSelected
=
selectedKeys
.
contains
(
message
.
hashCode
())
threadMessageHolder
.
isSelected
=
selectedKeys
.
contains
(
message
.
hashCode
())
threadMessageBody
.
apply
{
threadMessageBody
.
apply
{
text
=
message
.
body
text
=
SpannableStringUtil
.
getPhoneNumberWithBody
(
message
.
body
)
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
fontSize
)
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
fontSize
)
beVisibleIf
(
message
.
body
.
isNotEmpty
())
beVisibleIf
(
message
.
body
.
isNotEmpty
())
setOnLongClickListener
{
setOnLongClickListener
{
false
false
}
}
/*
setOnClickListener {
setOnClickListener
{
holder
.
viewClicked
(
message
)
holder
.
viewClicked
(
message
)
}*/
val
result
=
checkCellphone
(
message
.
body
)
if
(
result
.
isNotEmpty
())
{
tipsPop
.
setPhoneNumberData
(
result
)
tipsPop
.
showPopupWindow
()
}
}
}
}
if
(
message
.
isReceivedMessage
())
{
if
(
message
.
isReceivedMessage
())
{
...
@@ -452,4 +500,5 @@ private class ThreadItemDiffCallback : DiffUtil.ItemCallback<ThreadItem>() {
...
@@ -452,4 +500,5 @@ private class ThreadItemDiffCallback : DiffUtil.ItemCallback<ThreadItem>() {
is
Message
->
Message
.
areContentsTheSame
(
oldItem
,
newItem
as
Message
)
is
Message
->
Message
.
areContentsTheSame
(
oldItem
,
newItem
as
Message
)
}
}
}
}
}
}
app/src/main/kotlin/com/secspace/sms/util/SpannableStringUtil.kt
0 → 100644
View file @
605f0cc8
package
com.secspace.sms.util
import
android.content.Context
import
android.graphics.Color
import
android.text.SpannableString
import
android.text.Spanned
import
android.text.TextPaint
import
android.text.method.LinkMovementMethod
import
android.text.style.ClickableSpan
import
android.view.View
import
android.widget.TextView
import
java.util.regex.Pattern
object
SpannableStringUtil
{
fun
getPhoneNumberWithBody
(
strTel
:
String
):
SpannableString
{
val
ss
=
SpannableString
(
strTel
)
val
list
=
getNumbers
(
strTel
)
if
(
list
.
isNotEmpty
())
{
for
(
i
in
list
.
indices
)
{
ss
.
setSpan
(
object
:
ClickableSpan
()
{
override
fun
updateDrawState
(
ds
:
TextPaint
)
{
super
.
updateDrawState
(
ds
)
ds
.
color
=
Color
.
BLUE
//设置文件颜色
ds
.
isUnderlineText
=
true
//设置下划线
}
override
fun
onClick
(
widget
:
View
)
{
}
},
strTel
.
indexOf
(
list
[
i
]),
strTel
.
indexOf
(
list
[
i
])
+
11
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
return
ss
}
/**
* 将字符串中的电话号码设置点击事件和下划线
*
* @param context
* @param tv
* @param strTel
*/
fun
setTelUrl
(
context
:
Context
?,
tv
:
TextView
,
strTel
:
String
)
{
getPhoneNumberWithBody
(
strTel
)
tv
.
highlightColor
=
Color
.
TRANSPARENT
//设置点击后的颜色为透明,否则会一直出现高亮
tv
.
text
=
getPhoneNumberWithBody
(
strTel
)
tv
.
movementMethod
=
LinkMovementMethod
.
getInstance
()
//开始响应点击事件
}
/**
* 从字符串中查找电话号码字符串
*/
fun
getNumbers
(
content
:
String
?):
List
<
String
>
{
val
digitList
:
MutableList
<
String
>
=
ArrayList
()
val
p
=
Pattern
.
compile
(
"(\\d{11})"
)
val
m
=
p
.
matcher
(
content
)
while
(
m
.
find
())
{
val
find
=
m
.
group
(
1
).
toString
()
digitList
.
add
(
find
)
}
return
digitList
}
}
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