Skip to content

Commit 40a9cff

Browse files
committed
Improve some literals and add reason for blocking call to notification
1 parent 2f0bda8 commit 40a9cff

File tree

8 files changed

+65
-40
lines changed

8 files changed

+65
-40
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.core.view.WindowInsetsCompat
2626
import androidx.recyclerview.widget.LinearLayoutManager
2727
import androidx.recyclerview.widget.RecyclerView
2828
import com.addev.listaspam.adapter.CallLogAdapter
29+
import com.addev.listaspam.adapter.CallLogAdapter.Companion.REPORT_URL_TEMPLATE
2930
import com.addev.listaspam.util.BLOCK_NUMBERS_KEY
3031
import com.addev.listaspam.util.SPAM_PREFS
3132
import com.addev.listaspam.util.getCallLogs
@@ -40,7 +41,11 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
4041
private var permissionDeniedDialog: AlertDialog? = null
4142
private var callLogAdapter: CallLogAdapter? =null
4243
private var recyclerView: RecyclerView? = null
43-
private val REQUEST_CODE_PERMISSIONS = 1
44+
45+
companion object {
46+
private const val REQUEST_CODE_PERMISSIONS = 1
47+
private const val ABOUT_LINK = "https://github.com/adamff-dev/lista-spam-call-blocker-app";
48+
}
4449

4550
override fun onCreate(savedInstanceState: Bundle?) {
4651
super.onCreate(savedInstanceState)
@@ -64,6 +69,11 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
6469
startActivity(intent)
6570
true
6671
}
72+
R.id.action_about -> {
73+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(ABOUT_LINK))
74+
this.startActivity(intent)
75+
true
76+
}
6777
else -> super.onOptionsItemSelected(item)
6878
}
6979
}

