@@ -29,7 +29,8 @@ class SpamUtils {
2929 private const val SPAM_PREFS = " SPAM_PREFS"
3030 private const val BLOCK_NUMBERS_KEY = " BLOCK_NUMBERS"
3131 private const val SPAM_URL_TEMPLATE = " https://www.listaspam.com/busca.php?Telefono=%s"
32- private const val RESPONDERONO_URL_TEMPLATE = " https://www.responderono.es/numero-de-telefono/%s"
32+ private const val RESPONDERONO_URL_TEMPLATE =
33+ " https://www.responderono.es/numero-de-telefono/%s"
3334 private const val NOTIFICATION_CHANNEL_ID = " NOTIFICATION_CHANNEL"
3435 private const val NOTIFICATION_ID = 1
3536 private const val SPAM_REPORT_THRESHOLD = 1
@@ -47,7 +48,12 @@ class SpamUtils {
4748
4849 OkHttpClient ().newCall(request).enqueue(object : Callback {
4950 override fun onFailure (call : Call , e : IOException ) {
50- handleNetworkFailure(context, " Failed to check number in www.listaspam.com" , e, callback)
51+ handleNetworkFailure(
52+ context,
53+ " Failed to check number in www.listaspam.com" ,
54+ e,
55+ callback
56+ )
5157 }
5258
5359 override fun onResponse (call : Call , response : Response ) {
@@ -64,7 +70,12 @@ class SpamUtils {
6470 }
6571 }
6672 }
67- } ? : handleNetworkFailure(context, " Empty response from www.listaspam.com" , null , callback)
73+ } ? : handleNetworkFailure(
74+ context,
75+ " Empty response from www.listaspam.com" ,
76+ null ,
77+ callback
78+ )
6879 }
6980 })
7081 }
@@ -75,20 +86,34 @@ class SpamUtils {
7586 * @param number Phone number to check.
7687 * @param callback Callback function to handle the result.
7788 */
78- private fun checkResponderono (context : Context , number : String , callback : (isNegative: Boolean ) -> Unit ) {
89+ private fun checkResponderono (
90+ context : Context ,
91+ number : String ,
92+ callback : (isNegative: Boolean ) -> Unit
93+ ) {
7994 val url = RESPONDERONO_URL_TEMPLATE .format(number)
8095 val request = Request .Builder ().url(url).build()
8196
8297 OkHttpClient ().newCall(request).enqueue(object : Callback {
8398 override fun onFailure (call : Call , e : IOException ) {
84- handleNetworkFailure(context, " Failed to check number in www.responderono.es" , e, callback)
99+ handleNetworkFailure(
100+ context,
101+ " Failed to check number in www.responderono.es" ,
102+ e,
103+ callback
104+ )
85105 }
86106
87107 override fun onResponse (call : Call , response : Response ) {
88108 response.body?.string()?.let { body ->
89109 val isResponderONoNegative = body.contains(" .scoreContainer .score.negative" )
90110 callback(isResponderONoNegative)
91- } ? : handleNetworkFailure(context, " Empty response from www.responderono.es" , null , callback)
111+ } ? : handleNetworkFailure(
112+ context,
113+ " Empty response from www.responderono.es" ,
114+ null ,
115+ callback
116+ )
92117 }
93118 })
94119 }
@@ -99,7 +124,11 @@ class SpamUtils {
99124 * @param number Phone number identified as spam.
100125 * @param callback Callback function to handle the result.
101126 */
102- private fun handleSpamNumber (context : Context , number : String , callback : (isSpam: Boolean ) -> Unit ) {
127+ private fun handleSpamNumber (
128+ context : Context ,
129+ number : String ,
130+ callback : (isSpam: Boolean ) -> Unit
131+ ) {
103132 saveSpamNumber(context, number)
104133 sendNotification(context, number)
105134 callback(true )
@@ -111,7 +140,11 @@ class SpamUtils {
111140 * @param number Phone number identified as not spam.
112141 * @param callback Callback function to handle the result.
113142 */
114- private fun handleNonSpamNumber (context : Context , number : String , callback : (isSpam: Boolean ) -> Unit ) {
143+ private fun handleNonSpamNumber (
144+ context : Context ,
145+ number : String ,
146+ callback : (isSpam: Boolean ) -> Unit
147+ ) {
115148 Handler (Looper .getMainLooper()).post {
116149 showToast(context, " Incoming call is not spam" , Toast .LENGTH_LONG )
117150 }
@@ -126,7 +159,12 @@ class SpamUtils {
126159 * @param e Exception that occurred (optional).
127160 * @param callback Callback function to handle the result.
128161 */
129- private fun handleNetworkFailure (context : Context , message : String , e : IOException ? , callback : (Boolean ) -> Unit ) {
162+ private fun handleNetworkFailure (
163+ context : Context ,
164+ message : String ,
165+ e : IOException ? ,
166+ callback : (Boolean ) -> Unit
167+ ) {
130168 Handler (Looper .getMainLooper()).post {
131169 showToast(context, message, Toast .LENGTH_LONG )
132170 }
@@ -141,7 +179,8 @@ class SpamUtils {
141179 */
142180 private fun saveSpamNumber (context : Context , number : String ) {
143181 val sharedPreferences = context.getSharedPreferences(SPAM_PREFS , Context .MODE_PRIVATE )
144- val blockedNumbers = sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
182+ val blockedNumbers =
183+ sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
145184 blockedNumbers?.add(number)
146185 with (sharedPreferences.edit()) {
147186 putStringSet(BLOCK_NUMBERS_KEY , blockedNumbers)
@@ -156,7 +195,8 @@ class SpamUtils {
156195 */
157196 private fun removeSpamNumber (context : Context , number : String ) {
158197 val sharedPreferences = context.getSharedPreferences(SPAM_PREFS , Context .MODE_PRIVATE )
159- val blockedNumbers = sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
198+ val blockedNumbers =
199+ sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
160200 blockedNumbers?.remove(number)
161201 with (sharedPreferences.edit()) {
162202 putStringSet(BLOCK_NUMBERS_KEY , blockedNumbers)
0 commit comments