Merge pull request #430 from Naveen3Singh/pattern_blocking

Add the ability to block numbers by pattern
This commit is contained in:
Tibor Kaputa 2022-09-20 09:52:25 +02:00 committed by GitHub
commit 6727b2e09f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -66,7 +66,7 @@ dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:15c753bd01' implementation 'com.github.SimpleMobileTools:Simple-Commons:15c753bd01'
implementation 'org.greenrobot:eventbus:3.3.1' implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61' implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
implementation 'com.github.tibbi:android-smsmms:4cdacdb701' implementation 'com.github.tibbi:android-smsmms:875a46a9c4'
implementation "me.leolin:ShortcutBadger:1.1.22" implementation "me.leolin:ShortcutBadger:1.1.22"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3' implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'

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 {