Skip to content

Commit 3b73966

Browse files
committed
Move "end call if the number is already blocked" logic to SpamUtils
1 parent 20e5f67 commit 3b73966

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

app/src/main/java/com/addev/listaspam/MyCallScreeningService.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ class MyCallScreeningService : CallScreeningService() {
3434
val rawNumber = getRawPhoneNumber(details)
3535

3636
rawNumber?.let {
37-
val sharedPreferences = getSharedPreferences(SPAM_PREFS, Context.MODE_PRIVATE)
38-
val blockedNumbers = sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY, null)
39-
40-
// End call if the number is already blocked
41-
if (blockedNumbers?.contains(rawNumber) == true) {
42-
endCall(details)
43-
return
44-
}
45-
4637
// Check if the number is spam
4738
spamUtils.checkSpamNumber(this, it) { isSpam ->
4839
if (isSpam) {

app/src/main/java/com/addev/listaspam/SpamUtils.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.widget.Toast
1212
import androidx.core.app.ActivityCompat
1313
import androidx.core.app.NotificationCompat
1414
import androidx.core.app.NotificationManagerCompat
15+
import com.addev.listaspam.MyCallScreeningService.Companion
1516
import okhttp3.Call
1617
import okhttp3.Callback
1718
import okhttp3.OkHttpClient
@@ -43,6 +44,15 @@ class SpamUtils {
4344
* @param callback Callback function to handle the result.
4445
*/
4546
fun checkSpamNumber(context: Context, number: String, callback: (isSpam: Boolean) -> Unit) {
47+
val sharedPreferences = context.getSharedPreferences(SPAM_PREFS, Context.MODE_PRIVATE)
48+
val blockedNumbers = sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY, null)
49+
50+
// End call if the number is already blocked
51+
if (blockedNumbers?.contains(number) == true) {
52+
sendNotification(context, number)
53+
return callback(true)
54+
}
55+
4656
val url = SPAM_URL_TEMPLATE.format(number)
4757
val request = Request.Builder().url(url).build()
4858

0 commit comments

Comments
 (0)