app/src/main/java/com/addev/listaspam/adapter/CallLogAdapter.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,18 @@ class CallLogAdapter(
9191

9292
actionTextView.text = action
9393

94+
if (callLog.type == CallLog.Calls.BLOCKED_TYPE) {
95+
actionTextView.setTextColor(ContextCompat.getColor(context, android.R.color.holo_red_light))
96+
} else {
97+
actionTextView.setTextColor(ContextCompat.getColor(context, android.R.color.darker_gray))
98+
}
99+
94100
when {
95-
callLog.type == CallLog.Calls.BLOCKED_TYPE -> {
96-
numberTextView.setTextColor(ContextCompat.getColor(context, android.R.color.holo_red_light))
97-
actionTextView.setTextColor(ContextCompat.getColor(context, android.R.color.holo_red_light))
98-
}
99101
isBlocked -> numberTextView.setTextColor(ContextCompat.getColor(context, android.R.color.holo_red_light))
100102
isWhitelisted -> numberTextView.setTextColor(ContextCompat.getColor(context, android.R.color.holo_blue_dark))
101-
else -> numberTextView.setTextColor(ContextCompat.getColor(context, android.R.color.darker_gray))
103+
else -> {
104+
numberTextView.setTextColor(ContextCompat.getColor(context, android.R.color.darker_gray))
105+
}
102106
}
103107

104108
if (number.isNullOrBlank()) {

app/src/main/java/com/addev/listaspam/util/NotificationUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.addev.listaspam.R
1313
private const val NOTIFICATION_CHANNEL_ID = "NOTIFICATION_CHANNEL"
1414
private const val NOTIFICATION_ID = 1
1515

16-
fun sendNotification(context: Context, number: String) {
16+
fun sendNotification(context: Context, number: String, reason: String) {
1717
createNotificationChannel(context)
1818

1919
if (ActivityCompat.checkSelfPermission(
@@ -27,8 +27,8 @@ fun sendNotification(context: Context, number: String) {
2727

2828
val notification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
2929
.setSmallIcon(R.mipmap.ic_launcher)
30-
.setContentTitle(context.getString(R.string.notification_title_spam_blocked))
31-
.setContentText(context.getString(R.string.notification_text_spam_blocked, number))
30+
.setContentTitle(context.getString(R.string.notification_title_spam_blocked, number))
31+
.setContentText(context.getString(R.string.block_reason) + " " + reason)
3232
.setPriority(NotificationCompat.PRIORITY_HIGH)
3333
.build()
3434

app/src/main/java/com/addev/listaspam/util/SharedPreferencesUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fun shouldBlockHiddenNumbers(context: Context): Boolean {
1919

2020
fun shouldBlockInternationalNumbers(context: Context): Boolean {
2121
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
22-
return sharedPreferences.getBoolean("pref_block_international_numbers", true)
22+
return sharedPreferences.getBoolean("pref_block_international_numbers", false)
2323
}
2424

2525
fun shouldFilterWithListaSpam(context: Context): Boolean {

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class SpamUtils {
3535
"https://www.responderono.es/numero-de-telefono/%s"
3636
private const val RESPONDERONO_CSS_SELECTOR = ".scoreContainer .score.negative"
3737
private const val CLEVER_DIALER_URL_TEMPLATE = "https://www.cleverdialer.es/numero/%s"
38+
39+
private const val USER_AGENT =
40+
"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36"
3841
}
3942

4043
private val client = OkHttpClient()
@@ -54,8 +57,7 @@ class SpamUtils {
5457
}
5558

5659
if (number.isNullOrBlank() && shouldBlockHiddenNumbers(context)) {
57-
showToast(context, context.getString(R.string.block_hidden_number), Toast.LENGTH_LONG)
58-
handleSpamNumber(context, number, false, callback)
60+
handleSpamNumber(context, number, false, context.getString(R.string.block_hidden_number), callback)
5961
return@launch
6062
}
6163

@@ -64,23 +66,20 @@ class SpamUtils {
6466
}
6567

6668
if (isInternationalCall(number) && shouldBlockInternationalNumbers(context)) {
67-
showToast(context, context.getString(R.string.block_international_call), Toast.LENGTH_LONG)
68-
handleSpamNumber(context, number, false, callback)
69+
handleSpamNumber(context, number, false, context.getString(R.string.block_international_call), callback)
6970
return@launch
7071
}
7172

7273
if (isNumberBlocked(context, number)) {
73-
showToast(context, context.getString(R.string.block_already_blocked_number), Toast.LENGTH_LONG)
74-
handleSpamNumber(context, number, callback)
74+
handleSpamNumber(context, number, context.getString(R.string.block_already_blocked_number), callback)
7575
return@launch
7676
}
7777

7878
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
7979
if (isNumberInAgenda(context, number)) {
8080
return@launch
8181
} else if (shouldBlockNonContacts(context)) {
82-
showToast(context, context.getString(R.string.block_non_contact), Toast.LENGTH_LONG)
83-
handleSpamNumber(context, number, false, callback)
82+
handleSpamNumber(context, number, false, context.getString(R.string.block_non_contact), callback)
8483
return@launch
8584
}
8685
}
@@ -102,8 +101,7 @@ class SpamUtils {
102101
}
103102

104103
if (isSpam) {
105-
showToast(context, context.getString(R.string.block_non_contact), Toast.LENGTH_LONG)
106-
handleSpamNumber(context, number, callback)
104+
handleSpamNumber(context, number, context.getString(R.string.block_spam_number), callback)
107105
} else {
108106
handleNonSpamNumber(context, number, callback)
109107
}
@@ -210,7 +208,9 @@ class SpamUtils {
210208
* @return True if spam indicators are found, false otherwise.
211209
*/
212210
private suspend fun checkUrlForSpam(url: String, cssSelector: String): Boolean {
213-
val request = Request.Builder().url(url).build()
211+
val request = Request.Builder()
212+
.header("User-Agent", USER_AGENT)
213+
.url(url).build()
214214
return withContext(Dispatchers.IO) {
215215
try {
216216
val response = client.newCall(request).execute()
@@ -236,9 +236,10 @@ class SpamUtils {
236236
private fun handleSpamNumber(
237237
context: Context,
238238
number: String,
239+
reason: String,
239240
callback: (isSpam: Boolean) -> Unit
240241
) {
241-
handleSpamNumber(context, number, true, callback)
242+
handleSpamNumber(context, number, true, reason, callback)
242243
}
243244

244245
/**
@@ -251,12 +252,15 @@ class SpamUtils {
251252
context: Context,
252253
number: String,
253254
saveNumber: Boolean,
255+
reason: String,
254256
callback: (isSpam: Boolean) -> Unit
255257
) {
258+
showToast(context, context.getString(R.string.block_reason_long) + " " + reason, Toast.LENGTH_LONG)
259+
256260
if (saveNumber) {
257261
saveSpamNumber(context, number)
258262
}
259-
sendNotification(context, number)
263+
sendNotification(context, number, reason)
260264
callback(true)
261265
}
262266

app/src/main/res/menu/menu.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
<item
44
android:id="@+id/action_settings"
55
android:title="@string/action_settings" />
6+
<item
7+
android:id="@+id/action_about"
8+
android:title="@string/about" />
69
</menu>

app/src/main/res/values-es/strings.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
<string name="whitelisted_text_format">%1$s (whitelist)</string>
1717
<string name="duration_label">Duración: %1$d segundos</string>
1818
<string name="report_url_template">http://example.com/reportar?number=%1$s</string>
19-
<string name="incoming_call_not_spam">La llamada entrante no es spam</string>
19+
<string name="incoming_call_not_spam">La llamada entrante parece que no es spam</string>
2020
<string name="notification_channel_name">ListaSpam</string>
21-
<string name="notification_title_spam_blocked">Número de spam bloqueado</string>
22-
<string name="notification_text_spam_blocked">Número de spam bloqueado: %1$s</string>
21+
<string name="notification_title_spam_blocked">Llamada bloqueada: %1$s</string>
2322
<string name="number_copied_to_clipboard">Número copiado al portapapeles</string>
2423

2524
<!-- Call types -->
@@ -31,6 +30,7 @@
3130

3231
<!-- Preferences -->
3332
<string name="action_settings">Ajustes</string>
33+
<string name="about">Acerca de</string>
3434

3535
<string name="pref_enable_blocking_title">Activar bloqueo general</string>
3636
<string name="pref_enable_blocking_summary">Habilita o deshabilita el sistema de bloqueo de llamadas en toda la aplicación</string>
@@ -39,7 +39,7 @@
3939
<string name="pref_filter_lista_spam_summary">Bloquea llamadas de números de spam incluidos en la base de datos de listaspam.com</string>
4040

4141
<string name="pref_filter_responder_o_no_title">Filtrar con responderono.es</string>
42-
<string name="pref_filter_responder_o_no_summary">Bloquear llamadas de números de spam incluidos en la base de datos de responderono.es</string>
42+
<string name="pref_filter_responder_o_no_summary">Bloquea llamadas de números de spam incluidos en la base de datos de responderono.es</string>
4343

4444
<string name="pref_block_non_contacts_title">Bloquear números desconocidos</string>
4545
<string name="pref_block_non_contacts_summary">Bloquea todas las llamadas de números que no están en tu lista de contactos</string>
@@ -63,9 +63,11 @@
6363

6464
<!-- SpamUtils blocking reasons -->
6565
<string name="blocking_disabled">El bloqueo de llamadas está desactivado en la configuración</string>
66-
<string name="block_spam_number">Bloqueando llamada porque está reportada como spam</string>
67-
<string name="block_hidden_number">Bloqueando llamada porque es de un número oculto</string>
68-
<string name="block_international_call">Bloqueando llamada porque es una llamada internacional</string>
69-
<string name="block_already_blocked_number">Bloqueando llamada porque es de un número ya bloqueado</string>
70-
<string name="block_non_contact">Bloqueando llamada porque no es de un contacto en tu agenda</string>
66+
<string name="block_reason_long">Llamada bloqueada:</string>
67+
<string name="block_reason">Motivo:</string>
68+
<string name="block_spam_number">Reportado como spam</string>
69+
<string name="block_hidden_number">Número oculto</string>
70+
<string name="block_international_call">Llamada internacional</string>
71+
<string name="block_already_blocked_number">Número bloqueado</string>
72+
<string name="block_non_contact">No es un contacto</string>
7173
</resources>

app/src/main/res/values/strings.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
<string name="whitelisted_text_format">%1$s (whitelist)</string>
1717
<string name="duration_label">Duration: %1$d seconds</string>
1818
<string name="report_url_template">http://example.com/report?number=%1$s</string>
19-
<string name="incoming_call_not_spam">Incoming call is not spam</string>
19+
<string name="incoming_call_not_spam">The incoming call appears not to be spam</string>
2020
<string name="notification_channel_name">ListaSpam</string>
21-
<string name="notification_title_spam_blocked">Spam Number Blocked</string>
22-
<string name="notification_text_spam_blocked">Blocked spam number: %1$s</string>
21+
<string name="notification_title_spam_blocked">Call blocked: %1$s</string>
2322
<string name="number_copied_to_clipboard">Phone number copied to clipboard</string>
2423

2524
<!-- Call types -->
@@ -63,10 +62,13 @@
6362
<string name="remove_from_whitelist">Remove from whitelist</string>
6463

6564
<!-- SpamUtils blocking reasons -->
65+
<string name="block_reason_long">Call blocked:</string>
66+
<string name="block_reason">Reason:</string>
6667
<string name="blocking_disabled">Call blocking is disabled in settings</string>
67-
<string name="block_hidden_number">Blocking call because it\'s from a hidden number</string>
68-
<string name="block_spam_number">Blocking call because it\'s reported as spam</string>
69-
<string name="block_international_call">Blocking call because it\'s an international call</string>
70-
<string name="block_already_blocked_number">Blocking call because it\'s from an already blocked number</string>
71-
<string name="block_non_contact">Blocking call because it\'s not from a contact in your agenda</string>
68+
<string name="block_hidden_number">Hidden number</string>
69+
<string name="block_spam_number">Reported as spam</string>
70+
<string name="block_international_call">International call</string>
71+
<string name="block_already_blocked_number">Blocked number</string>
72+
<string name="block_non_contact">Not a contact</string>
73+
<string name="about">About</string>
7274
</resources>

0 commit comments

Comments
 (0)