Commit fa7e3e63 by zhangchengbo

feat:添加根据通话记录对顺丰号码进行掩码功能

parent b343c5fd
...@@ -8,25 +8,27 @@ import android.os.Build ...@@ -8,25 +8,27 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.provider.Telephony import android.provider.Telephony
import android.text.TextUtils import android.text.TextUtils
import android.util.Log
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.secspace.log.Log import androidx.lifecycle.lifecycleScope
import com.secspace.sms.R import com.secspace.sms.R
import com.secspace.sms.adapters.ConversationsAdapter import com.secspace.sms.adapters.ConversationsAdapter
import com.secspace.sms.adapters.SearchResultsAdapter import com.secspace.sms.adapters.SearchResultsAdapter
import com.secspace.sms.databinding.ActivityMainBinding import com.secspace.sms.databinding.ActivityMainBinding
import com.secspace.sms.extensions.* import com.secspace.sms.extensions.*
import com.secspace.sms.helpers.RecentsHelper
import com.secspace.sms.helpers.SEARCHED_MESSAGE_ID 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.Conversation import com.secspace.sms.models.*
import com.secspace.sms.models.Events import com.secspace.sms.util.PhoneUtils
import com.secspace.sms.models.Message
import com.secspace.sms.models.SearchResult
import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.util.GsonUtil import com.simplemobiletools.commons.util.GsonUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
...@@ -79,6 +81,8 @@ class MainActivity : SimpleActivity() { ...@@ -79,6 +81,8 @@ class MainActivity : SimpleActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
initMessenger()
updateMenuColors() updateMenuColors()
refreshMenuItems() refreshMenuItems()
...@@ -170,17 +174,17 @@ class MainActivity : SimpleActivity() { ...@@ -170,17 +174,17 @@ class MainActivity : SimpleActivity() {
searchTextChanged(text) searchTextChanged(text)
} }
/* binding.mainMenu.getToolbar().setOnMenuItemClickListener { menuItem -> /* binding.mainMenu.getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.show_recycle_bin -> launchRecycleBin() R.id.show_recycle_bin -> launchRecycleBin()
R.id.show_archived -> launchArchivedConversations() R.id.show_archived -> launchArchivedConversations()
R.id.settings -> launchSettings() R.id.settings -> launchSettings()
R.id.about -> launchAbout() R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false else -> return@setOnMenuItemClickListener false
} }
return@setOnMenuItemClickListener true return@setOnMenuItemClickListener true
}*/ }*/
} }
private fun refreshMenuItems() { private fun refreshMenuItems() {
...@@ -254,7 +258,7 @@ class MainActivity : SimpleActivity() { ...@@ -254,7 +258,7 @@ class MainActivity : SimpleActivity() {
} }
} }
initMessenger() // initMessenger()
bus = EventBus.getDefault() bus = EventBus.getDefault()
try { try {
bus!!.register(this) bus!!.register(this)
...@@ -285,7 +289,7 @@ class MainActivity : SimpleActivity() { ...@@ -285,7 +289,7 @@ class MainActivity : SimpleActivity() {
} }
private fun getCachedConversations() { private fun getCachedConversations() {
ensureBackgroundThread { lifecycleScope.launch(Dispatchers.IO) {
val conversations = try { val conversations = try {
conversationsDB.getNonArchived().toMutableList() as ArrayList<Conversation> conversationsDB.getNonArchived().toMutableList() as ArrayList<Conversation>
} catch (e: Exception) { } catch (e: Exception) {
...@@ -299,10 +303,10 @@ class MainActivity : SimpleActivity() { ...@@ -299,10 +303,10 @@ class MainActivity : SimpleActivity() {
} }
updateUnreadCountBadge(conversations) updateUnreadCountBadge(conversations)
runOnUiThread { // runOnUiThread {
// setupConversations(conversations, cached = true) // setupConversations(conversations, cached = true)
getNewConversations((conversations + archived).toMutableList() as ArrayList<Conversation>) getNewConversations((conversations + archived).toMutableList() as ArrayList<Conversation>)
} // }
conversations.forEach { conversations.forEach {
clearExpiredScheduledMessages(it.threadId) clearExpiredScheduledMessages(it.threadId)
} }
...@@ -311,8 +315,8 @@ class MainActivity : SimpleActivity() { ...@@ -311,8 +315,8 @@ class MainActivity : SimpleActivity() {
private fun getNewConversations(cachedConversations: ArrayList<Conversation>) { private fun getNewConversations(cachedConversations: ArrayList<Conversation>) {
val privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true) 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)}") // Log.e(TAG, " getNewConversations privateContacts:${GsonUtil.parseListToJson(privateContacts)}")
//获取系统SMS DB短信列表 //获取系统SMS DB短信列表
val conversations: java.util.ArrayList<Conversation> = getConversations(privateContacts = privateContacts) val conversations: java.util.ArrayList<Conversation> = getConversations(privateContacts = privateContacts)
...@@ -366,9 +370,9 @@ class MainActivity : SimpleActivity() { ...@@ -366,9 +370,9 @@ class MainActivity : SimpleActivity() {
} }
val allConversations = conversationsDB.getNonArchived() as ArrayList<Conversation> val allConversations = conversationsDB.getNonArchived() as ArrayList<Conversation>
// Log.e(TAG, "----MainActivity----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}") // Log.e(TAG, "----MainActivity----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}")
runOnUiThread { // runOnUiThread {
setupConversations(allConversations) setupConversations(allConversations)
} // }
// Log.e(TAG, "----MainActivity----handleMessage appRunCount:${config.appRunCount}") // Log.e(TAG, "----MainActivity----handleMessage appRunCount:${config.appRunCount}")
if (config.appRunCount == 1) { if (config.appRunCount == 1) {
...@@ -380,7 +384,6 @@ class MainActivity : SimpleActivity() { ...@@ -380,7 +384,6 @@ class MainActivity : SimpleActivity() {
} }
} }
} }
}
private fun getOrCreateConversationsAdapter(): ConversationsAdapter { private fun getOrCreateConversationsAdapter(): ConversationsAdapter {
var currAdapter = binding.conversationsList.adapter var currAdapter = binding.conversationsList.adapter
...@@ -402,29 +405,73 @@ class MainActivity : SimpleActivity() { ...@@ -402,29 +405,73 @@ class MainActivity : SimpleActivity() {
} }
private fun setupConversations(conversations: ArrayList<Conversation>, cached: Boolean = false) { private fun setupConversations(conversations: ArrayList<Conversation>, cached: Boolean = false) {
if (conversations.size == 0) return
val sortedConversations = conversations.sortedWith( val sortedConversations = conversations.sortedWith(
compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) } compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) }
.thenByDescending { it.date } .thenByDescending { it.date }
).toMutableList() as ArrayList<Conversation> ).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()) val firstConversation = sortedConversations.first()//获取第一条未掩码会话
} else { Log.d(TAG, " MainActivity firstConversation() 获取第一条会话 =: ${GsonUtil.parseBeanToJson(firstConversation)}")
showOrHideProgress(false) // val smsDraft: String? = getSmsDraft(firstConversation.threadId)
showOrHidePlaceholder(conversations.isEmpty()) // 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)}") lifecycleScope.launch(Dispatchers.Main) {
try { // delay(1_000)
getOrCreateConversationsAdapter().apply { Log.d(TAG, " MainActivity setupConversations() 修改后显示短信列表数据 =: ${GsonUtil.parseListToJson(sortedConversations)}")
updateConversations(sortedConversations) { // runOnUiThread {
if (!cached) {
showOrHidePlaceholder(currentList.isEmpty()) 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() { ...@@ -590,8 +637,8 @@ class MainActivity : SimpleActivity() {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun refreshMessages(event: Events.RefreshMessages) { fun refreshMessages(event: Events.RefreshMessages) {
Log.e(TAG, "----MainActivity----refreshMessages EventBus") // Log.e(TAG, "----MainActivity----refreshMessages EventBus")
initMessenger() // initMessenger()
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment