Add the ability to block numbers by pattern

This commit is contained in:
Naveen 2022-09-17 23:52:06 +05:30
parent 46a933d69b
commit cb9e91ce08
1 changed files with 7 additions and 3 deletions

View File

@ -6,18 +6,22 @@ import android.os.Handler
import android.os.Looper import android.os.Looper
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.simplemobiletools.commons.extensions.isNumberBlocked import com.simplemobiletools.commons.extensions.isNumberBlocked
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.extensions.* import com.simplemobiletools.smsmessenger.extensions.*
// more info at https://github.com/klinker41/android-smsmms // more info at https://github.com/klinker41/android-smsmms
class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() { class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
override fun isAddressBlocked(context: Context, address: String): Boolean {
val normalizedAddress = address.normalizePhoneNumber()
return context.isNumberBlocked(normalizedAddress)
}
override fun onMessageReceived(context: Context, messageUri: Uri) { override fun onMessageReceived(context: Context, messageUri: Uri) {
val mms = context.getLatestMMS() ?: return val mms = context.getLatestMMS() ?: return
val address = mms.participants.firstOrNull()?.phoneNumbers?.first()?.normalizedNumber ?: "" val address = mms.participants.firstOrNull()?.phoneNumbers?.first()?.normalizedNumber ?: ""
if (context.isNumberBlocked(address)) {
return
}
val size = context.resources.getDimension(R.dimen.notification_large_icon_size).toInt() val size = context.resources.getDimension(R.dimen.notification_large_icon_size).toInt()
ensureBackgroundThread { ensureBackgroundThread {