Add the ability to block numbers by pattern
This commit is contained in:
parent
46a933d69b
commit
cb9e91ce08
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue